byte - Confused about assembly instructions -


i reading tutorial on assembly: http://orangejuiceliberationfront.com/intel-assembler-on-mac-os-x/ , came across basic assembly code:

    .text .globl _main _main:     pushl %ebp     movl %esp, %ebp     subl $8, %esp     movl $0, %eax     leave     ret 

and kinda understand of this, don't know why subl $8, %esp called. understand subtracts 8 bytes esp, have no idea why necessary or why done. tutorial said balances stack onto 16-byte boundary, don't know "balancing" stack means or why using number 8 makes 16 byte boundary.

later in tutorial show how define function, , call this:

    .text .globl _dosomething _dosomething:     pushl %ebp     movl %esp, %ebp     subl $8, %esp     nop     leave     ret  .globl _main _main:     pushl   %ebp     movl    %esp, %ebp     subl    $24, %esp     movl    $3, (%esp)     call    _dosomething     movl    $0, %eax     leave     ret 

and tutorial there "8 align, 16 our 4-byte parameter , padding" on line: subl $24, %esp

but if there 4 byte parameter , padding, why using number 16? also, parameter?

i on intel core mac, running os x 10.9.3, compiling gcc -s -m32 .

i'm new assembly, please make answers simple possible. thanks!

let's @ sequence of instructions:

1. nop   #call-stack aligned 16 bytes (sp multiple of 16) start. 2. call function #pushes return address (4 bytes) onto stack.  ---(called function) 3. push %ebp #pushes base-pointer (4 bytes) onto stack, 8-byte aligned ---cannot call function expects find 16-byte aligned stack--- 4. sub $8, %esp #aligns stack 16 bytes 5. call other_function 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -