I'm creating software for the 8051 microcontroller with assembly language, but I have one heck of a time trying to figure out how how to swap the values of two registers.
I need this because I only have one pointer register available (R1) left to my program and one regular register (R3) so I thought I can somehow make R3 as a usable pointer since R0 is already used. I looked at other register banks and the pointers there are already in use as well and I do not want to corrupt them.
In this example, I want to preserve the original R1 value and use R3 as the active pointer that advances.
Then elsewhere in my code (not shown) when data is saved to the buffer, the original R1 value advances and R3 stays the same.
So how do I swap R1 and R3 in this case?
xch A,R3 ;?? - Trying to swap R1 and R3 xch A,R1 ;?? mov A,@R1 ;Load from buffer mov @R1,#0h ;and clean it at current position jz noaudrun inc R1 ;if loaded value isn't 0, advance buffer anl CLKR1,#AUDQ ;and make overflow = beginning of buffer acall run ;and run code noaudrun: xch A,R1 ;swap R1 and R3 again xch A,R3