1. Convert the following pseudo code routine into MIPS assembler language:
- Set register $t0 = 1
- In four separate instructions add 2, then 3, then 4, then 5 into register $t0
$t0 = $t0 + 2 + 3 + 4 + 5
- Copy the result from register $t0 into register $t1
2. Convert the following into MIPS assembler language:
- Set register $t0 = 0
- Initialize the register $t1 = 10
- Use register $t2 as a counter, and create a loop that repeats 5 times
- Each time through the loop, add register $t1 to $t0
- And add 10 (decimal) to register $t1
- As a result, $t0 should have the sum of the equation: 10 + 20 + 30 + 40 + 50
3. Generate an instruction sequence that will result in an arithmetic overflow. Do not use an endless loop, but rather create a specific code sequence.
Please add comments!!
1.
addi $t0 $zero 0x1 //set register $t0 =1
addi $t0 $t0 0x2 //add 2 to register $t0
addi $t0 $t0 0x3 //add 3 to register $t0
addi $t0 $t0 0x4 //add 4 to register $t0
addi $t0 $t0 0x5 //add 5 to register $t0
add $t1 $t0 $zero //$t1 = $t0+0
2.
addi $t0 $zero 0x0 //set register $t0 =0
addi $t1 $zero 0xA //set register $t1 =10
addi $t2 $zero 0x0 //set register $t2 =0
Loop:
slti $t3 $t2 0x5 //set $t3 = 1 if $t2<5
beq $t3 $zero end //if $t3 is not set branch to
end
add $t0 $t0 $t1 //$t0 = $t0+$t1
addi $t1 $t1 0xA //$t1 = $t1+10
addi $t2 $t2 0x1 //$t2 = $t2+1
j Loop //jump to Loop
end:
3.
MIPS integers are 32-bit, and since you'll be using signed
integers, the maximum value is 2^31-1 . Thus any addition which
results in a number larger than this should produce an overflow ,
e.g if you try to add 1 to 2147483647:
# Load 2147483647 into $s1
lui $s0, 32767
ori $s1, $s0, 65535
# Add 1 to $s1 and store in $s2. This should produce an
overflow
addi $s2, $s1, 1
Get Answers For Free
Most questions answered within 1 hours.