Question

In: Computer Science

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

Solutions

Expert Solution

In this program , we have to perform the operation f = 5x + 3y + z

First, we need to load x, y and z into registers. Let them be loaded into $s1, $s2 and $s3 respectively

then, we will multiply $s1 with 5 to get the value of 5x.

Then, multiply $s2 with 3 to get the value of 3y

add $s1, $s2 and $s3 and store it in $s0. $s0 will now store the value of 5x + 3y + z

store the value in $s0 to f

Since, x ,y and z are to initialized with any integers, I will assign x = 1 , y = 2 and z = 3

program:

.data

x : .word 1
y : .word 2
z : .word 3
f : .word 0

.text
.globl main

main:

   lw $s1, x
   lw $s2, y
   lw $s3, z #s3 = z
  
   mul $s1, $s1, 5 # $s1 = 5x
   mul $s2, $s2, 3 # $s2 = 3x
   add $s0, $s1, $s2 # $s0 = 5x + 3y
   add $s0, $s0, $s3 # s0 = 5x + 3y + z
  
   la $t0, f #$t0 = &f
   sw $s0, ($t0) # f = 5x + 3y + z
  
  


Related Solutions

Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; else return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results Submit your code and report here.
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers...
Write a MIPS Assembly Language program to perform the following operations: Request and read two integers from the console (Dn and Up), Call a recursive function to compute the result int RecurseFunc( int Dn, int Up ) { if( Dn < 1 ) return 0; return Dn * Up + RecurseFunc( Dn - 1, Up + 1 ); } Print out the results
Write a program to perform the calculation of the following equation and save the result accordingly:...
Write a program 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
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays...
Assignment Description: Write a MIPS assembly language program that adds the following two integers and displays the sum and the difference. In the .data section, define two variables num1 and num2 both words. Initialize num1 to 92413 10 and num2 to D4B 16 (use 0xD4B to initialize, Note that D4B is a hexadecimal number). Your main procedure/function should load the values of num1 and num2 into two temporary registers, and display them on the console window. Then add the values...
Write a mips assembly language program to ask the user to enter two integers A and...
Write a mips assembly language program to ask the user to enter two integers A and B and then display the result of computing the expression: A + 2B - 5.
Write a mips assembly language program that asks the user to enter an unsigned number and...
Write a mips assembly language program that asks the user to enter an unsigned number and read it. Then swap the bits at odd positions with those at even positions and display the resulting number. For example, if the user enters the number 9, which has binary representation of 1001, then bit 0 is swapped with bit 1, and bit 2 is swapped with bit 3, resulting in the binary number 0110. Thus, the program should display 6.
Write a mips assembly language program. Ask the user whether he wants to repeat the program:...
Write a mips assembly language program. Ask the user whether he wants to repeat the program: "\nRepeat [y/n]? ". Use service code 12 to read a character and the branch instruction to repeat the main function if the user input is character 'y'.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT