MIPS Assembly code You are tasked to calculate a specific al

MIPS Assembly code

You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f and g for the expression: f = (A^4-4B^3+3C^2-2D) g = (AB^2+C^2D^3) without using any intrinsic multiplication instructions, subroutines, and function calls. More formally, 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 = (A^4-4B^3+3C^2-2D) and g = (AB^2 +C^2D^3) 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.

Solution

.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

MIPS Assembly code You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f and g for the expression: f = (A^4-4B^3+3C^2-2D) g =
MIPS Assembly code You are tasked to calculate a specific algebraic expansion, i.e. compute the value of f and g for the expression: f = (A^4-4B^3+3C^2-2D) g =

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site