Professional Documents
Culture Documents
Laboratory Exercise 2 (MIDTERM)
Laboratory Exercise 2 (MIDTERM)
Laboratory Exercise 2 (MIDTERM)
Laboratory Exercise
Basic CPU Instructions
Objectives:
Create instructions that will move data into the CPU registers;
Create instructions that will compare values in CPU registers;
Push data to the stack and pop data from the stack;
Create instructions that will jump register content to another address location;
Add values in CPU registers; and
Demonstrate compare instruction’s effect on the status register flags.
Materials:
Basic Principles:
Procedures:
Perform what is being asked.
1. Open the CPU-OS Simulator application.
2. Create a new program. Type Act2 – Surname as your program name in the Program Name text
box located in the program frame below the CPU instructions in memory (RAM). Ex: Act2 -
DelaCruz
3. Type in number zero (0) in the Base Address text box. Then, click the ADD button.
4. In the instructions tab, click ADD NEW button. This will display the Instructions: CPU0 window.
5. Create an instruction that moves number 5 to register R00. Refer to the data transfer instructions
table.
6. Execute the instruction done by simply double clicking on the item in the CPU INSTRUCTIONS
IN MEMORY (RAM) view.
7. Create an instruction that moves number 8 to register R01, then execute it. Observe the contents
of R00 and R01 in the Register Set view.
8. Create an instruction that adds the contents of R00 and R01, then execute it. Refer to the
arithmetic instructions table above.
9. In which register is the result stored? What is the value of that register? Write your answer on the
space provided.
10. Create an instruction that pushes the answers in Step 9 to the top of the program stack, and then
execute it. Observe the result in PROGRAM STACK (RAM) view.
11. Create an instruction that will push number -2 on top of the stack and execute it.
12. Create an instruction that will compare the values in registers R00 and R01 then execute it.
13. Record the status (i.e., set or reset) of the Z/N flags of the status register. If the box is checked
then means set; otherwise, means not set.
14. Create an instruction that will unconditionally jump to the first instruction done in item #5, then
execute it.
15. Observe the Special CPU Registers value in the PC register. To which address is it pointing?
Explain your answer on the space provided.
It is pointing at 8100. Program Counter Register is 29, Status register is 3 and base register
is 0.
16. Create an instruction that will pop the value on top of the program stack into register R02, then
execute it.
17. Create an instruction that will pop the value on top of the program stack into register R03, then
execute it.
18. Execute the last instruction again, which is done in Step 17. What happened? Explain your
answer on the space provided.
An error has occurred stating that “Stack underflow, i.e. the stack is empty!”
19. Create an instruction that will compare the values in registers R04 and R05.
20. Manually insert two (2) equal values in registers R04 and R05. Execute the compare instruction
done in item #19.
21. Which of the status flags Z/N is set? Why? Explain your answer on the space provided.
22. Manually insert a value in register R05 greater than that in register R04. Execute the compare
instruction done in item #19.
23. Which of the status flags Z/N is set? Why? Explain your answer on the space provided.
24. Create an instruction that will conditionally jump to the first instruction done in item #5 if the values
in registers R04 and R05 are equal. Note: You will need to execute the compare instruction first
before you execute the jump instruction if you change values in R04 and R05.
25. Test the instruction done in item #24 by manually putting values in registers R04 and R05. Then,
execute the compare instruction and execute the jump instruction (i.e., you will need to execute
the compare instruction first before you execute the jump instruction every time you change
values in R04 and R05).
26. Call the attention of the Lab Facilitator once finished.