PASM Coding help: Integer to ASCII - ASCII to Integer
Mike G
Posts: 2,702
Can some one point me to a resource for converting an integer to ASCII and an ASCII string to an integer using PASM? I knocked this conversion out in SPIN without much effort. For some reason converting SPIN to PASM has got me reeling. I think my base 10 SPIN approach is clogging up my thought process.
Comments
http://www.asciitable.com/index/asciifull.gif
And conversion to binary,,,
http://www.ascii.cl/conversion.htm
From two different objects that I wrote. May not be symmetric. Also not really tuned for efficiency (memory or speed), although it should be reasonable for most cases.
This is what I came up with. It looks a lengthy compared to SRLM's version. This exercise was much more involved than I thought; self-modifying code, division, looping...
If Johnny Mac is out there... Integer to ASCII could make a good Spin Zone article?
Next up, ASCII to integer. Should be a little easier, I hope.
Essentially, it works by shifting the hex value left into a destination register one bit at a time, and adding 3 to any nibble of the destination that is greater than 4. This converts the hex value into BCD, packed one digit per nibble. From here you'd just take the nibbles one at a time, add an ASCII offset of $30, and send to the LCD. The above routine can handle a decimal value of up to 99,999,999, any more than that and you'll need to modify it to use two longs for the destination.
The algorithm works just as well in reverse to convert decimal back into hex, shifting the BCD value right one bit at a time into the destination, still checking all nibbles of the BCD value and subtracting 3 from any nibble that is greater than 4.
So you have a 32bit data in memory, of course that is binary data.
And that we can also see it as dec and hex is just alternative version that
'data viewer' / assembler shows it.
Converting this binary to a 8 digit ascii hex would be great start.
unfortunately ascii A-F does not follow directly after 0-9
So either create a look up table, or with some controlled additions.
This should set 8 longs to ascii hex,
if you want reversed order use #myhex+8 and use sub label, _my9
if you want 8 bytes in 2 longs when it would need more coding.
can you please email me the spin code of integer to ASCII conversion for propeller?
my email is at_jay@yahoo.com.
Thanks
Jay
I couldn't find FullDuplexSerialPlus in the Object Exchange. Maybe it's part of some other package (like the Propeller Education Kit software). In any event, I've attached my copy of it.