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 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
Write a mips program that would function in QTSPIM that asks the user to enter a...
Write a mips program that would function in QTSPIM that asks the user to enter a list of integer values, one per line, with the last value being a negative. The program should read in these integers until a negative number is entered. Afterwards the program should print 1) sum, 2) minimum value, 3) max value, 4) mean and 5) variance value. of the numbers that were entered.
Write a MIPS program that asks the user for 2 numbers. Output the sum of the...
Write a MIPS program that asks the user for 2 numbers. Output the sum of the 2 numbers. The difference between the 2 numbers (num1-num2) and (num2-num1) The value that is 305 more than the 1st number. The value that is 305 less than the 2nd number
Write the following program in MIPS: a) declare an array A of the following numbers: 3,...
Write the following program in MIPS: a) declare an array A of the following numbers: 3, 5, 8, 10, 12, 2, 76, 43, 90, 44 b) declare a variable called size which stores the number of element in array A, that is 10. c) write a subroutine to search for a number stored in an array and return true or false. In C++ the subroutine is as follows: search(array, size, number_To_Search) e.g. search(A, 10, 12) The subroutine should return 0...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT