Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write an arithmetic unit and related self testing in MIPS assembly as following.

ID: 3761866 • Letter: W

Question

Write an arithmetic unit and related self testing in MIPS assembly as following. Put all the source codes in a directory and compress them into a zip file and upload. Grader should be able to download your zip file, unzip it and directly load it into MARS for final machine code generation and run - without any error.

1. The over all program should ask user for two integer numbers (a, b) and target arithmetic operation (+,-,*./) and will print the result of the operation with a comment if the result produced is correct or not.

2. Write add_normal, sub_normal, mul_normal and div_normal procedures which all takes $a0 and $a1 as two argument integers and returns the operation results in $v0 (and in $v1 for Hi result in mul or div). All these *_normal uses only native arithmetic operation of MIPS.

3. Write add_logic, sub_logic, mul_logic and div_logic procedures which all takes $a0 and $a1 and two argument integer and returns the operation results in $v0 (and in $v1 for Hi result in mul or div). All these *_logic uses only native logic operation of MIPS. They implement arithmetic operation using logic algorithm taught in CS47.

4. Write two procedure au_normal and au_logic which takes two integers and one operation code for +,-,* and / in $a0, $a1 and $a2. These two procedure returns results in $v0 and $v1 ($v1 contains the Hi value of the result from * or /). The main program (Label must be 'main') calls au_logic to determine the result and print the result as it gets back from the au_logic. This au_logic uses all the *_logic procedures implemented in #3. The main program also calls au_normal procedure to determine golden result and compare it with the result obtained from au_logic to determine pass or fail. It prints the result pass / fail. This au_normal uses all the *_normal procedure implemented in #2.

Explanation / Answer

Hi,

Below are your programs:

Program 1:

Answer:

.data

string0: .asciiz "nWelcome to calculator program!!!!"
string1: .asciiz "nn Enter first value a: "
string2: .asciiz " Enter (+, -, /, *): "
string3: .asciiz "n Enter second value b: "
string4: .asciiz "n Invalid Operator! Try again. "
string5: .asciiz "n Answer is: "
string6: .asciiz "nn Another Calculation? y, n: "
string7: .asciiz "nn Invalid input! Please enter y or n."
string8: .asciiz "nn Calculator is Terminated."

.text
.globl main

main:
addi $v0, $0, 4

la $a0, string0 //Loads and Prints the hellp message

syscall #printing str0

calculator:

addi $v0, $0, 4

la $a0, string1 //Prompts user to key in his value for a:

syscall #printing string1

addi $v0, $0, 6

syscall
mov.s $f1, $f0   #reading and storing first value

addi $v0, $0, 4

la $a0, string2

syscall #printing string2

addi $v0, $0, 12

syscall #Now reading operator

add $a1, $v0, $0   #storing the operator

addi $v0, $0, 4

la $a0, string3
syscall #printing string3

addi $v0, $0, 6

syscall
mov.s $f2, $f0   #reading and storing second value

addi $9, $0, 0x2b
beq $a1, $9, addIt   #checking if +

addi $9, $0, 0x2d
beq $a1, $9, subIt   #checking if –

addi $9, $0, 0x2a
beq $a1, $9, mulIt   #checking if *

addi $9, $0, 0x2f
beq $a1, $9, divIt   #checking if /

addi $v0, $0, 4

la $a0, string4

syscall #printing string4 if invalid operator is chosen.
j calc

addIt:
add.s $f12, $f1, $f2   #adding values
j printAnswer

subIt:
sub.s $f12, $f1, $f2   #subtracting values
j printAnswer

mulIt:
mul.s $f12, $f1, $f2   #multiplying values
j printAnswer

divIt:
div.s $f12, $f1, $f2   #dividing values
j printAnswer

printAnswer:
addi $v0, $0, 4

la $a0, string5

syscall #printing string5

li $v0, 2
syscall #Now printing the answer
//Checking to see if user wants to perform another calculation
j anotherCalc

anotherCalc:
addi $v0, $0, 4

la $a0, string6

syscall #printing string6

addi $v0, $0, 12

syscall #reading command

add $a1, $v0, $0   #storing command

addi $9, $0, 0x79
beq $a1, $9, calc   #checking if y

addi $9, $0, 0x6e
beq $a1, $9, exitApp   #checking if n

addi $v0, $0, 4

la $a0, string7

syscall #printing string7
j anotherCalc

exitApp:
addi $v0, $0, 4

la $a0, string8

syscall #printing string8
jr $31 # Exit main subroutine.

Program 2:

Answer:

.data

string0: .asciiz "nWelcome to calculator program!!!!"
string1: .asciiz "nn Enter first value a: "
string2: .asciiz " Enter (+, -, /, *): "
string3: .asciiz "n Enter second value b: "
string4: .asciiz "n Invalid Operator! Try again. "
string5: .asciiz "n Answer is: "
string6: .asciiz "nn Another Calculation? y, n: "
string7: .asciiz "nn Invalid input! Please enter y or n."
string8: .asciiz "nn Calculator is Terminated."

.text
.globl main

main:
addi $v0, $0, 4

la $a0, string0 //Loads and Prints the hellp message

syscall #printing str0

calculator:

addi $v0, $0, 4

la $a0, string1 //Prompts user to key in his value for a:

syscall #printing string1

addi $v0, $0, 6

syscall
mov.s $f1, $f0   #reading and storing first value

addi $v0, $0, 4

la $a0, string2

syscall #printing string2

addi $v0, $0, 12

syscall #Now reading operator

add $a1, $v0, $0   #storing the operator

addi $v0, $0, 4

la $a0, string3
syscall #printing string3

addi $v0, $0, 6

syscall
mov.s $f2, $f0   #reading and storing second value

addi $9, $0, 0x2b
beq $a1, $9, addIt   #checking if +

addi $9, $0, 0x2d
beq $a1, $9, subIt   #checking if –

addi $9, $0, 0x2a
beq $a1, $9, mulIt   #checking if *

addi $9, $0, 0x2f
beq $a1, $9, divIt   #checking if /

addi $v0, $0, 4

la $a0, string4

syscall #printing string4 if invalid operator is chosen.
j calc

addIt:
add.s $f12, $f1, $f2   #adding values
j printAnswer

subIt:
sub.s $f12, $f1, $f2   #subtracting values
j printAnswer

mulIt:
mul.s $f12, $f1, $f2   #multiplying values
j printAnswer

divIt:
div.s $f12, $f1, $f2   #dividing values
j printAnswer

printAnswer:
addi $v0, $0, 4

la $a0, string5

syscall #printing string5

li $v0, 2
syscall #Now printing the answer
//Checking to see if user wants to perform another calculation
j anotherCalc

anotherCalc:
addi $v0, $0, 4

la $a0, string6

syscall #printing string6

addi $v0, $0, 12

syscall #reading command

add $a1, $v0, $0   #storing command

addi $9, $0, 0x79
beq $a1, $9, calc   #checking if y

addi $9, $0, 0x6e
beq $a1, $9, exitApp   #checking if n

addi $v0, $0, 4

la $a0, string7

syscall #printing string7
j anotherCalc

exitApp:
addi $v0, $0, 4

la $a0, string8

syscall #printing string8
jr $31 # Exit main subroutine.

2.
.text
main: #assume value a is already in $t0, b in $t1
add $a0, $0, $t0 #Same as move function
add $a1, $0, $t1
//Similar to c line
int main () {
int x;
x = add_normal (a,b);
x = sub_normal (a,b);
x = mul_normal (a,b);
x = div_normal (a,b);

}
jal add_normal #Call addition Procedure
sub $a0, $0, $t0 #Same as move function
sub $a1, $0, $t1
jal sub_normal #Call substraction procedure
mul $a0, $0, $t0 #Same as move function
mul $a1, $0, $t1

jal mul_normal #Call Multiply procedure
div $a0, $0, $t0 #Same as move function
div $a1, $0, $t1
jal div_normal #Call Division procedure
add $t3, $0, $v0 #Move the return value into any temp register
syscall
add_normal:
addi $sp, $sp, -4 #Adjusting Stack Pointer
sw $t0, 0($sp) #Restore Previous Value
add $t0, $a0, $a1 #Procedure Body
add $v0, $0, $t0 #Results
lw $t0, 0($sp) #Load previous value
addi $sp, $sp, 4 #Moving Stack Pointer
jr $ra #return (Copy $ra to PC)

sub_normal:
subi $sp, $sp, -4 #Adjusting Stack Pointer
sw $t0, 0($sp) #Restore Previous Value
sub $t0, $a0, $a1 #Procedure Body
sub $v0, $0, $t0 #Results
lw $t0, 0($sp) #Load previous value
subi $sp, $sp, 4 #Moving Stack Pointer
jr $ra #return (Copy $ra to PC)

mul_normal:
muli $sp, $sp, -4 #Adjustin Stack Pointer
sw $t0, 0($sp) #Restore Previous Value
mul $t0, $a0, $a1 #Procedure Body
mul $v0, $0, $t0 #Results
lw $t0, 0($sp) #Load previous value
muli $sp, $sp, 4 #Moving Stack Pointer
jr $ra #return (Copy $ra to PC)

div_normal:
divi $sp, $sp, -4 #Adjustin Stack Pointer
sw $t0, 0($sp) #Restore Previous Value
div $t0, $a0, $a1 #Procedure Body
div $v0, $0, $t0 #Results
lw $t0, 0($sp) #Load previous value
divi $sp, $sp, 4 #Moving Stack Pointer
jr $ra #return (Copy $ra to PC)

Program 3:

Not sure what is taught in your class using logic algorithm taught in CS47.

Program 4:

Not sure what is taught in your class using logic algorithm taught in CS47.

Hope that helps...HAPPY ANSWERING!!!!!!!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote