Assembly language programming of the MIPS 1. Exercise 2 — Shifting and Adding In
ID: 3865193 • Letter: A
Question
Assembly language programming of the MIPS
1. Exercise 2 — Shifting and Adding
Initialize the sum in register $8 to zero. Then add 409610 to $8 sixteen times. You don't know how to loop, yet, so do this by making 16 copies of the same instruction. The value 409610 is 0x1000.
Next initialize register $9 to 409610. Shift $9 left by the correct number of positions so that registers $8 and $9 contain the same bit pattern.
Finally, initialize aregister $10 to 409610. Add $10 to itself the correct number of times so that it contains the same bit pattern as the other two registers.
2. Exercise 4 — Arithmetic Expression
Let register $8 be x and register $9 be y. Write a program to evaluate:
Leave the result in register $10. Inspect the register after running the program to check that the program works. Run the program several times, initialize x and y to different values for each run. (use X=1, Y=2)
Explanation / Answer
1. Exercise 2:
MOVE $8,$ZERO #Initializing $8 to 0
#Adding 16 times the value 0x1000 to $8
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
ADD $8,$8,0x1000
MOVE $9,0x1000 #Initializing $9 to 0x1000
SLL $9,$9,4 #2^4 = 16. shifting left 4 times is equivalent to muliplying by 16.
MOVE $10,0x1000 #Initializing $10 to 0x1000
#Adding $10 to itself 15 times to make it equal to $8
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
ADD $10,$10,$10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.