Technique(s) for converting integer to ascii bit pattern in pasm?
grahamreitz
Posts: 56
This has probably been answered before. Although, I didn't see anything with a quick forum search.
What techniques are used to convert an integer, stored in a cog register, into an ascii bit pattern, for the purpose of sending it to a terminal, such as the Parallax Serial Terminal?
Thanks,
graham
What techniques are used to convert an integer, stored in a cog register, into an ascii bit pattern, for the purpose of sending it to a terminal, such as the Parallax Serial Terminal?
Thanks,
graham
Comments
If you don't mind me parroting the algorithm:
1) Number in a cog register #1 is 123
2) 123/10 = 12r3, store 3 in register #2, 12 in register #1
3) 12/10 = 1r2, store 2 in register #3, 1 in register #1
4) 1/10 = 0r1, store 1 in register #4, 0 in register #1
5) End.
I see that there is a modulus operator in pasm, '//'. Although, does it only work on constants and not registers?
From manual:
"NOTE: All operators shown are constant expression operators."
I was looking for example syntax of the binary operators in pasm, but only saw spin examples.
Would this work?
Post Edited (greitz) : 8/21/2009 9:35:47 PM GMT
It's not really all that clear, but from what I've seen so far it works on positive numbers.
BTW, your code snippet above won't work, since operators in PASM are constant (compile time) only.
The proper division routine is a bit quicker but takes 30 or 40 longs of COG RAM. It's a lot easier in x86 where the processor does division for you; that's in the PASM instruction set but it's not implemented in the Prop I.