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...
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...
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...
Write a MIPS assembly program that prompts the user first for a string, then for a...
Write a MIPS assembly program that prompts the user first for a string, then for a character. The program should then search the string for the character and print out the number of times the character appears in the string. You can use as many restrictions as you want, just be sure to list them. You must allocate space in the .data segment of your program for the user string.
write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
Write a simple MIPS program that asks the user to input a string and then a...
Write a simple MIPS program that asks the user to input a string and then a character. The program should then count how many times that character appears in the string and print out that value. Please use comments.
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];
Write a C++ program Given fuzzy sets A and B, find complement A, A ∪ B,...
Write a C++ program Given fuzzy sets A and B, find complement A, A ∪ B, and A ∩ B A = {0.2 : a, 0.7 : b, 0.5 : c, 0.01 : k, 0.98 : z} and B = {0.42 : a, 0.6 : b, 0.5 : h, 0.1 : k, 0.44 : m, 0.8 : z}
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT