what does movsbl instruction do? [duplicate]
I have searched on the net, but i couldn't find a clear example to understand what does this instruction do. So, if someone can give an example about this, it will be very helpful to me.
Move with sign extend from byte to longword. In Intel syntax, the mnemonic of this instruction is MOVSX.
A C compiler may use this instruction when a variable of type int8_t
needs to be converted to int
, which happens automatically on arithmetic and a few other operations (integer promotion).
Because this instruction writes to all 32 (or 64) bits of the destination register, it avoids performance penalties that may result from writing to only the low 8 (or 16) bits of a register. A similar set of instructions allows extending with zero bits (MOVZX in Intel syntax, MOVZst in AT&T syntax (from size s to size t)).
Top web hit for movsbl
is this page, and if you search for movsbl
it says
MOVSBL and MOVZBL
* MOVSBL sign-extends a single byte, and copies it into a
double-word destination
* MOVZBL expands a single byte to 32 bits with 24 leading
zeros, and copies it into a double-word destination
Example:
%eax = 0x12345678
%edx = 0xAAAABBBB
MOVB %dh, %al %eax = 0x123456BB
MOVSBL %dh, %eax %eax = 0xFFFFFFBB
MOVZBL %dh, %eax %eax = 0x000000BB
Looks like a pretty clear example to me. For more examples, read the page that comes next.