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.
-
3There's more than just one assembly instruction set out there... which one are you dealing with? x86? MIPS? PPC? ARM? etc... etc... etc..? – Marc B Oct 22 '11 at 17:01
-
1And MOVZBL to zero extend: http://stackoverflow.com/questions/9317922/what-does-the-movzbl-instruction-do-in-ia-32-att-syntax?lq=1 – Ciro Santilli OurBigBook.com Jul 08 '15 at 12:09
-
`movsbl` is AT&T syntax for [`movsx`](http://www.felixcloutier.com/x86/MOVSX:MOVSXD.html). Not *strictly* a duplicate, but so close that they really should be linked. Read the answer to the linked question with `movsx` in place of `movzx` and it works for this question, too. – Peter Cordes Jul 23 '16 at 03:15
4 Answers
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)).

- 10,509
- 2
- 26
- 39
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.

- 44,448
- 11
- 96
- 135
Assuming you are talking about x86, the MOVSBL instruction extends a byte (8 bits) representing a signed number to 32-bit signed number. The remaining 24 bits are zeros or ones depending on the sign so that the two's complement value remains.
Meaning, if you had a negative number, the upper 24 bits will be 1s, otherwise they will be zeroes.
The equivalent for unsigned numbers is MOVZBL, which extends always with 0s.

- 103
- 1
- 6
Assuming this is AT&T assembly syntax for IA32 (i386/x86_64) it means MOV with Sign-extension from Byte to Long. That is it is equivalent to MOVSX r32, r/m8
see 3-730 Vol. 2A.

- 29,780
- 4
- 43
- 53