I am trying to copy the memory address content from [0th- 4th] location to [3th -7th] address location . Need not use temporary variable while copying . I see there is overap for 6th and 7th location copied data and its incorrect data . How to fix this issue ? can we use NBA assignment /Fork_join concept to do that ? if yes how to do ?
Current Output
run -all
# Mem[ 0] = 17750c26
# Mem[ 1] = 9d0db966
# Mem[ 2] = bcb9e3b6
# Mem[ 3] = 510e08c6
# Mem[ 4] = 83956e46
# Mem[ 5] = 3bd10f72
# Mem[ 6] = 769bf32e
# Mem[ 7] = fa374467
# Mem[ 8] = 3386553a
# Mem[ 9] = 46f91c6a
# After copying - Mem[ 0] = 17750c26
# After copying - Mem[ 1] = 9d0db966
# After copying - Mem[ 2] = bcb9e3b6
# After copying - Mem[ 3] = 17750c26
# After copying - Mem[ 4] = 9d0db966
# After copying - Mem[ 5] = bcb9e3b6
# After copying - Mem[ 6] = 17750c26
# After copying - Mem[ 7] = 9d0db966
# After copying - Mem[ 8] = 3386553a
# After copying - Mem[ 9] = 46f91c6a
# Copy content of memory locations from one address to another address without using temp variables
SV Code -
class copy_memory ;
parameter DEPTH = 10 ;
logic [31:0] mem[DEPTH];
task swap( logic [31:0] addr_src , logic [31:0] addr_dest , logic [31:0] size );
// Intialise the memory
for (int i=0 ; i< DEPTH ; i++) begin
mem[i] = $urandom();
$display("Mem[%d] = %h ",i,mem[i]);
end
for (int i=0 ; i< size ; i++) begin
mem[addr_dest] = mem[addr_src] ;
addr_dest++;
addr_src++;
end
for (int i=0 ; i< DEPTH ; i++) begin
$display("After copying - Mem[%d] = %h ",i,mem[i]);
end
endtask
endclass
module mem_model ;
initial begin
copy_memory mem_h;
mem_h = new();
mem_h.swap(0,3,5) ;
$display ("Copy content of memory locations from one address to another address without using temp variables ");
end
endmodule
```verilog