In: Computer Science
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").
.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