# Constraining address for the memory making sure the Offset is not within the previous memory regions

**URL:** <https://verificationacademy.com/forums/t/constraining-address-for-the-memory-making-sure-the-offset-is-not-within-the-previous-memory-regions/33486>\
**Category:** UVM\
**Tags:** SV-Constraint-Solver, UVM, SV-constraint, constrained-random-generation\
**Created:** [September 13, 2017, 1:40am UTC](https://verificationacademy.com/forums/t/constraining-address-for-the-memory-making-sure-the-offset-is-not-within-the-previous-memory-regions/33486 "2017-09-13T01:40:22Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![dave\_59](https://verificationacademy.com/forums/user_avatar/verificationacademy.com/dave_59/32/4499_2.png) [@dave\_59](https://verificationacademy.com/forums/u/dave_59)\
**Post date:** [September 13, 2017, 2:39am UTC](https://verificationacademy.com/forums/t/constraining-address-for-the-memory-making-sure-the-offset-is-not-within-the-previous-memory-regions/33486/2 "2017-09-13T02:39:22Z")

</div>

_In reply to [prashanthiyer90](https://verificationacademy.com/forums/t/constraining-address-for-the-memory-making-sure-the-offset-is-not-within-the-previous-memory-regions/33486):_  
You will need to build a database of used addresses and make sure that each address in not withing the new range you want add.

```verilog
module top;
  class A;
    rand int unsigned start,size;
    int used[$];
    constraint c{0<size;size<5;start<20;
       foreach(used[addr])!(used[addr] inside {[start:start+size-1]});}
    function void post_randomize();
       for(int addr = start; addr<(start+size); addr++)
         used.push_back(addr);
       used.sort(); // makes display easier to read
    endfunction
  endclass
  A h = new;
  initial repeat(15) begin
    if (!h.randomize) $error("no more space to write");
    $display("%p",h);
  end
endmodule : top

```

---

_[View the full topic](https://verificationacademy.com/forums/t/constraining-address-for-the-memory-making-sure-the-offset-is-not-within-the-previous-memory-regions/33486)._
