Using Psuedo-Code and assembly code format. Write a subroutine which takes two i
ID: 3546198 • Letter: U
Question
Using Psuedo-Code and assembly code format.
Write a subroutine which takes two inputs in R5 and R6 and returns a
result in R7 which is the product of R5 and R6. Use the (very inefficient) method of repeated
additions to achieve the multiplication.
R5 and R6 are 16?bit non?zero positive integers each less than 255. Use stack based local
variables.
Example:
45*3 = 45 + 45 + 45 (add 45, 3 times)
Note that for 156*5 you would want to do:
156 + 156 + 156 + 156 + 156 (add 456, 5 times)
and not:
5 + 5 + 5 +
Explanation / Answer
## i can't exactly understand your question.. Anyways, this is the assembly code (mips) for the program.. Data read in $t5 and $t6, then stored in stack, then the func is called.. it then returns the answer in the stack itself and the answer is then stored in $t7
.data
number_prompt:
.asciiz "Enter the number: "
out_msg:
.asciiz " and their product is: "
#####Code Segment###########
.text
.globl main
main:
la $a0,number_prompt
li $v0,4
syscall
li $v0,5
syscall
move $t5, $v0
la $a0,number_prompt
li $v0,4
syscall
li $v0,5
syscall
move $t6, $v0
blt $t5, $t6, swap
end_swap:
sub $sp, $sp, 4
sw $t5, ($sp)
sub $sp, $sp, 4
sw $t6, ($sp)
jal compute_pro
lw $t7, ($sp)
add $sp, $sp, 4
la $a0,out_msg
li $v0,4
syscall
li $v0, 1
move $a0, $t7
syscall
b exit
exit:
li $v0, 10
syscall
swap:
move $t4, $t5
move $t5, $t6
move $t6, $t4
b end_swap
compute_pro:
li $t7, 0
lw $t6, ($sp)
add $sp, $sp, 4
lw $t5, ($sp)
add $sp, $sp, 4
loop:
add $t7, $t7, $t5
sub $t6, $t6, 1
bgtz $t6, loop
end_loop:
sub $sp, $sp, 4
sw $t7, ($sp)
jr $ra
la $a0,out_msg
li $v0,4
syscall
li $v0, 1
move $a0, $t7
syscall
b exit
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.