Admin
===========================Q1========================
2021_sep
a) [2] Which of the following statements best describes the term program counter?
1. It stores the number of steps a program takes to execute
2. When an instruction is executing, it stores the address of the previous instruction that executed
3. When an instruction is executing, it stores the address of that instruction
4. When an instruction is executing, it stores the address of the next instruction to execute
5. When an instruction is executing, it stores the previous instruction that executed
6. It stores the size of the program in bytes
7. It stores the total number of instructions in a program
8. When an instruction is executing, it stores that instruction
9. When an instruction is executing, it stores the next instruction to execute
b) [2] Our ISA has two types of instructions for transferring control to a new location; i.e.,
to a target address: jump and branch. Which of the following statements best describes the
difference between these two types of control-transfer instructions. To make the comparison
fair, just consider the unconditional version of each instruction (i.e., j and br).
1. Jump has a more narrow range of possible target addresses, but is potentially faster than branch
2. They do exactly the same thing, but branch is potentially faster than jump
3. Branch has a more narrow range of possible target addresses, but is potentially faster than jump
4. In assembly code, they use different formats to specify the target address
5. They do exactly the same thing, but jump is potentially faster than branch
===========================Q2========================
2021_sep
Reading Assembly Code [10 marks]
ld $n, r0 #
ld (r0), r0 #
ld $a, r1 #
ld $0, r2 #
ld $0, r3 #
L0: beq r0, L5 #
ld (r1, r2, 4), r5 #
L1: ld (r5), r6 #
beq r6, L4 #
bgt r6, L2 #
inc r3 #
L2: inca r5 #
br L1 #
L4: inc r2 #
dec r0 #
br L0 #
L5: ld $r, r0 #
st r3, (r0) #
a) [6] Add comments to the assembly code show on the previous page.
Draw arrows for branches. Draw and label boxes to identify templates for control-flow structures.
Make your comments as high-level, C-like as possible.
b) [2] Give an equivalent C program.
c) [2] Describe in plain English what this code computes.
===========================Q3========================
ld $x, r7
ld $z, r6
ld $0, r0
ld $0, r1
L0: ld (r6), r2
not r2
inc r2
add r1, r2
beq r2, L1
ld (r7, r1, 4), r2
add r2, r0
inc rl
br L0
L1: ld $-100, r1
add r0, r1
bgt rl, L2
ld $0, r0
br L3
L2: ld $1, r0
L3: ld $y, r5
st r0, (r5)
halt
===========================Q4========================
===========================Q5========================
===========================Q6========================
===========================Q7========================
===========================Q8========================
===========================Q9========================
===========================Q10========================
===========================Q11========================
===========================Q12========================
===========================Q13========================