Prev: 37735 Up: Map Next: 37782
37746: Convert numeric value BC to ASCII string at location HL
Used by the routine at 36647.
Input
BC A numeric value
HL Points to location to hold a five-character string, e.g. 23497)
37746 PUSH DE Store DE
37747 LD DE,54743 Point DE at table of powers of ten
37750 PUSH BC Store BC (value)
37751 PUSH HL Store HL (location to hold string)
37752 PUSH HL Store HL (location to hold string)
37753 LD H,B Load BC (value) into HL...
37754 LD L,C ...
37755 EX DE,HL Swap DE (now value) and HL (now pointer to table of powers of ten)
37756 LD C,(HL) Read WORD at HL (power of ten) into BC...
37757 INC HL ...and advance HL by two bytes...
37758 LD B,(HL) ...
37759 INC HL ...
37760 EX DE,HL Swap DE (now pointer to next power of ten) and HL (now value)
37761 LD A,47 Load A with 47 (ASCII code immediately prior to that for zero, "0")
37763 INC A Increase A to next ASCII character
37764 OR A Reset carry flag
37765 SBC HL,BC Subtract (BC [power of ten] + carry flag) from HL (value)
37767 JR NC,37763 If carry flag was not set then loop back to 37763
37769 ADD HL,BC Add power of ten back to HL
37770 EX (SP),HL Swap value on top of stack (now remaining value) with HL (now location to hold string)
37771 LD (HL),A Store ASCII code in table at 23497 and advance HL to next slot...
37772 INC HL ...
37773 EX (SP),HL Swap value on top of stack (pointer to entry in table of ASCII characters at 23497) with HL (now remaining value)
37774 DEC C Decrease C to check if last power of ten (i.e. 1) has been reached...
37775 JR NZ,37755 ...and if not, then loop back to 37755 for next power of ten
37777 POP HL Restore HL
37778 POP HL Restore HL
37779 POP BC Restore BC
37780 POP DE Restore DE
37781 RET Return
Prev: 37735 Up: Map Next: 37782