Tuesday 31 January 2012

To swap the nibbles of R0 and R1 so that low nibble of R0 swaps with the high nibble of R1 and the high nibble of R0 swaps with the low nibble of R1 ,


Method 1:


ORG 00H
MOV R0,#38H ; Load contents to register R0
MOV R1,#46H ; Load contents to register R1
MOV A,R0       ; Copy the contents of R0 to A
SWAP A           ;  Swap the nibbles of A
XCH A,R1        ; Exchange the swaped contents of A with the contents of R1
SWAP A           ; Again swap the nibbles of A ie nibbles of R1
XCH A,R0        ; Exchange of contents of A with R0
END






Method 2:


ORG 00H
MOV R0,#34H ; Load R0 with value 34H
MOV R1,#12H ; Load R1 with value 12H
MOV A,R0       ; Copy the value from R0 to Accumulator
RL A                 ; Rotate left so that D7 is exchanged with D0
RL A
RL A
RL A                ; After this line A=43H
XCH A,R1       ; Exchange contents of R1 & A, A=12H ,R1=43H
RL A                ; Again rotate the bits
RL A
RL A
RL A               ; After this A=34H
XCH A,R0      ; Exchange contents of R0 & A, R0=34H
END