Starting from:

$30

CSE230-Assignment 3 Solved

Objectives:

 

-write a MIPS assembly language program 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 the specified (see the C program below) 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 % 4) + num3) * 2) / num4) + num1 where

num1 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 program:

--------

int num1, num2, num3, num4, ans1, ans2, ans3, ans4, ans5, ans6; printf("Enter a value:\n");

//read an integer from a user input and store it in num1 scanf("%d", &num1); printf("Enter another value:\n");

//read an integer from a user input and store it in num2 scanf("%d", &num2); printf ("Enter one more value:\n");

//read an integer from a user input and store it in num3 scanf("%d", &num3); printf ("Enter one more value:\n");

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

 

ans1 = num4+num1; //addition printf("num4+num1=%d\n", ans1);

ans2 = num1-num2; //subtraction printf("num1-num2=%d\n", ans2);

ans3 = num4*num2; //multiplication printf("num4*num2=%d\n", ans3);

ans4 = num1/num3; //division printf("num1/num3=%d\n", ans4);

ans5 = num3%num1; //remainder of division printf("num3 mod num1=%d\n", ans5);

ans6 = ((((num2 % 4) + num3) * 2) / num4) + num1; printf("((((num2 mod 4) + num3) * 2) / num4) + num1=%d\n", 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

num4+num1=5

num1-num2=3 num4*num2=-15 num1/num3=0 num3 mod num1=3

((((num2 mod 4) + num3) * 2) / num4) + num1=0

 --------------------------------------------

More products