Question

In: Computer Science

Using MARS and MIPS 2. Write and test a program to swap the contents of two...

Using MARS and MIPS

2. Write and test a program to swap the contents of two registers. Assume there is only one additional register available that may be destroyed.

Your program should initially read values (of type integer, float or string) into registers. Next, it will swap the values read, then print the final contents of each register

(you are not allowed to use "move").

Solutions

Expert Solution

.data
input1: .asciiz"Enter value of register 1: "
input2: .asciiz"Enter value of register 2: "
output1: .asciiz "After swapping\nValue at Register 1: "
output2: .asciiz "\nValue at Register 2: "
.text
.globl main
main:
# taking number 1 from user and moving it to register $t1
   li $v0, 4
   la $a0, input1
   syscall
   li $v0, 5
   syscall
   add $t1, $0, $v0
# taking number 2 from user and moving it to register $t2  
   li $v0, 4
   la $a0, input2
   syscall
   li $v0, 5
   syscall
   add $t2, $0, $v0
# swapping using only two registers  
   add $t1, $t1, $t2
   sub $t2, $t1, $t2
   sub $t1, $t1, $t2
#printing
   li $v0, 4
   la $a0, output1
   syscall
   li $v0, 1
   add $a0, $t1, $0
   syscall
  
   li $v0, 4
   la $a0, output2
   syscall
   li $v0, 1
   add $a0, $t2, $0
   syscall

#Output


Related Solutions

Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle....
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle. (NAME = John Doe) 2)Write a Program that intializes X to 10, Y to 20 and Z to -50, adds X and Y and Z and prints the following the value of each variable, for example value of x is 10 as well as the result of the addition.
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function....
Use MARS to write and simulate a MIPS assembly language program to implement the strlen function. The program should ask for a user's input and print the length of the user's input. Write the main function to call strlen. The main function should: - Prompt the user for input - Pass that input to strlen using registers $a0. - Preserve (i.e. push onto the stack) any T registers that the main function uses. The strlen function should: - Preserve any...
Write a AL program that will interchange the contents of the two variables.
Assume we have two string variables:  Shakespeare byte 'Brevity is the soul of wit' and Poet byte 'The problem is not in the stars but within ourselves'  Write a AL program that will interchange the contents of the two variables.
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute...
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute six T[i] and display aproper message about roots .the the program should store all T[i] as memory array a = [1, 1, 1, 1, 1, 1]; b = [1, 2, 4, 8, 16, 32]; c = [-6, -4, -2, 2, 4, 6]; d = [-1, -3, -5, -7, -9, -11]; for (i=0 ; i<=6; i++) { T[i] =-4 *b [i] * d[i] +c[i] *...
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:   ...
Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that...
Write a MIPS function using a MARS 4.5 complier named void makeRandomArray(int arr[], int size) that generates and stores a specified number of random numbers each of whose values are between 0 and 1000 in an array
Write a C++ program to swap two numbers and show your output
Write a C++ program to swap two numbers and show your output
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT