Test 2 Answer
Test 2 Answer
TEST 2 (Anwer)
Instruction to candidates :
Answer ALL questions by writing your final answers on the table given. Candidates are allowed to
use non-programmable scientific calculator.
Q1. Answer the following questions based on the assembly code below:
Figure 1
(a) Translate the following assembly code to machine code. Express your answer in hexadecimal.
Answer:
Opcode rs rt immediate
Chex 910 910 FFhex
0 0 1 1 0 0 0 1 0 0 1 0 1 0 0 1 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
3 1 2 9 0 0 F F
Answer = 0x3129 00FF
(ii) beq $t1, $zero, exit (5 marks)
Answer:
Opcode rs rt immediate
4hex 910 010 410
0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0
1 1 2 0 0 0 0 4
Answer = 0x1120 0004
(b) Assuming that the initial value of $t1 is equal to 0x2F45, and $t2 is equal to 0x001F,
determine the new values of the following registers. Express your answer in hexadecimal.
(i) $t1 after the instruction “andi $t1, $t1, 0xFF”. (5 marks)
Answer:
(ii) $t2 after the instruction “add $t2, $t2, $t1”. (2 marks)
Answer:
Answer:
Answer:
Load and store instructions involved memory access, where the memory
address is calculated from base address + offset.
Therefore, the answer is base (displacement) addressing modes.
(d) Name TWO (2) pseudoinstructions that were used in the assembly code above. (4 marks)
Answer:
Move
Li
[25 marks]
Q2. (a) Translate the following machine code to assembly code: 0x022B8025. (5 marks)
Answer:
R –format has the following fields: opcode (6 bits), rs (5bits), rt (5bits), rd (5bits), shamt
(5bits), and funct (6bits).
Break the number according to the fields:
0 2 2 B 8 0 2 5
0 0 0 0 0 0 1 0 0 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 0 0 1 0 0 1 0 1
opcode rs rt rd shamt funct
Answer:
Convert to hexadecimal: 0000 0000 0100 0000 0000 0000 0010 0100
The answer is 0x0040 0024
(c) Arrange the following action in the correct sequence during a function call. (5 marks)
C → F → A. → B → D → E
Answer:
Register
Memory
Instruction / Constant / Immediate
(i) A register that hold the address after a jal instruction. (2 marks)
Answer:
$ra
(ii) A special register that hold the address of the current instruction being executed.
(2 marks)
Answer:
[25 marks]
___________________________