Hi folks
I having a go a double dabble (or it's reverse) to convert an 8 digit unpacked BCD to binary. Rather than assign a variable name to each digit, I think I can do this:
If I use
Code:
digits idata
digit db 1,2,3,4,5,6,7,8
myprog code
...
end
I think I can loop through each digit by incrementing fsr and accessing indf, but how do I address the first (or any other, for that matter) digit?
Also, if I use
Code:
output res 4 ; it needs to end up a 32bit word, whatever
can I rrf my way through "output" instead of having 4 variable names to manage?
Both should work. However, decide first whether you're using big or little endian. I prefer little endian - I.E lowest byte stored first.
You can then do,
Code:
rrf output+3,f ;shift msbyte
rrf output+2,f ;shift next byte
rrf output+2,f ;shift next byte
rrf output,f ;shift lsbyte
Edit, you probably want to clear the carry before the shifts.
I used double dabble a few years ago but wrote it in C.
That's great, thanks Mike.
It occurred to me after I posted the question, I need to change individual digits of the BCD input (which comes from a keypad). Do I use the same notation? eg digit+1, digit+2 etc?