Quote Originally Posted by jderson View Post
IT WORKS! Now I'll spend the rest of the afternoon figuring out HOW it works! Thank you!
Dave
All the program is doing is pretending that two smaller variables are one bigger variable.
If you think about it, you can extrapolate the concept out to as far as you've got memory for.
A byte will hold 0-255, good enough for 0-99, not quite a 1000
A word will hold 0-65535, good enough for a '3-digit group'.
So a word holds a 3-digit group, just like a calculator does...
You keep adding into the least significant 3-digit group, checking after each add if that '3-digit group' overflowed by going over 999. Going over 999 isn't overflowed for a word variable, but it's overflowed for a '3-digit group'. Therefore, since the variable has held the whole value, we can subtract out the maximum of that '3-digit group', in this case 1000, and add 1 (or 2 if you overflowed to 2000, or 3 if you overflowed to 3000, and so on) to the next higher '3-digit group', which in this case, would also be the next higher word variable.

Example:
Code:
ones var word
thousands var word
millions var word
billions var word
trillions var word
quadrillions var word
quintillions var word
sextillions var word

lcdout $fe , 1
'if you had a 40 character LCD, this would probably show up like it should
main:
lcdout dec3 sextillioins,dec3 quintillions,dec3 quadrillions,dec3 trillions,dec3 billions,_
   dec3 millions,dec3 thousands,dec3 ones

ones = ones + 1

if ones > 1000 then
 ones = ones - 1000 : thousands = thousands + 1
end
if thousands > 1000 then
 thousands = thousands - 1000 : millions = millions + 1
endif
if millions > 1000 then
 millions = million - 1000 : billions = billions + 1
endif
if billions > 1000 then
 billions = billions - 1000 : trillions = trillions + 1
endif
if trillions > 1000 then
 trillions = trillions - 1000 : quadrillions = quadrillions + 1
endif
if quadrillions > 1000 then
 quadrillions = quadrillions - 1000 : quintilliions = quintillions + 1
endif
if quintillions > 1000 then
 quintillions = quintillions - 1000 : sextillions = sextillions + 1
endif
if sextillions > 1000 then you've counted a helluva lot of numbers

goto main
end
I wouldn't sit around waiting for the highest digit to roll over though... Might be there for awhile...