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

The read_int system call (number 5) will cause the running program to stop and w

ID: 3561260 • Letter: T

Question

The read_int system call (number 5) will cause the running program to stop and wait for the user to type in an integer at the keyboard. The integer will be put into SvO register and will be available after the syscall completes. Write a MIPS assembly language program which prompts for a user to enter four integers and calls read_int four times to read in four integers. The program should perform addition, subtraction, multiplication, integer division, and modulo operation (compute the remainder of their division) using two of these four integers (see the C program below), then display their result on the console window. Also compute numl - ( ( (5+num3*num2) * 3) / num4) where numl is the first read integer, num2 is the second read integer, nuin3 is the third read integer, and num4 is the forth read integer, and display the result. Name your source code file assignment3.s. The following shows how it looks like in a C program:

Explanation / Answer

.data
prompt: .asciiz "Enter a value: "
prompt1: .asciiz "Enter another value: "
prompt2: .asciiz "Enter one more value: "
prompt3: .asciiz "num3+num1 = "
prompt4: .asciiz " num1-num2 ="
prompt5: .asciiz " num4*num1 = "
prompt6: .asciiz " num2/num3 = "
prompt7: .asciiz " num1 mod num2 = "
prompt8: .asciiz " num1 - (((5+num3*num2)*3)/num4) = "
#variable declarations
num1: .word 0
num2: .word 0
num3: .word 0
num4 :.word 0
ans1: .word 0
ans2: .word 0
ans3: .word 0
ans4: .word 0
ans5: .word 0
ans6: .word 0

.text

main :
# print the string
li $v0,4
la $a0,prompt
syscall
# Get integer p and put in num1
li $v0,5
syscall
la $t1,num1
sw $v0,0($t1)
# print the string
li $v0,4
la $a0,prompt1
syscall
# Get integer p and put in num2
li $v0,5
syscall
la $t1,num2
sw $v0,0($t1)
# print the string
li $v0,4
la $a0,prompt2
syscall
# Get integer p and put in num3
li $v0,5
syscall
la $t1,num3
sw $v0,0($t1)
# print the string
li $v0,4
la $a0,prompt2
syscall
# Get integer p and put in num4
li $v0,5
syscall
la $t1,num4
sw $v0,0($t1)
#perform the arithmetic operations
#num3+num1 =
la $t0,num3
lw $t0,($t0)
la $t1,num1
lw $t1,($t1)
add $t0,$t1,$t0
# print the string
li $v0,4
la $a0,prompt3
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
#num1-num2 =
la $t0,num2
lw $t0,($t0)
la $t1,num1
lw $t1,($t1)
sub $t0,$t1,$t0
# print the string
li $v0,4
la $a0,prompt4
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
#num4*num1 =
la $t0,num4
lw $t0,($t0)
la $t1,num1
lw $t1,($t1)
mul $t0,$t1,$t0
# print the string
li $v0,4
la $a0,prompt5
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
#num2/num3 =
la $t0,num2
lw $t0,($t0)
la $t1,num3
lw $t1,($t1)
div $t0,$t0,$t1
# print the string
li $v0,4
la $a0,prompt6
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
#num1 mod num2 =
la $t0,num1
lw $t0,($t0)
la $t1,num2
lw $t1,($t1)
div $t2,$t0,$t1 #$t2 = num1/num2 (truncated)
mul $t2,$t2,$t1 #$t2 = (num1/num2)*num2
sub $t0,$t0,$t2 #$t0 = num1 - (num1/num2)*num2 - of num1 mod num2
# print the string
li $v0,4
la $a0,prompt7
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
#num1 - (((5+num3*num2)*3)/num4) =
la $t0,num2
lw $t0,($t0)
la $t1,num3
lw $t1,($t1)
mul $t0,$t0,$t1 #num3*num2
addi $t0,$t0,5 #(5+num3*num2)
addi $t1,$0,3
mul $t0,$t0,$t1 #((5+num3*num2)*3)
la $t1,num4
lw $t1,($t1)
div $t0,$t0,$t1 #(((5+num3*num2)*3)/num4)
la $t1,num1
lw $t1,($t1)
sub $t0,$t1,$t0 #num1 - (((5+num3*num2)*3)/num4)
# print the string
li $v0,4
la $a0,prompt8
syscall
# print the int
li $v0,1
addi $a0,$t0,0
syscall
InfLoop : j InfLoop # stay here for infinite time

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