swapping values of any two registers in 8051 language

by Mike   Last Updated August 26, 2018 23:05 PM

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
xch A,R1 ;swap R1 and R3 again
xch A,R3

Related Questions

Understanding LSB and MSB

Updated January 26, 2018 18:05 PM

Problem with the closing of a logic circuit

Updated July 15, 2018 10:05 AM

Business logic : Database vs Code

Updated April 02, 2016 08:02 AM

XOR Combinations

Updated March 02, 2017 21:05 PM