The objective of this program is to swap two numbers without using temporary variables. I came up with a solution by just using math but when I assemble, the numbers don't swap and I can't figure out why. Can anyone explain my mistake?
.text
main:
la $a0,n1
la $a1,n2
jal swap
li $v0,1 # print n1 and n2; should be 27 and 14
lw $a0,n1
syscall
li $v0,11
li $a0,' '
syscall
li $v0,1
lw $a0,n2
syscall
li $v0,11
li $a0,'\n'
syscall
li $v0,10 # exit
syscall
swap: #this is my code and where I'm having problems
sub $a0, $a0, $a1
add $a1, $a1, $a0
sub $a0, $a1, $a0
jr $ra
.data
n1: .word 14
n2: .word 27