How many byes is each instruction compiled to in x86 assembly?

Mask picture Mask · Mar 30, 2010 · Viewed 12.2k times · Source
0x004012d0 <main+0>:    push   %ebp
0x004012d1 <main+1>:    mov    %esp,%ebp
0x004012d3 <main+3>:    sub    $0x28,%esp

If the address is not available, can we calculate it ourselves?

I mean we only have this:

push   %ebp
mov    %esp,%ebp
sub    $0x28,%esp

Answer

Andrey picture Andrey · Mar 30, 2010

amount of bytes is difference of addresses between adjacent instructions:

0x004012d0 <main+0>:    push   %ebp ;1 byte
0x004012d1 <main+1>:    mov    %esp,%ebp ;2 bytes
0x004012d3 <main+3>:    sub    $0x28,%esp

if you have only text then go here: http://www.swansontec.com/sintel.html and here: http://faydoc.tripod.com/cpu/conventions.htm and calculate for each instruction, prefix and operand