User guide
18-61
DirectC Interface
scalar vc_getMemoryScalar(vc_handle, U indx)
Returns the value of a one-bit memory element. For example:
extern void bitflipper (inout reg array [127:0] mem1);
module test;
reg mem1 [127:0];
initial
begin
mem1 [0] = 1;
$display("mem1[0]=%0d",mem1[0]);
bitflipper(mem1);
$display("mem1[0]=%0d",mem1[0]);
$finish;
end
endmodule
Here in this Verilog code we declare a memory with 128 one-bit
elements, assign a value to element 0, and display its value before
and after we call a C/C++ function named bitflipper.
#include <stdio.h>
#include "DirectC.h"
void bitflipper(vc_handle h)
{
scalar holder=vc_getMemoryScalar(h, 0);
holder = ! holder;
vc_putMemoryScalar(h, 0, holder);
}
Here we declare a variable of type scalar, named holder, to hold
the value of the one-bit Verilog memory element. The routine
vc_getMemoryScalar returns the value of the element to the
variable. The value of holder is inverted and then the variable is
included as a parameter in the vc_putMemoryScalar routine to
pass the value to that element in the Verilog memory.