Packing and retrieving packed bitfields


I'm interested in what the suggested way is to pack a value and retrieve that packed value again.

I think to do this from a memory address -- if I'm understanding correctly -- is trivial, as you can retrieve the value based on the memory offset. Is that correct, or is it more complex than that?

For trying to pack two 16-bit values into a register, here is what I have:

mov $72, %ax            # low 2-bytes  (of eax)
or $(19 << 16), %eax    # high 2 bytes (of eax)

mov %eax, %ebx
and $0x0000FFFF, %ebx # low bits go in ebx
mov %eax, %ecx

and $0xFFFF0000, %ecx # high bits go in ecx
shr $16, %ecx

Is this the suggested way to do it? And is there a way to do a 'move-and-mask' in a single operation, or it needs to be done in two steps?

mov %eax, %ebx
and $0x0000FFFF, %ebx
asked on Stack Overflow Oct 4, 2020 by David542 • edited Oct 4, 2020 by Peter Cordes

0 Answers

Nobody has answered this question yet.

User contributions licensed under CC BY-SA 3.0