User guide

18-63
DirectC Interface
Here when the C/C++ function is declared on our Verilog code it does
not specify a bit-width or element range for the inout argument to the
mem_elem_halver C/C++ function because in the Verilog code we
call the C/C++ function twice, with a different memory each time and
these memories have different bit widths and different element
ranges.
Notice that we assign a value that included X values to the 0 element
in memory mem2.
#include <stdio.h>
#include "DirectC.h"
void mem_elem_halver(vc_handle h)
{
int i =vc_getMemoryInteger(h, 0);
i = i/2;
vc_putMemoryInteger(h, 0, i);
}
This C/C++ function inputs the value of an element and then outputs
half that value. The vc_getMemoryInteger routine returns the
integer equivalent of the element you specify by vc_handle and index
number, to an int variable i. The function halves the value in i. Then
the vc_putMemoryInteger routine passes the new value by value
to the specified memory element.
The Verilog code displays the following before the C/C++ function is
called twice with the different memories as the arguments:
mem1[0]=999
mem2[0]=X