April 2003
Intermediate to advanced
576 pages
15h 13m
English
We can rewrite the DECNUM program (Figure 6-5) using a stack that stores each digit from right to left as individual bytes (most significant digit on the bottom of the stack). Each element is computed as a remainder, converted into an ASCII character, and then transferred byte-by-byte into the order (left to right) required for printing. The new DECNUM2 program is shown in Figure 7-3.
// DECNUM2 Convert integer to ASCII // This program converts the positive number at X2 // into a string of ASCII-encoded decimal digits at A2 W = 64 // W = number width LEN = 20 // Allowance for 20 digits DOT8 = 0xcccccccccccccccd // 0.8 (approx.) .data // Declare storage .align ... |