Tutorial # 2 Solution

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 3

Microprocessor-based system

Tutorial # 2 Solution

Q.1. Fill the blanks in the following questions:

1. The MIPS processor is a Reduced Instruction Set (RISC) computer.


2. The MIPS processor has 32 general purpose registers.
3. The MIPS instructions are 32 bit wide, and there are 3 instructions formats called: Register (R-
Format), Immediate (I-Format), Jump (J-Format).
4. The difference between add and addu instructions is that overflow causes an arithmetic exception
for add instruction but not for addu instruction.
5. The difference between sll and sllv instructions is the shift amount is constant for sll instruction
but variable and stored in a register for sllv.

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

2. if (a == b) c = d + e; else c = d – e; Assume that a, b, c, d, e are in $s0, …, $s4 respectively


bne $s0, $s1, else

addu $s2, $s3, $s4

j exit

else: subu $s2, $s3, $s4

exit: ...

3. if ( ($s1 > 0) && ( ($s2 < 100) {$s4++;}

ble $s1, $zero, EndIf


li $t1, 100
bge $s2, $t1, EndIf
addiu $s4, $s4, 1
EndIf:
4. if (($sl > $s2) || ($s2 > $s3)) {$s4 = 1;}

bgt $s1, $s2, L1 # yes, execute if part


ble $s2, $s3, next # no: skip if part
L1: li $s4, 1 # set $s4 to 1
next:

Q.3.

1) Name one addressing mode that does not refer to a memory location or a register.

Immediate addressing

2) What does the instruction J [R31] do?

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.

3) What does the machine instruction ADD [R2], [R3], R1 do?

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.

4) When is the JAL (jump and link) instruction used?

To go to procedures.

5) Why are registers used within a processor?

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

2) What does the instruction J [R31] do?

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.

3) What does the machine instruction ADD [R2], [R3], R1 do?

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.

4) When is the JAL (jump and link) instruction used?

To go to procedures.

5) Why are registers used within a processor?


To hold operands with high speed access. Speed of accessing operand (compared to using
memory)

You might also like