Hi guys…In this article let’s learn conversion.The ascii to Hex conversion logic is very simple.The hexadecimal numbers from 31H-39H are 0-9 numbers in ascii and
41H to 46H are A to F numbers. So we should first compare the number with 40H if it is lesser subtract with 30H and it is greater subtract with 37H.
1)Initialize R0 with number which is required to find equivalent Hexadecimal number code.
2)Compare it with 40H and jump to label1 if it is equal.
3)Compare the carry bit to find which is greater and lesser.
4)If the carry bit is not set(it implies it is greater)jump to label2.
5)If it is lesser subtract the number with 30H.
6)If it is greater subtract the number with 37H.
Code goes here:
MAIN: MOV R0,#41H ; move the numbers to be converted
CJNE A,#40H,LABEL1 ; compare the number with 40H
LABEL1:JNC LABEL2 ;If the number is greater than 40H jump to label2
SUBB A,#30H ; If the number is lesser than 40H subtract with with 30H
LABEL2: CLR c
SUBB A,#37H ;If the number is greater than 40H subtract with 37H