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

MIPS assembly from C for simple arithmetic and prompting user code. please use P

ID: 2247730 • Letter: M

Question

MIPS assembly from C for simple arithmetic and prompting user code. please use PCSPIM.

Objectives: write assembly language programs to -perform arithmetic and logical operations on variables -use syscall operations to display integers and strings on the console window -use syscall operations to read integers from the keyboard. Assignment Description: 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 $v0 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 num2 (num4 + numl mod 3) *2) /num3) where numl is the first read integer, num2 is the second read integer, num3 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 progranm int num1, num2, num3, num4, ansl, ans2, ans3, ans4, ans5, ans6 printf C"Enter a value: "); //read an integer from a user input and store it in numl scanf ("%d", &num1;) ; printf ("Enter another value: "); //read an integer from a user input and store it in num2 scanf ("%d", &num2;); printf ("Enter one more value: ") //read an integer from a user input and store it in num3 scanf ("sd", &num3;) printf ("Enter one more value: ") //read an integer from a user input and store it in num4 scanf ("sd", &num4;) ans! = num2 +num3 ; //addition printf( "num2+num3-%d ", ans!) ; ans2 = num3-num4; //subtract 1 n printf( "num3-num4-%d ", ans2);

Explanation / Answer

Given below is the MIPS program for the question. Shown the output at end. Please don't forget to rate the answer if it helped. Thank you very much.

.data
prompt1: .asciiz "Enter a value: "
prompt2: .asciiz "Enter another value: "
prompt3: .asciiz "Enter one more value: "
msg1: .asciiz " num2+num3="
msg2: .asciiz " num3-num4="
msg3: .asciiz " num3*num1="
msg4: .asciiz " num2/num4="
msg5: .asciiz " num4 mod num3="
msg6: .asciiz " num2 - (((num4 + num1 mod 3) * 2 / num3) = "

.text
#.........get 1st input ...........
#display the prompt
li $v0, 4
la $a0, prompt1
syscall

#get user input and store it in t1
li $v0, 5
syscall
move $t1, $v0

#.........get 2nd input ...........
#display the prompt
li $v0, 4
la $a0, prompt2
syscall

#get user input and store it in t2
li $v0, 5
syscall
move $t2, $v0

#.........get 3rd input ...........
#display the prompt
li $v0, 4
la $a0, prompt3
syscall

#get user input and store it in t3
li $v0, 5
syscall
move $t3, $v0

#.........get 4th input ...........
#display the prompt
li $v0, 4
la $a0, prompt3
syscall

#get user input and store it in t4
li $v0, 5
syscall
move $t4, $v0

#calculate num2+num3 and display
add $t5, $t2, $t3
#show msg
li $v0, 4
la $a0, msg1
syscall
#show result
li $v0, 1
move $a0, $t5
syscall

#calculate num3-num4 and display
sub $t5, $t3, $t4
#show msg
li $v0, 4
la $a0, msg2
syscall
#show result
li $v0, 1
move $a0, $t5
syscall


#calculate num3*num1 and display
mul $t5, $t3, $t1
#show msg
li $v0, 4
la $a0, msg3
syscall
#show result
li $v0, 1
move $a0, $t5
syscall


#calculate num2/num4 and display
div $t5, $t2, $t4
#show msg
li $v0, 4
la $a0, msg4
syscall
#show result
li $v0, 1
move $a0, $t5
syscall


#calculate num4 mod num3 and display
rem $t5, $t4, $t3
#show msg
li $v0, 4
la $a0, msg5
syscall
#show result
li $v0, 1
move $a0, $t5
syscall


#calculate num2 - (((num4 + num1 mod 3) * 2 / num3) and display
rem $t5, $t3, 3
add $t5, $t5, $t4
mul $t5, $t5, 2
div $t5, $t5, $t3
sub $t5, $t2, $t5
#show msg
li $v0, 4
la $a0, msg6
syscall
#show result
li $v0, 1
move $a0, $t5
syscall


#exit
li $v0, 10
syscall

output


Enter a value:
8
Enter another value:
5
Enter one more value:
11
Enter one more value:
-3

num2+num3=16
num3-num4=14
num3*num1=88
num2/num4=-1
num4 mod num3=-3
num2 - (((num4 + num1 mod 3) * 2 / num3) = 5