1

Possible Duplicate:
what does movsbl instruction do?

Related: what does movsbl instruction do?

Upon disassembling a program, I found a really peculiar instruction:

0x0000000000401106: movsbl (%rbx,%rax,1),%ecx

I think I know what movsbl does: It basically extends a byte and adds leading ones (sign extended) to the register.

But I have absolutely no clue what it does when it is used in the above context.

Any light to shed on this instruction would be most appreciated!

Community
  • 1
  • 1
TtT23
  • 6,876
  • 34
  • 103
  • 174
  • Which disassembler? I'd assume the `<` and `>` are supposed to be `(` and `)`, and it's just a normal "sign extend byte at address RBX+RAX*1 to 32-bits and store in RCX" instruction. – Brendan Dec 14 '12 at 15:56
  • Note: Ironically; data moved into ECX causes the upper 32-bits of RCX to be zeroed; so this instruction would actually sign extend from 8-bits to 32-bits, then zero extend from 32-bits to 64-bits... :-) – Brendan Dec 14 '12 at 16:00

2 Answers2

2

The instruction

movsbl <%rbx,%rax,1>,%ecx

reads one byte from the memory location addressed by the first operand, sign extends the byte to 32 bits, and stores the result in the ecx register.

Now to <%rbx,%rax,1>. This simply denotes the memory address formed by adding together the values of rbx and rax. In case you're wondering, the 1 is the multiplier applied to rax.

NPE
  • 486,780
  • 108
  • 951
  • 1,012
0

That instruction loads a byte from address rbx+rax and sign extends it into ecx. Note that sign extension duplicates the most significant bit of the source into the top bits of the destination so it's not always "leading ones". This is so that when interpreted as 2's complement signed number, the value doesn't change.

Jester
  • 56,577
  • 4
  • 81
  • 125