This tutorial is intended to follow the tutorial on accessing registers in a microprogram.
The purpose of this tutorial is to learn how to access memory in a microprogram. The example program duplicates the value at the top of the stack by reading the value and pushing it onto the stack.
1. Click on the Microprogram Editor tab.
2. Clear the control store (Control menu; Clear Control Store).
In order to read the value at the top of the stack, the value in SP (register 4) must be copied to the MAR and a read operation initiated.
3. Set the "Next Addr" field to 000000001.
4. Set up the ALU, B-bus, and C-bus fields to load the value in the SP register into the MAR. You should know how to do this from the tutorial on accessing registers.
5. Set the "Read" bit to 1 to initiate the read operation.
Here is the microinstruction at 0x000:
The read operation initiated in the first instruction has not yet been completed; the requested value has not yet been loaded into the MDR by memory. There is, however, some useful work that can be done while we wait. Since we will be pushing the value we read from memory onto the stack, we can increment the SP and, simultaneously, load the new stack pointer address into the MAR.
6. Set the "Next Addr" field to 000000010.
7. Set up the ALU, B-bus, and C-bus fields to load the value of the SP into the ALU, increment it, and store the result back in the SP and in the MAR. The only thing new here is the increment operation. Earlier, you set the ALU to generate the sum 0 + B-Bus. Now, you want the ALU to generate the sum (0 + B-Bus) + 1. (Try to figure out how to do this before continuing.) All you need to do is to set the INC bit in the ALU section of control bits.
We are not initiating a new memory access operation so the memory access bits should all be set at 0.
Here is the microinstruction at 0x001:
After the second microinstruction has been executed, the read operation initiated in the first instruction will have been completed and the top of stack value will be in the MDR. The stack pointer has been incremented and the new stack pointer value has been copied to the MAR. All we need to do in this instruction is initiate the write operation.
8. Set the "Next Addr" field to 000000011.
9. Set the "Write" bit to 1.
10. The write operation initiated in the previous instruction will be completed following the execution of this instruction. Since there is nothing else to do, this will be the micro "halt" instruction (the next address is 0xFF and everything else zeroes).
Here is the complete program:
If you want, you can save your microprogram before continuing (Control menu; Save Control Store).
11. Click on the Computer Simulator tab.
12. Click the Reset button.
13. Click the Goto SP button (below the memory display on the left).
14. Make sure the Display Words radio button is selected.
15. Enter a value of 10 at word address 4096 (the top of the stack).
16. Click the Micro Step button to execute the first microinstruction. The data path display should confirm that the address stored in the SP register was copied to the MAR and that a read operation was initiated (indicated by the green arrow pointing from the MAR to memory).
17. Click Micro Step. The read operation has finished as indicated by
The stack pointer indicater ("SP == >" ) has moved to address 4097 because you incremented the value in SP. Finally, the new SP value was also loaded into the MAR.
18. Click Micro Step. The green arrow pointing from the MAR towards memory indicates that the requested memory access has begun:
19. Click Micro Step. The write operation has finished as indicated by
The microprogram has terminated.
20. Click Reset and change the value at the top of the stack (address 4096) to 20.
21. Click the Run button. Confirm that the value on the top of the stack has been duplicated. The SP value should be 4097 and a value of 20 should be stored at that address.
The next tutorial covers arithmetic in a microprogram.