Question

In: Computer Science

Write a MIPS program that executes the statement: s = (a + b) – (c +...

Write a MIPS program that executes the statement: s = (a + b) – (c + 101), where a, b, and c are

user provided integer inputs, and s is computed and printed as an output. Answer the following:


a. Suppose the user enters a = 5, b = 10, and c = -30, what is the expected value of s?


b. Which instruction in your program computed the value of s and which register is used?


c. What is the address of this instruction in memory?


d. Put a breakpoint at this instruction and write the value of the register used for computing s in


decimal and hexadecimal.

Solutions

Expert Solution

MIPS PROGRAM

.data
   askA: .asciiz "Enter value of a: "
   askB: .asciiz "Enter value of b: "
   askC: .asciiz "Enter value of c: "
   msgS: .asciiz "Result s: "
.text
   # Prompt user to enter value of a
   li $v0, 4
   la $a0, askA
   syscall
   # Get user input
   li $v0, 5
   syscall
   #store the result in t0
   move $t0, $v0
  
   # Prompt user to enter value of b
   li $v0, 4
   la $a0, askB
   syscall
   # Get user input
   li $v0, 5
   syscall
   #store the result in t1
   move $t1, $v0
  
   add $t2, $t0, $t1
  
   # Prompt user to enter value of c
   li $v0, 4
   la $a0, askC
   syscall
   # Get user input
   li $v0, 5
   syscall
   #store the result in t0
   move $t0, $v0
  
   add $t1,$t0,101
  
   sub $t0,$t2,$t1
  
   li $v0, 4
   la $a0, msgS
   syscall
   #print or show the age
   li $v0, 1
   move $a0, $t0
   syscall

Explanation

$t0 = a

$t1 = b

$2 = $t0 + $t1

$t0 = c

$t1 = $t0 + 101

$t0 = $t2 - $t1

Qa Ans) -56

Qc Ans )

Qb Ans)

sub $t0,$t2,$t1

Qd Ans)

Hexadecimal

Decimal


Related Solutions

MIPS a) Consider the C statement: a = (b + d) + (b - c) +...
MIPS a) Consider the C statement: a = (b + d) + (b - c) + (c + d) Which of the following assembly instructions can be used to replicate all or part of this statement in MIPS, without changing or reducing the equation. Assume variables a, b, c, and d are assigned to registers $s0, $s1, $s2 and $s3 respectively. 1. sub $t0, $s2, $s3 2. sub $t0, $s0, $s3 3. sub $t1, $s1, $s2 4. sub $t2, $s1,...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user...
Count the number of 1’s and 0’s Write a MIPS program that will ask the user to enter an integer, and then output the number of 1’s and 0’s that are present in the integer’s signed 32-bit binary representation. For example, 15 has a binary representation of 0000 0000 0000 0000 0000 0000 0000 1111, which has 28 zeroes and 4 ones. We have provided you the starter code that deals with the input/output logic. The integer input is saved...
Write the MIPS assembly version of this C code: int weird(char[] s, int x) { int...
Write the MIPS assembly version of this C code: int weird(char[] s, int x) { int i; for (i = 0; i < x; i++) { if (s[i] == ‘A’) { return power(10, i); } } return -1; } int power(int base, int i) { int j = 0; while (j < base) { base = base * base; j++; } return base; }
Let a , b , c be three integer numbers. Write a C++ program with a...
Let a , b , c be three integer numbers. Write a C++ program with a functions void rotate1(int* a,int* b,int* c) void rotate2(int& a,int& b,int& c) such that a -> b , b -> c and c -> a. Thus we use two different approaches (pointers in rotate1 and references in rotate2).
C++ For this assignment, you will write a C++ program to either add (A), subtract (S),...
C++ For this assignment, you will write a C++ program to either add (A), subtract (S), multiply (M), and (N), or (O) two matrices if possible. You will read in the dimensions (rows, then columns) of the first matrix, then read the first matrix, then the dimensions (rows then columns) of the second matrix, then the second matrix, then a character (A, S, M, N, O) to determine which operation they want to do. The program will then perform the...
What are the values in arrays a, b, and c after the following code executes (list...
What are the values in arrays a, b, and c after the following code executes (list all of the elements of the arrays)? double[] a = new double[4]; double[] b = {6,4,2}; a[a.length-1] = b[b.length-1]; double[] c = b; c[0] = -1; b[1] = c[2]; c = a; c[0] = -2; a[1] = c[3];
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that...
I have to do the following MIPS coding assignment. Question 1 Write a MIPS program that meets the following requirements (NOTE: your program statements should follow the order of the requirements and each requirement should correspond to only one assembly instruction): Loads the hexadecimal equivalent of 23710 into register 13 using an immediate bitwise OR instruction Loads the hexadecimal equivalent of 183410 into register 17 using an immediate bitwise OR instruction Performs the bitwise AND operation on the operands stored...
Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string...
Transfer in MIPS char * strtoupper(char s[]) { char c; c = s[0]; /* empty string */ if (c == 0) return s; /* convert the first character to upper case*/ if (c >= ‘a’ && d <= ‘z’) { c -= 32; s[0] = c; } /* convert the remaining characters*/ strtoupper(s + 1); return s; }
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS)...
Coding Problem 1: In this program, you are asked to write a program in assembly (MIPS) which works as a simple calculator. The program will get two integer numbers, and based on the requested operation, the result should be shown to the user. a. The program should print a meaningful phrase for each input, and the result. i. “Enter the first number” ii. “Enter the second number” iii. “Enter the operation type” iv. “The result is” b. The user should...
MIPS Program I'm trying to write a program that will take in two numbers from the...
MIPS Program I'm trying to write a program that will take in two numbers from the user and output the sum at the end. However, I keep getting very wrong answers. For example, I add 2 and 2 and get 268501000. Help would be appreciated. .data #starts data use userIn1:    .word 4 #sets aside space for input    userIn2:    .word 4 #sets aside space for input total:    .word 4 #sets space aside for input    request:   ...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT