assembly code calculate a algebraic f and g f = (A^4-4B^3+3C^2-2D) g = (AB^2+C^2
ID: 3903120 • Letter: A
Question
assembly code
calculate a algebraic f and g
f = (A^4-4B^3+3C^2-2D)
g = (AB^2+C^2D^3)
without using any intrinsic multiplication instructions, subroutines, and function calls.
write MIPS assembly code that accepts four positive integers A, B, C, and D as input parameters. The
code shall execute in MARS to prompt the user to enter four positive integers represented in decimal,
each separated by the Enter key. The program shall calculate f and g using your own self-written multiplication routine.
The program will then output f and g in
decimal and binary, using syscall routines for each output.
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. must use a loop. No use of Macro, Subroutines, or Functions
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
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.