1

I have the following function:

void myFunc()
{
    int a, b, c;

    a = 1;
    b = 2;
    c = 3;
}

gcc -S file.c gives such assembly code:

myFunc:
.LFB0:
    .cfi_startproc
    pushq   %rbp
    .cfi_def_cfa_offset 16
    .cfi_offset 6, -16 
    movq    %rsp, %rbp
    .cfi_def_cfa_register 6
    movl    $1, -12(%rbp)
    movl    $2, -8(%rbp)
    movl    $3, -4(%rbp)
    nop 
    popq    %rbp
    .cfi_def_cfa 7, 8
    ret 
    .cfi_endproc

As we see the variables a, b and c are stored in the memory below the place RSP register points to.

How does it work? Why didn't gcc subtract required memory space from esp? What if i would want to use inline assembly code and use there the instruction "push"? would it overwrite the local variable?

Rost
  • 65
  • 1
  • 7

0 Answers0