Use QtSpim. Write a program that determines the value of the following expressio
ID: 3685805 • Letter: U
Question
Use QtSpim.
Write a program that determines the value of the following expression:
(x*y)/z
Use x = 1600000 (=0x186A00), y = 80000 (=0x13880), and z = 400000 (=61A80). Initialize three registers ($8, $9, and $10) to these values. Since the immediate operand of the ori instruction is only 16 bits wide, use shift instructions to move bits into the correct locations of the registers.
Choose wisely the order of multiply and divide operations so that the significant bits always remain in the lo result register.
Explanation / Answer
#Designed to demonstrate ways around bit width for immediates and stuff
ori $8, $0, 1562 #x- 1600000- all shifted right, needs to be shifted left to be 32 bit, its shift is 10
ori $9, $0, 78 #y- 80000- shifted right 10, needs to be shifted left to be 32 bit wide
ori $10, $0, 390 #z- 400000- shifted right 10, needs to be shifted left to be 32 bit wide
ori $11, $0, 0 #temp register
multu $8, $9 #x * y
mflo $11 #temporarily store the result of x and y
nop
nop
divu $11, $10 #divides z by the result of x * y
mflo $11 #stores the result in register 11
sll $11, $11, 10 #shifts the binary left
#end of program
#result is almost as good as doing left shift earlier in code, but its good enough. It's got a margin of error of
#about 1000 or so.
The above code simply shifts a binary number right to a certain number of places, performs a function on the values, then shifts the number left again, in order to fit 32 bit calculations into 16 bit areas and stuff
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.