Move seperate bytes into a word
How can I combine these bytes into a word size variable? I am using only four bits of the bytes "0-3" and would like to place them into a word in such a way that "Z" holds A= 0-3, B= 4-7, C=8-11,and D=12-15.
Example:
A=%00000001
B=%00000010
C=%00000011
D=%00000100
Z=0100001100100001
I was thinking of using Aliases in the manual but not sure if that was a way to do it.
I really didn't want to do this:
z.0=a.0
z.1=a.1
etc.
Thanks
4 bytes RAM, 4 instructions to convert
OK - here's a little smaller verion...;o}
Code:
Z VAR WORD BANK0 ; use BANKA for 18F part
A VAR Z.LowByte
B VAR BYTE BANK0
C VAR Z.HighByte
D VAR BYTE BANK0
A=%00000001
B=%00000010
C=%00000011
D=%00000100
ASM
CHK?RP _Z
swapf _B, W ; swap nibbles in B, result in W
iorwf _A, F ; or with A, result in A (low byte is done)
swapf _D, W ; swap nibbles in D, result in W
iorwf _C, F ; or with C, result in C (HighByte is done)
ENDASM
Z = %0100 0011 0010 0001