Hello,
I am require to write a program module to convert a Hex digit passed to it in the lower nibble of Accumulator A to its ASCII character code. The upper nibble should be treated as "don't care".
Return the ASCII code in Accumulator A and save it in a suitable memory location.
All other CPU register values are to remain unchanged.
thats in australia university man...
Can you just give me an idea how to do thisc onversion.
i know how to convert BCD to ASCII..but this one i dnt know...
I am going to school here in the USA and I am taking a class that teaches the 68HC11. When I asked why use the 68HC11, I was told that a microcontroller is a microcontroller, it's just that newer ones may have more extras.
i think i got the steps how to proceed.. can anyone check it out and let me know if its good?
First of all, clear the upper bits by doing an AND with immediate data 0x0F.
Then compare the remaining number with 9. If it's less than or equal to 9, then do an OR with 0x30H and that is the ASCII code.
If the number is greater than 9, then subtract 9 and then do an OR with 0x40H to get the ASCII code.
68hc11:
ANDA#$0F
ADDA #$100-#$0x0a ; check if higher than 9
BCS label; if higher than move to letters
ADDA #$3A+#$100-#$41
label
ADDA #$41
result for 0..9 is A_register +0x100- 0x0A +0x41 = 0x41..0x46 (A..F)
result for A..F is A_register +0x100- 0x0A +0x41 +0x3A+0x100-0x41= 0x30..0x39 (0..9)
now i have to write a program module to convert a Hex byte passed to it in AccA to its ASCII coded word.
Return the word in AccD and then save it in a suitable area memory.
NB. This module affects AccA & AccB.
TAB; copy A to B
-- convert A to hex using previous method
ANDB#$F0
LSRB; if you don't have a "swap nibbles in B" instruction
LSRB
LSRB
LSRB
-- convert to B hex using previous method and instructions for B register