16 For 3 and 2 the keyboard gives 0x33 and 0x32 respectively
16. For 3 and 2 the keyboard gives 0x33 and 0x32, respectively. Write a program to convert 0x33 and 0x32 to packed BCD and store the result in R2.
Solution
MOV R0, #41H ; 41H is a hex number for 0x32
MOV R1, #42H ; 42H is a hex number for 0x33
MOV A,@R0 ; get the hex number into A.
MOV R2, A
ANL A, #0FH ; and with 0F.
INC R2
MOV @R2, A ; store the first number into destination.
MOV A, R2
ANL A, #0F0H ; and with F0
SWAP A ; interchange lower and upper nibbles.
INC R2
MOV @R2, A ; store the second no to destination.
END
