asimes
asimes

Reputation: 5894

Please verify meaning of AT&T Assembly line

This line is not very clear to me (I'm very new to Assembly):

movsbl 0xffffffff(%edx,%ebx,1),%eax

I understand mov, but movsbl is a new one to me. In a simpler example that uses foo instead of 0xffffffff(%edx,%ebx,1) I understand it to be this (not at all sure this is right, just searched a related topic):

eax = foo&0x800000ff;

I've never had a line of Assembly refer to -1 (0xffffffff), where is the information being put into %eax coming from exactly? Is it whatever is stored at:

[%edx + %ebx -1]

Upvotes: 2

Views: 1633

Answers (2)

FrankH.
FrankH.

Reputation: 18227

If you'd write it in C, the line would be something akin to:

#include <stdlib.h>

int loadByte(char *base, size_t index)
{
    return (int)base[index - 1];
}

Compiling this (on UN*X, for 64bit x86) results in the following object code:

Disassembly of section .text:

0000000000000000 :
   0:   0f be 44 37 ff          movsbl 0xffffffffffffffff(%rdi,%rsi,1),%eax
   5:   c3                      retq

As previously said, movsb means move (load) a byte, sign extend it to ... (so there are movsbw, movsbl and movsbq for conversions to word / short, long / int and quad / long long).

Your assembly is for 32bit (because the registers used for addressing are 32bit), but otherwise the meaning is the same.

Upvotes: 1

Ian Atkin
Ian Atkin

Reputation: 6356

movsbl <%x, %y, 1>, %z

Says, read one byte from the memory location addressed by the first operand (x), extend the byte to 32 bits, and store the result in the register (z).

<%x, %y, 1> is the memory address formed by adding together the values of x and y; 1 is the multiplier applied to y.

Upvotes: 5

Related Questions