7.2. DECNUM2: Using Stack Operations

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.

Figure 7-3. DECNUM2: An illustration of stack usage
 // 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 ...

Get Itanium® Architecture for Programmers: Understanding 64-Bit Processors and EPIC Principles now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.