When I was writing my LCD libraries I found a compact, elegant, approach to converting the contents of a variable to a set of 5 digits using a loop and a shift in Rolfi's library of subroutines and macros SubsMacros1602I2C_M2v2.basinc here.
The code below using Rolfi's approach is 37 bytes with the statments "w5=34567" and "sertxd (b2)" commented out.
The code below using Rolfi's approach is 37 bytes with the statments "w5=34567" and "sertxd (b2)" commented out.
Code:
w5=34567
b2=w5/10000+"0" ; Prepare the 10,000's digit in b2
w5=w5//10000 ; and then mask out the 10,000 digit of w5 so the shift does not overflow w5
for b3 = 1 to 5 ; Print 5 digits
sertxd (b2) ; Print the current digit
b2=w5/1000+"0" ; Calculate the next digit
w5=w5//1000*10 ; Shift the remaing digits in w5 one position to the left
next
Last edited: