Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Assembly Language Write a program that determines the value of the following exp

ID: 3685813 • Letter: A

Question

Assembly Language

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.

2. Your program has a data section declared as follows: .data .byte 12 .byte 97 .byte 133 .byte 82 .byte 236 Write a program that adds the values up and computes the average. Please use $8 to save the base address, $9 to save the average, and $10 to save intermediate results.

Explanation / Answer

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.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote