Define a struct test1 with two fields, a1: 8 bits and a2: 8 bits. Define a method m() that returns an 8-bit uint that is the sum of a1 and a2. Instantiate the struct test1 in the sys struct. Invoke the method m() in the post_generate() method of the test1 struct and assign the result to variable i using the out() method. (Hint: Use the implicit result variable.)
Define a struct test2 with two fields, b1: 8 bits and b2: 8 bits. Define a method m() as follows (Hint: Use the case action):
Argument type can have values of 0, 1, 2 or 3.
Return value is an 8-bit uint.
If type == 0, then return value = b1 + b2.
If type == 1, then return value = b1 ^ b2.
If type == 2, then return value = b1 & b2.
If type == 3, then return value = sys.test1.a1 + sys.test1.a2.
Print the value of the type and result using the outf() method.
Invoke the method m() with type == 3 in the post_generate() method of the test2 struct and assign the result to a variable i.
Instantiate the struct test2 in the sys struct.
Rewrite Exercise 2 using the if-then-else action instead of the case action. Name the struct test3 instead of test2.
Define a struct named "instruction" that contains the fields: opcode: 8 bits, op1: 8 bits and op2: 8 bits. Define l_instructions as a list of the struct instruction in the sys struct. In the sys struct, define a method loop() as follows:
Declare a local variable count of the type uint.
Declare a local variable list_size of the type uint.
Set list_size equal to the size of the l_instructions list.
Write an e style for loop using the variable count that loops from 0 to list_size-1 in list l_instructions and prints out the value of the fields of instruction using the out() method.
Write a C style for loop using the variable count that loops from 0 to list_size-1 in list l_instructions and prints out the value of the fields of instruction using the outf() method.
Write a for each loop that loops for each element in list l_instructions and prints out the value of the struct instruction using the print action.
Invoke the method loop() in the post_generate() method of the sys struct.
Extend the sys struct. Extend the method loop() using the is also keywords. Write a while loop that counts up each element in list l_instructions from 0 to list_size-1 and prints the struct instruction using the print action. (Hint: You may need to redeclare the variable count.)
Load all code from exercises 1 to 5 into Specman Elite and verify that it loads without error.