Question
Write a program that computes 23*x. Do this by using register $7 for x and register $10 for the final result. Load $7 at the
Write a program that computes 23*x. Do this by using register $7 for x and register $10 for the final result. Load $7 at the start of the program with an ori instruction. Assume that bit patterns represent positive integers using unsigned binary. Do the multiplication by shifting and adding. Notice that 23*x is equal to 16*x + 4*x + 2*x + x.
Don't use explicit multiply instructions. Do use the addu and maybe the addiu instructions.
Don't do input or output or loading and storing from memory. The instructions up through chapter 13 are enough. Put the result in register $10 at the end of the program. Write the program so that the value for x can easily be changed by editing the ori instruction at the beginning of the program.
.text .globl main
main: ori $7, $0, 1 # put x into $7 addu $10, $0, $7 # $10 = x sll $7, $7, 1 # $7 = 2x addu $10, $10, $7 # $10 = 3x sll $7, $7, 1 # $7 = 4x addu $10, $10, $7 # $10 = 7x sll $7, $7, 1 # $7 = 8x addu $10, $10, $7 # $10 = 15x addu $10, $10, $7 # $10 = 23x
## End of file
This is what I have so far, but when I run the program through QTSPIM, register 10 at the end holds 17, not 23. I am unsure what I am doing wrong and despite trying everything I know, I cannot figure it out. Please help!! Thank you!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started