You are tasked to calculate a specific algebraic expansion, i.e. compute the val
ID: 3561655 • Letter: Y
Question
You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f for the expression f=[a+(a*b)+(a*b*c)] without using any intrinsic multiplication instructions. More formally, write MIPS assembly code that accepts three positive integers a, b, and c as input parameters. The code shall execute in MARS to prompt the user to enter three positive integers represented in decimal, each separated by the Enter key. The program shall calculate f=[a+(a*b)+(a*b*c)] using your own self-written multiplication routine. The program will then output f in decimal and binary, using syscall routines for each output. Note: To receive credit, no multiplication, no division, and no shift instructions shall be used. Namely, none of { mul, mul.d, mul.s, mulo, mulou, mult, multu, mulu, div, divu, rem, sll, sllv, sra, srav, srl, srlv } or else a zero score will result. Thus, it is necessary to compose your own multiplication technique. In addition, use of a loop is required for credit to realize the multiplication code.
Explanation / Answer
.data
message: .asciiz "Enter three integrs seperated by Enter key value: "
message1: .asciiz " f = a + a*b + a*b*c: "
val_1: .word 0
val_2: .word 0
val_3: .word 0
.text
main :
#ask user
li $v0,4
la $a0,message
syscall
# Read first integer and put in val_1
li $v0,5
syscall
la $t1,val_1
sw $v0,0($t1)
add $a0,$0,$v0 #a
# Read first integer and put in val_2
li $v0,5
syscall
la $t1,val_2
sw $v0,0($t1)
add $a1,$0,$v0 #b
jal my_mul #$a2 = a*b
la $t1,val_1
lw $a0,0($t1) #a
add $a3,$a0,$a2 # a + a*b
# Read first integer and put in val_3
li $v0,5
syscall
la $t1,val_3
sw $v0,0($t1)
add $a0,$0,$v0 #c
add $a1,$0,$a2
jal my_mul
add $a3,$a3,$a2 # a + a*b + a*b*c
li $v0,4
la $a0,message1
syscall
li $v0,1
addi $a0,$a3,0
syscall
forever : j forever
my_mul: #input in $a0,$a1 and output in $a2 = $a1*$a0
addi $a2,$0,0
again:beq $a0,$0,end
add $a2,$a2,$a1
subi $a0,$a0,1
b again
end:jr $ra
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.