So currently at $t0 I have a variable x stored. I want $t0 to now store -x. How can I do this?
I tried
sub $t4, 0, $t0 move $t0, $t4
Any pointers as to why this says parser syntax error?
So currently at $t0 I have a variable x stored. I want $t0 to now store -x. How can I do this?
I tried
sub $t4, 0, $t0 move $t0, $t4
Any pointers as to why this says parser syntax error?
By the formula 0-x = -x , and knowing that $0 is hard-coded to zero.
Try
sub $t0, $0, $t0
This will negate $t0 and then put it back into $t0.
You can store -x in $t0 by using these 2 lines :
not $t0,$t0
addi $t0,$t0,1
These 2 lines basically apply 2's complement to the binary value stored in $t0.
NOTE: This might not be the most optimised choice in MIPS, but it does the job.