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: 2247717 • 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 $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 + num1 mod 3)*2)/num3) where num1 is the first read integer, num2 is the second read integer,  num3is 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:

int num1, num2, num3, num4, ans1, ans2, ans3, ans4, ans5, ans6;

printf("Enter a value: ");

//read an integer from a user input and store it in num1
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("%d", &num3);

printf ("Enter one more value: ");

//read an integer from a user input and store it in num4
scanf("%d", &num4);

ans1 = num2+num3; //addition

printf("num2+num3=%d ", ans1);

ans2 = num3-num4; //subtraction

printf("num3-num4=%d ", ans2);

ans3 = num3*num1; //multiplication

printf("num3*num1=%d ", ans3);

ans4 = num2/num4; //integer division

printf("num2/num4=%d ", ans4);

ans5 = num4%num3; //remainder of division

printf("num4 mod num3=%d ", ans5);

ans6 = num2-(((num4 + num1 % 3)*2)/num3);

printf("num2-(((num4 + num1 % 3)*2)/num3)=%d ", ans6);

Here is a sample output (user input is in bold):

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

Explanation / Answer

#include <stdio.h>

int theArray[40];

int main() {

int num1, num2, num3, num4, num5, num6, num7, num8; /* Our "registers" */

num7 = 1;

num8 = 1;

theArray[0] = num7; /* Storing the first two terms of the */

theArray[num8] = num7; /* sequence into our array             */

num1 = 2;

LLoop:

num4 = num1 - 2;

num5 = num1 - 1;

num2 = theArray[num4];

num3 = theArray[num5];

num6 = num2 + num3;

theArray[num1] = num6;

num1 = num1 + 1;

if (num1 < 40) goto LLoop;

return 0;

}

#include <stdio.h>

int theArray[40];

int main() {

int num1, num2, num3, num4, num5, num6, num7, num8; /* Our "registers" */

num7 = 1;

num8 = 1;

theArray[0] = num7; /* Storing the first two terms of the */

theArray[num8] = num7; /* sequence into our array             */

num1 = 2;

LLoop:

num4 = num1 - 2;

num5 = num1 - 1;

num2 = theArray[num4];

num3 = theArray[num5];

num6 = num2 + num3;

theArray[num1] = num6;

num1 = num1 + 1;

if (num1 < 40) goto LLoop;

return 0;

}

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