;************************************************************ ; Listing 5 - Implementing $invert in VCS ; ; "A Verilog programming-language-interface primer," ; EDN, September 2, 1999, pg 75. ; http://www.ednmag.com/ednmag/reg/090299/18ms525.htm ;************************************************************ #include "vcsuser.h" int invert_calltf(), my_checktf(); void move(); int my_checktf() { if (tf_nump() != 1) { tf_error("Usage: $invert(register_name);\n"); } if (tf_typep(1) != tf_readwrite) { tf_error ("Argument must be a register type\n"); } } int invert_calltf() { char *val_string; /* Temporarily holds the value of the reg */ /* Step 1 of the algorithm */ val_string = (char *) malloc(tf_sizep(1)+1); /* +1 to accommodate the null char at the end */ strcpy(val_string, tf_strgetp(1, 'b')); /* Step 2 of the algorithm */ move('1', '2', val_string); move('0', '1', val_string); move('z', 'x', val_string); move('2', '0', val_string); /* Step 3 of the algorithm */ io_printf("$invert: %s --> %s at time %d\n", tf_strgetp(1, 'b'), val_string, tf_gettime()); tf_strdelputp(1, tf_sizep(1), 'b', val_string, 0, 0); } void move(from, to, in_str) char from, to, *in_str; { int i=0; while(*(in_str+i)) { if (*(in_str+i) == from) *(in_str+i) = to; i++; } }