Home > Blockchain >  How to swap contents of two variables with one register (asm-simulator toy ISA)?
How to swap contents of two variables with one register (asm-simulator toy ISA)?

Time:12-14

I am new in assembly I tried to move variables in this link https://schweigi.github.io/assembler-simulator/ I tried to change the content of char1 and char3

JMP start
char1: db "A"  
char2: db "B"
char3: db "C"
start:
    MOV A, [char1]
    MOV B, [char3]
    MOV [char3],A
    MOV [char1],B

now I want to do it only with one register ( without B ) , it is possible to define another variable but i didn't understand how to move the content between 2 variables
Could you please advise ?

CodePudding user response:

Here is the (not recommended) XOR method

MOV A, [char1]
XOR A, [char3]
XOR [char1], A
XOR [char3], A

A discussion of the XOR method is here:

CodePudding user response:

Thanks to Vane

    JMP start
char1: db "D"  
char2: db "O"
char3: db "G"
start:
    MOV A, [char1]  
    PUSH A 
        MOV A, [char3]
    MOV [char1], A
    POP A
    MOV [char3], A
  • Related