Please follow all the instructions You are tasked to calculate a specific algebr
ID: 663639 • Letter: P
Question
Please follow all the instructions
You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f and g for theexpression:
f = (A4-4B3+3C2-2D)g = (AB2+C2D3)
without using any intrinsic multiplication instructions. More formally, write MIPS assembly code thataccepts four positive integers a, b, c, and d as input parameters. The code shall execute in MARS toprompt the user to enter four positive integers represented in decimal, each separated by the Enter key.The program shall calculate f=(A4-4B3+3C2-2D) and g=(AB2+C2D3) using your own self-writtenmultiplication routine. The program will then output f in decimal and binary, using syscall routines foreach 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 tocompose your own multiplication technique. In addition, use of a loop is required for credit to realize themultiplication code.
Explanation / Answer
__start:
la $a0, prompt # address of prompt goes in
li $v0, 4 # service code for print string
syscall
sw $v1, Num1 # store what was entered
li $v1, 4 # service code
syscall
sw $v2, Num2 # store what was entered
li $v2, 4 # service code
syscall
sw $v3, Num3 # store what was entered
li $v3, 4 # service code
syscall
sw $v4, Num4 # store what was entered
li $v4, 4 # service code
move $t0, $0 #sum=0
move $v1, $0 #num=0
while4:
bltz $v1, endwhile4
mul $t0, $v1
#$v1 switches role here
la $v1,avar #read int call
syscall
endwhile4:
move $t0, $0 #sum=0
move $v2, $0 #num=0
while3:
bltz $v2, endwhile3
mul $t0, $v2
#$v2 switches role here
syscall
endwhile3:
mul $v2,4
la $v2,bvar #read int call
move $t0, $0 #sum=0
move $v3, $0 #num=0
while2:
bltz $v3, endwhile2
mul $t0, $v3
#$v3 switches role here
syscall
endwhile2:
mul $v3,3
la $v3,cvar #read int call
mul $a4,$v0,4
lw $t0, avar
lw $t1,bvar
sub $a1,$t0,$t1
lw $t0, cvar
sub $a2, $t0, $v0
add $a3,$a1,$a2
la $a3,f
li $v0, 4
syscall
li $v0, 10
#------------------------------------------------------------------
# Data segment
#------------------------------------------------------------------
.data
Num1: .word 0
Num2: .word 0
Num3: .word 0
Num4: .word 0
prompt: .ascii "Please type 4 integers, end each with the "
.asciiz "Enter key: "
f: .asciiz " is the sum. "
#------ end of file ADDNUMS.ASM