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
We want to store these 2 values inside the dl register. The dl register is of 8 bits, so 5 + 3 = 8 bits
; al < 2 ^ 5, bl < 2 ^ 3mov al, blshl dl, 3or dl, bl ; xor would also work fine
mov cl, dl ; Make a copy of dland dl, 111b ; Extract lowest 3 bits (b)mov bl, dlshr cl, 3 ; Extract highest 5 bits (a)mov al, cl
After experimenting with this I thought of coding a high level version of this using C. In here we pack and unpack a DWORD and a short inside a DWORD64 variable and build a string value and again unpack the DWORD64 value back to their original variables with the original values.