Previous Section Next Section

4.8 Exercises

  1. Define a struct named "instruction" that contains the following fields:

    1. opcode: 8 bits

    2. op1: 8 bits

    3. op2: 8 bits

  2. Extend the definition of struct "instruction" by adding the following fields:

    1. kind_op2: A field of enumerated type with two values, imm and reg. (Hint: You may need to define an enumerated type before you add the field.)

    2. memory_instr: boolean

  3. Extend the definition of the predefined struct sys by adding the following fields:

    1. l_instructions: A list of struct instruction

    2. data: A list of 8-bit unsigned integers

    3. memory_test: boolean

  4. Extend the run() method within sys to modify the l_instructions list as follows. (Hint: You may need to add a variable of type instruction before modifying the list.)

    1. Add an instruction to the end of the list.

    2. Delete an instruction from the head of the list.

    3. Insert an instruction at index == 5.

  5. Extend the definition of struct "instruction" using the when subtype to conditionally add the following fields:

    1. When the field kind_op2 is generated as imm, define a new field called imm_value that is an 8-bit unsigned value.

    2. When the field kind_op2 is generated as reg, define a new field called reg_value that is an 8-bit unsigned value.

  6. For each of the following, choose whether a struct or a unit should be used to represent it in e.

    1. A data object used to represent a single test vector

    2. An input driver that drives each data object onto the device

    3. A protocol monitor that monitors the protocol on the bus

  7. Define a unit named "port" that contains the following fields:

    1. port_id: 8 bits

    2. data: 8 bits

    3. clock: 8 bits

  8. Create three instances (port0, port1, and port2) of the unit port in struct sys.

  9. In struct sys bind the instances of unit "port" to the corresponding HDL hierarchy instances using hdl_path() as follows:

    1. port0 to "~/top/router_i/chan0"

    2. port1 to "~/top/router_i/chan1"

    3. port2 to "~/top/router_i/chan2"

  10. Load all code from exercises 2 to 9 into Specman Elite and verify that it loads without error.

Previous Section Next Section