/* ---------------------------------------------------------------------------- Parity generator, using a function with an unconstrained input. 'odd_parity' returns true if the input has an odd number of bits set, and false otherwise. Note: 1 - the predefined 'result' variable is used to return the parity 2 - the use of the slice operator to extract a single bit of 'a'. In general, a range can be extracted; 'a.(3:0)', for example, returns the low nibble in 'a' 3 - the predefined _assertCount and _errorCount variables are used to display the number of assertions executed, and the number that failed. Run this code as 'rtv parity_gen.tv'. The expected output is: _assertCount: 8; _errorCount: 0 If you change the code and expect errors to be reported, then you will need to ensure that your program does not terminate after the first assertion failure. To do this, run the code as 'rtv --rte 20 parity_gen.tv'. The code will now keep running until 20 errors are reported. * ------------------------------------------------------------------------- */ void main() { bit1 a = 1'b1; assert( odd_parity(a)); bit2 b = 2'b01; assert( odd_parity(b)); bit3 c = 3'b101; assert(!odd_parity(c)); bit4 d = 4'b0101; assert(!odd_parity(d)); bit5 e = 5'b10101; assert( odd_parity(e)); bit6 f = 6'b010101; assert( odd_parity(f)); bit7 g = 7'b1010101; assert(!odd_parity(g)); bit8 h = 8'b01010101; assert(!odd_parity(h)); report("_assertCount: %d; _errorCount: %d\n", _assertCount, _errorCount); } bool odd_parity(ubit a) { result = false; // default value; here only for clarity for(int i=0; i