Ric wrote: ↑Mon 15 Dec 2025, 11:13
I was always under the impression that if you were only loading the low or high byte, the rest of the register remained unchanged, thus the need to flush it first.
The rest of the register remains unchanged, yes, but that's fine since the subsequent code
doesn't care about the rest of the register. If it did,
osopen would be documented as receiving the parameter in
eax, not in
al, and your code would need to be:
Code: Select all
mov edx,text
mov eax,1
call "osopen"
ret
This code will work, of course, but it's wasteful because it's zeroing the other 24 bits of eax unnecessarily.
In a circumstance, which isn't the case here, when you need to zero-extend or sign-extend the
LS 8 bits of eax into the remaining
24 bits then use the specific instructions provided:
Code: Select all
movzx eax,al ; zero-extend al into eax
movsx eax,al ; sign-extend al into eax
Finally, remember that on a 64-bit CPU zero-extending a 32-bit register into a 64-bit register
happens automatically, it doesn't need any explicit code. For example
xor eax,eax zeroes all 64-bits of
rax, not just the lower 32-bits as you might expect.