• Techo

[IC design] Google interview design verification, Systemverilog constraint and memory read part two

以下的題目皆是需要使用 systemverilog 來實現

Q1. Give a constraint to allocate 4 memory blocks in 4KB memory.


Ans:

class Allocate_mem;


rand bit [12:0] start_addr[4];

rand bit [12:0] size[4];

constraint c_total_size {

size.sum() with (int'(item)) <= 4096;

}

constraint c_no_overlap {

foreach(start_addr[i]) {

if(i != 3)

start_addr[i+1] >= start_addr[i] + size[i];

else

4096 >= int'(start_addr[i] + size[i]);

}

}


endclass



Q2. Give a function to find out N byte continuous memory in 1 KB memory, if it finds enough memory space then return the start address, if not,this function should return -1

How to check this address it available? if this address value is not equal to 0, it means it's not available?


Ans:

mem[1024];

function getMem(int N);

int cnt = 0;

int cur_addr = 0;

while(1) begin

if( mem[cur_addr] == 0) begin

cnt = 1;

while(1) begin

if( mem[cnt+cur_addr] != 0) begin

break;

end else if (cnt == (N-1)) begin

return cur_addr;

end

cnt = cnt + 1;

end

end

end

return -1;

endfunction

95 次瀏覽
Logo2020.JPG
  • Instagram - White Circle
  • Google+ - White Circle
  • Facebook - White Circle

Contact Us

Techo私人程式家教

官方LINE ID : @tutortecho

zh-Hant.png

© Copyright 2018 by Sherry Wu and Techo Chao.

Proudly created with Wix.com,

but page loading is too slow,so I don't recommend it.