Tutorial # 2 Solution
Tutorial # 2 Solution
Tutorial # 2 Solution
Tutorial # 2 Solution
Q.2. Write the minimum required MIPS instructions to implement each of the following. Pseudo instruction
can be used.
1. Multiply the content of register $s1 by 30 without using multiplication instructions.
sll $t1, $s1, 5 # $t1=32*$s1
sll $s1, $s1, 1 # $s1=2*$s1
subu $s1, $t1, $s1 # $s1=2*$s1
j exit
exit: ...
Q.3.
1) Name one addressing mode that does not refer to a memory location or a register.
Immediate addressing
Changes the execution sequence to the location whose address is given in R31, i.e. go to the location
whose address is held in R31.
Add the contents of R1 with the contents of memory location whose address is held in R3, and puts
the result in the memory location whose address is held in R2. (If R1 32-bits, 4 consecutive memory
locations used.) Also acceptable to have [R2] as source and R1 as destination.
To go to procedures.
To hold operands with high speed access. Speed of accessing operand (compared to using memory)
3. if (a > 0) b = a + 10; else b = a - 10;
slt $t0, $0, $t1 # if $0 < $t1 then $t0 = 1, else $t0 = 0
beq $t0, $0, else # if $t0 == $0 then branch to else
addi $t2, $t1, 10
j exit
else: addi $t2, $t1, -10
exit:
Q.3.
1) Name one addressing mode that does not refer to a memory location or a register.
Immediate addressing
Changes the execution sequence to the location whose address is given in R31, i.e. go to the
location whose address is held in R31.
Add the contents of R1 with the contents of memory location whose address is held in R3,
and puts the result in the memory location whose address is held in R2. (If R1 32-bits, 4
consecutive memory locations used.) Also acceptable to have [R2] as source and R1 as
destination.
To go to procedures.