For these programming exercises, use only those instructions that have been disc
ID: 3737984 • Letter: F
Question
For these programming exercises, use only those instructions that have been discussed so far in these notes:
ori
USING MIPS SIMULATOR
Let register $8 be x. Write a program that computes 13x. Leave the result in register $10. Initialize x to 1 for debugging. Then try some other positive values.
Extend your program so that it also computes -13x and leaves the result in register $11 (This will take one additional instruction.) Now initialize x to -1. Look at your result for 13x. Is it correct?
add sll addi srl addiu sub addu subu and nor andi xor or xoriori
USING MIPS SIMULATOR
Let register $8 be x. Write a program that computes 13x. Leave the result in register $10. Initialize x to 1 for debugging. Then try some other positive values.
Extend your program so that it also computes -13x and leaves the result in register $11 (This will take one additional instruction.) Now initialize x to -1. Look at your result for 13x. Is it correct?
Explanation / Answer
# 10 = 13*x li $8, 1 # x = 1 sll $10, $8, 4 # $10 = 16*x sll $9, $8, 1 # temp = 2*x sub $10, $10, $9 # $10 = 14*x sub $10, $10, $8 # $10 = 13*x # 10 = -13*x li $8, 1 # x = 1 sll $11, $8, 1 # $11 = 2*x add $11, $11, $8 # $11 = 3*x sll $9, $8, 4 # temp = 16*x sub $11, $11, $9 # $11 = -13*x