CS232, Spring 2008
Wombat
Programming assignments W4-1
due:
Friday, March 14
Assignment
Modify the Wombat3 by adding two new instructions and by modifying the jmp, jmpz, and jmpn machine instructions so that they use pc-relative addressing. Call the result the Wombat4. Then write a Wombat4 program that uses the two new instructions and one or more of the jump instructions to do something interesting.
Details about creating the Wombat4
- To change the addressing mode of the three jump instructions, start up CPU Sim and load the Wombat3 machine.
- Use the "Machine instructions..." menu item from the Modify menu to open the Machine Instruction Dialog. Click on the "Edit Fields..." button to bring up the dialog for editing fields. Add a new field named "relAddr" whose type is "required", numBits is "8", relativity is "pcRelativePostIncr", default value is 0, and check the signed box. Then click the OK button to close the fields dialog.
- In the Machine Instructions dialog, change the format of the three jump instructions so that the last symbol is "relAddr" instead of "addr".
- The assembler will now put the relative offset of the jump into the last 8 bits of the instruction, rather than the absolute address of the jump. More precisely, the value in the last 8 bits of the instruction is the offset of the jump from the instruction immediately after the jump instruction rather than the offset from the jump instruction itself. Note that the offset will be negative for a backward jump and positive for a forward jump.
- Modify the microinstructions in the execution sequences of the three jump instructions so that they behave properly.
- Add a new instruction, "loadc" ("load constant") for loading a constant into one of the A registers. It should have the
5-bit opcode 11 (hex). The first operand (3 bits wide) is the index of the
register to be loaded and the second operand (8 bits wide) is the actual value
(in 8-bit 2's complement notation) to be loaded into the register. Therefore the instruction should have format "op reg delta8", where "delta8" is a new field of 8 bits whose type is "required", relativity is "absolute", default value is "0", and is signed. The instruction
would appear in your Wombat4 programs as follows:
loadc A0 -1 ;loads the value -1 into A[0]
loadc A0 55 ;loads the value 55 into A[0]
- Add a new instruction, "incr" ("increment") for incrementing or decrementing one of the A registers. It should have the
5-bit opcode 12 (hex). The first operand (3 bits wide) is the index of the
register to be incremented and the second operand (8 bits wide) is the amount
(in 8-bit 2's complement notation) by which the register is to be incremented. Therefore the instruction should, like the loadc instruction, have format "op reg delta8". The instruction
would appear in your Wombat4 programs as follows:
incr A0 1 ;increments the value in A[0] by 1
incr A0 -2 ;increments the value in A[0] by -2 (or, equivalently, decrements A[0] by 2)
- Save your changes and call the result the Wombat4.
- Test your changes to the jump instructions using the W3-1.a code from the previous project and any other test code you want to use. You should not need to change the W3-1.a assembly code.
- Thoroughly test your new loadc and incr instructions as well (I will when I grade it).
Exercise W4-1
Create your own Wombat4 assembly language program called "W4-1.<your-last-name>.a" that (a) does something interesting, (b) uses the loadc and incr instructions, and (c) uses at least one of the three modified jump instructions. Be creative!
What to Hand In
No hard copies are necessary this time. Just
email me an electronic copy of your "Wombat4.cpu" renamed "Wombat4.<your-last-name>.cpu" (for
example, I would name my file "Wombat4.Skrien.cpu") and an electronic copy of your "W4-1.<your-last-name>.a" assembly language program. PLEASE name your files correctly!