To pack a 3 bit number and a 5 bit number together into an 8 bit byte
X contains a 3 bit number and Y contains a 5 bit number
combine |
|
X = |
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y = |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
|
to produce |
|
R = |
|
R7 |
R6 |
R5 |
R4 |
R3 |
R2 |
R1 |
R0 |
|
|
|
X2 |
X1 |
X0 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
In XCSB this would be written as:
e.g.
X = 0x05
Y = 0x16
R = (X << 5) | Y
Looking step by step at the computation we see
|
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
|
R7 |
R6 |
R5 |
R4 |
R3 |
R2 |
R1 |
R0 |
X = 0x05 |
|
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Y = 0x16 |
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
|
|
|
|
|
|
|
|
|
R = (X << 5) |
|
|
|
|
|
|
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
R = R | Y |
|
|
|
|
|
|
|
|
|
|
|
|
|
x |
x |
x |
x |
x |
|
1 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
e.g.
X = 0x05
Y = 0x56
R = (X << 5) | Y
Looking step by step at the computation we see
|
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
|
R7 |
R6 |
R5 |
R4 |
R3 |
R2 |
R1 |
R0 |
X = 0x05 |
|
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Y = 0x56 |
|
|
|
|
|
|
|
|
|
|
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
|
|
|
|
|
|
|
|
|
R = (X << 5) |
|
|
|
|
|
|
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
R = R | Y |
|
|
|
|
|
|
|
|
|
|
|
x |
|
x |
x |
x |
x |
x |
|
1 |
1 |
1 |
1 |
0 |
1 |
1 |
0 |
NOTE: here the result 11110110 is incorrect, it should be 10110110 but because Y did not actually fit into 6 bits the result was corrupted.
The bit shown as 1 is in error, notice how this came from Y6
Using a mask to fix the above problem
e.g.
X = 0x05
Y = 0x56
R = (X << 5) | (Y & (0xff >> 3))
Looking step by step at the computation we see
|
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
|
R7 |
R6 |
R5 |
R4 |
R3 |
R2 |
R1 |
R0 |
|
E7 |
E6 |
E5 |
E4 |
E3 |
E2 |
E1 |
E0 |
X = 0x05 |
|
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Y = 0x56 |
|
|
|
|
|
|
|
|
|
|
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
R = (X << 5) |
|
|
|
|
|
|
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
E = 0xff |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
E = (E >> 3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
1 |
1 |
1 |
1 |
1 |
E = Y & E |
|
|
|
|
|
|
|
|
|
|
|
|
|
x |
x |
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
1 |
0 |
1 |
1 |
0 |
R = R | E |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
|
|
|
|
x |
x |
x |
x |
x |
To pack a 3 bit number, a 2 bit number and a 3 bit number together into an 8 bit byte
W contains a 3 bit number, X contains a 2 bit number, Y contains a 3 bit number
combine |
|
W = |
|
W7 |
W6 |
W5 |
W4 |
W3 |
W2 |
W1 |
W0 |
|
X = |
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y = |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
|
to produce |
|
R = |
|
R7 |
R6 |
R5 |
R4 |
R3 |
R2 |
R1 |
R0 |
|
|
|
W2 |
W1 |
W0 |
X1 |
X0 |
Y2 |
Y1 |
Y0 |
In XCSB this would be written as:
e.g.
W = 0x05
X = 0x02
Y = 0x06
R = (W << 5) | (X << 3) | Y
Looking step by step at the computation we see
|
|
W7 |
W6 |
W5 |
W4 |
W3 |
W2 |
W1 |
W0 |
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2 |
Y1 |
Y0 |
|
R7 |
R6 |
R5 |
R4 |
R3 |
R2 |
R1 |
R0 |
|
E7 |
E6 |
E5 |
E4 |
E3 |
E2 |
E1 |
E0 |
W = 0x05 |
|
0 |
0 |
0 |
0 |
0 |
1 |
0 |
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
X = 0x02 |
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
0 |
0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|
|
|
|
|
|
|
|
|
|
|
|
|
|
X = 0x0A |
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
0 |
1 |
0 |
1 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Y = 0x06 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
R = (W << 5) |
|
|
|
|
|
|
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
0 |
0 |
0 |
0 |
0 |
|
|
|
|
|
|
|
|
|
E = (X << 3) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x |
|
x |
x |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
1 |
0 |
1 |
0 |
0 |
0 |
0 |
E = E | Y |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
0 |
1 |
0 |
1 |
0 |
1 |
1 |
0 |
R = R | E |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
1 |
1 |
1 |
0 |
1 |
1 |
0 |
|
|
x |
|
x |
x |
x |
x |
x |
NOTE: here the result 11110110 is incorrect, it should be 10110110 but because Y did not actually fit into 6 bits the result was corrupted.
The bit shown as 1 is in error, notice how this came from X3
Using a mask to fix the above problem
e.g.
W = 0x05
X = 0x0A
Y = 0x06
R = (W << 5) | ((X & (0xff >> 6)) << 3) | (Y & (0xff >> 3))
Looking step by step at the computation we see
|
|
W7 |
W6 |
W5 |
W4 |
W3 |
W2 |
W1 |
W0 |
|
X7 |
X6 |
X5 |
X4 |
X3 |
X2 |
X1 |
X0 |
|
Y7 |
Y6 |
Y5 |
Y4 |
Y3 |
Y2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|
R = R | E |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
1 |
0 |
0 |
0 |
0 |
|
|
|
|
x |
x |
|
|
|
E = 0xff |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
E = (E >> 5) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
0 |
0 |
1 |
1 |
1 |
E = E & Y |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
x |
x |
x |
|
|
|
|
|
|
|
|
|
|
0 |
0 |
0 |
0 |
0 |
1 |
1 |
0 |
R = R | E |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
0 |
1 |
1 |
0 |
1 |
1 |
0 |
|
|
|
|
|
|
x |
x |
x |
NOTE: some of the steps shown here are combined by the XCSB compiler
into single step. The real code generated by the compiler is shorter
than shown, the full sequence is shown here for completeness