changeset 51:e0c0ed649269

Make print_uint16d slightly smaller when removing leading zeroes
author William Astle <lost@l-w.ca>
date Sat, 10 Dec 2022 00:37:32 -0700
parents aecea4c62324
children 05c754390b1c
files src/lwbasic.s
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/lwbasic.s	Sat Dec 10 00:22:52 2022 -0700
+++ b/src/lwbasic.s	Sat Dec 10 00:37:32 2022 -0700
@@ -1311,23 +1311,22 @@
                 bsr print_uint16d4
                 puls d                          ; get back number residue and clean up stack
                 addb #0x30                      ; convert 1s digit to number
-                stb ,y+                         ; stash it
-                clr ,y                          ; NUL terminate it
+                stb ,y                          ; stash it
+                clr 1,y                         ; NUL terminate it
                 leay ,s                         ; point to start of converted number
-print_uint16d0  lda ,y+                         ; get first digit
-                beq print_uint16d3              ; brif number was zero
-                cmpa #0x30                      ; is it a zero?
-                beq print_uint16d0              ; brif so - skip it
-                leay -1,y                       ; move back to first nonzero digit
+print_uint16d0  lda ,y                          ; get digit at start
+                cmpa #0x30                      ; zero digit?
+                bne print_uint16d1              ; brif not - we can just show the number from here
+                ldb 1,y                         ; end of number?
+                beq print_uint16d1              ; brif so - show the zero anyway
+                leay 1,y                        ; move past the zero
+                bra print_uint16d0              ; see if we have more zeroes to skip
 print_uint16d1  lda ,y+                         ; get number digit
                 beq print_uint16d2              ; brif end of number
                 jsr writechr                    ; output the digit
                 bra print_uint16d1              ; handle next digit
 print_uint16d2  leas 6,s                        ; clean up the stack
                 rts
-print_uint16d3  lda #0x30                       ; digit 0 (less 1 for inc below)
-                leas 6,s                        ; clean up the stack
-                jmp writechr                    ; output zero and return
 print_uint16d4  lda #0x30-1                     ; init digit value
                 pshs a,u                        ; save the digit position and digit value
                 ldd 5,s                         ; get back residue