
![]() |
||
| Updates | Knowledge base | Manuals | Resellers | Warranties | Feedback | ||
Knowledge Base[ Back ] [ Index ] [ Categories ] [ Next ] Q10026. Routine (Word2Ascii) of preparing a 16 bit number to be printed in decimal form.More informationRoutine converts a 2-byte number to ASCII characters. All values are considered positive.AssemblerAny assembler.Input(SP+4) -> Number to convert(SP+2) -> Five-byte ASCII buffer start address (SP+0) -> Normal return address OutputASCII buffer is filled with converted numberA : Ascii code of LSB BC: 000Ah DE: Buffer start address HL: Least significant digit of number to convert Routine
;Word2Ascii: POP BC ;Retrieve ret address
; POP DE ;Fetch ASCII buffer
; POP HL ;Fetch number to convert
; PUSH BC ;Push ret address back
Word2Ascii: POP HL ;Ret addr briefly to HL
POP DE ;Fetch ASCII buffer to DE
EX (SP),HL ;Exchg Ret (SP) with Number (HL)
LD BC,10000 ;Prepare BC to subtract
PUSH IX ;Save content of IX
PUSH DE ;Transfer content of
POP IX ;Register DE to IX
LD (IX+0),"0"-1 ;Insert char in buffer
XOR A ;Clear carry flag
W2A_5: INC (IX+0) ;Inc char
SBC HL,BC ;Deduct 10K from HL
JR NC,W2A_5 ;Loop until negative result
ADD HL,BC ;Restore positive in HL
LD BC,1000 ;Prepare BC to subtract
LD (IX+1),"0"-1 ;Insert char in buffer
XOR A ;Clear carry flag
W2A_4: INC (IX+1) ;Inc char
SBC HL,BC ;Deduct 1K from HL
JR NC,W2A_4 ;Loop until negative result
ADD HL,BC ;Restore positive in HL
LD BC,100 ;Prepare BC to subtract
LD (IX+2),"0"-1 ;Insert char in buffer
XOR A ;Clear carry flag
W2A_3: INC (IX+2) ;Inc char
SBC HL,BC ;Deduct 100 from HL
JR NC,W2A_3 ;Loop until negative result
ADD HL,BC ;Restore positive in HL
LD BC,10 ;Prepare BC to subtract
LD (IX+3),"0"-1 ;Insert char in buffer
XOR A ;Clear carry flag
W2A_2: INC (IX+3) ;Inc char
SBC HL,BC ;Deduct 10 from HL
JR NC,W2A_2 ;Loop until negative result
ADD HL,BC ;Restore positive to HL
LD A,L ;Last number to A
ADD A,"0" ;Add the "0" difference
LD (IX+4),A ;Put last char in buffer
POP IX ;Restore original value in IX
RET
Added byMarcelo Lopez14 May 2003. [ Back ] [ Index ] [ Categories ] [ Next ] |