"Z" holds
A= 0-3,
B= 4-7,
C=8-11,and
D=12-15.
First thing is to isolate each 4LSB of each variable. Easy way, using boolean AND (&)
Code:
A = A & $0F
B = B & $0F
C = C & $0F
D = D & $0F
Now, you need to shift some bits of your Bytes variables. This is done using left shift (<<). Check your manual about that. Knowing that, we could modify the above like
Code:
A = A & $0F
B = B << 4
C = C & $0F
D = D << 4
Now you need to combine A & B, and C & D, then the whole thing together. Boolean OR do the trick
Code:
A = (A & $0F) | (B <<4) ' a hold A & B
C = (C & $0F) | (D <<4) ' C hold C & D
Then you need to send A and C where they're suppose to go in Z
Code:
Z.LowByte = A
Z.HighByte = C
A is now LSB of Z(0-7), C is now MSB of Z(8-15).
This could be shorten like
Code:
Z.LowByte = (A & $0F) | (B <<4)
Z.HighByte = (C & $0F) | (D <<4)
If you're REALLY SURE you NEVER EVER mess with bits <7:4> of your variables, then yes, this could reduce to
Code:
Z.HighByte = (D<<4) | C
Z.LowByte = (B<<4) | A
OR
Code:
Z = (D<<12) | (C<<8) | (B<<4) | A
I see other ways, but this should be more than enough to start
Bookmarks