I am struggling with a problem in assembly, where I have to take the first byte (FF) of the hex code and copy it over the entire value:
0x045893FF input 0xFFFFFFFF output
What I did is:
movl $0x04580393FF, %eax shl $24, %eax # to get only the last byte 0xFF000000
Now I want to copy this byte into the rest of the register.
You could do it for instance like this:
mov %al, %ah #0x0458FFFF mov %ax, %bx #0xFFFF shl $16, %eax #0xFFFF0000 mov %bx, %ax #0xFFFFFFFF
Another way would be:
movzx %al, %eax imul $0x1010101, %eax
The last one is possibly faster on modern architectures.
User contributions licensed under CC BY-SA 3.0