You are on page 1of 4

Input: ;R6--low byte of the 16BIT hext data ;R5--hi byte ;output: ;R4-- 1'S dec nuber of ACII

;R3-- 10'S dec number of ASCII ;R2-- 100'S dec nuber of ASCII ;R1-- 1000'S dec number of ASCII ;R0-- 10000'S dec number of ASCII ;usage: ;clear R0,R1,R2,R3,R4 ;mov R5,High BYTE of the data to be converted ;mov R6,Low byte of the data to be converted ;-------------------------------Hex16ToASCII: push PSW push ACC CLR C MOV R0,#0 ;10,000 counter clear Hex16ASCIILoop1: MOV A,R6 ;"16bit hex data" - 10,000 (2710H) SUBB A,#10H MOV R6,A ;save left value MOV A,R5 SUBB A,#27H MOV R5,A JC Hex16AsciiComp1 ;if "16bit hex data"< 10,000,jump to skip1 INC R0 ;else save 10,000s counter jmp Hex16ASCIILoop1 ;again:"16bit hex data" - 10,000 (2710H) Hex16AsciiComp1: ;here is the compensation at condition ;"16bit hex data"< 10,000 ;because we have subtrate it with 10,000 ;so add 10,000

;get the 1,000s',100s',10s',1s' value to R5R6 MOV A,R6 ADD A,#10H MOV R6,A MOV A,R5 ADDC A,#27H MOV R5,A CLR C ;End of the compensation MOV R1,#0 ;1,000 counter clear Hex16ASCIILoop2: ;subtrate the left data by 1,000(3E8) ;repeatedly,until R5R6<1,000 MOV A,R6 subb A,#0E8H mov R6,A MOV A,R5 subb A,#03H MOV R5,A JC Hex16AsciiComp2 ;the left R5R6 <1,000,jump to compesation 2 INC R1 ;else save the 1,000 counter R1 jmp Hex16ASCIILoop2 Hex16AsciiComp2: ;Compensate because subbtrate 1000 from R5R6 ;at the condition R5R6<1000 MOV A,R6 ADD A,#0E8H MOV R6,A MOV A,R5 ADDC A,#03H MOV R5,A CLR C MOV R2,#0 ;100S' counter clear Hex16AsciiLoop3:

;the 100s' (64H)condition mov A,R6 SUBB A,#64H mov R6,A MOV A,R5 subb A,#0 JC Hex16AcsiiComp3 INC R2 jmp Hex16AsciiLoop3 Hex16AcsiiComp3: mov A,R6 ADD A,#64H MOV R6,A MOV A,R5 ADDC A,#0 MOV R5,A CLR C MOV R3,#0 ;10S' counter clear Hex16AsciiLoop4: ;10S' CONDITION, (R5 =0,so despite it) mov A,R6 SUBB A,#0AH MOV R6,A JC Hex16AsciiComp4 INC R3 jmp Hex16AsciiLoop4 Hex16AsciiComp4: add A,#0AH MOV R6,A ;here R6 represent 1S' mov R4,a ;1S' counter ->R4 ;NOW R4,R3,R2,R1,R0 all add 30H,to get real ;ASCII code clr c

mov A,R4 addc A,#30H MOV R4,A MOV A,R3 ADD A,#30H MOV R3,A MOV A,R2 ADD A,#30H MOV R2,A MOV A,R1 ADD A,#30H MOV R1,A MOV A,R0 ADD A,#30H MOV R0,A pop PSW pop ACC RET ;END OF CONVERATION ROUTINE.

You might also like