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

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 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
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 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. 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'.
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
Write a MIPS Assembly language program to request a file name from the user, open the...
Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write out the contents to the console. This is what I have so far: .data    fileName:   .space 100    prompt1:   .asciiz "Enter the file name: "    prompt2:    .asciiz ""    prompt3:   .asciiz "\n"    buffer:    .space 4096 .text    main:        #        li $v0, 4        la $a0, prompt1       ...
Write a mips assembly language program that asks the user to enter an alphabetic character (either...
Write a mips assembly language program that asks the user to enter an alphabetic character (either lower or upper case)and change the case of the character from lower to upper and from upper to lower and display it.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT