I was doing some random experiments using assembly and C. This is a simple example in packing 2 numbers inside a register in assembly. Let’s assume
$latex al < 2^{5}&bg=232225&fg=bbbbbb&s=4$
$latex bl < 2^{3}&bg=232225&fg=bbbbbb&s=4$
We want to store these 2 values inside the dl register. The dl register is of 8 bits, so 5 + 3 = 8 bits
Packing
1 2 3 4 |
; al < 2 ^ 5, bl < 2 ^ 3 mov al, bl shl dl, 3 or dl, bl ; xor would also work fine |
Unpacking
1 2 3 4 5 |
mov cl, dl ; Make a copy of dl and dl, 111b ; Extract lowest 3 bits (b) mov bl, dl shr cl, 3 ; Extract highest 5 bits (a) mov al, cl |