Disassembly: Allocating variables

0
int a = 20;
int b = 10;

Above source code is translated to disassembly code like this: (gdb)

int a = 10;
    0x8000683 movl $0xa,-0x10(%rbp)  main+8

int b = 20;
    0x800068a movl $0x14,-0xc(%rbp)  main+15

As I know, memory's address is distributed from the large number in the bottom to the small number in the top.

 +----------------+ 0x00000000
 |      Code      |
 +----------------+
 |      Data      |
 +----------------+
 |      Heap      | |
 +----------------+ V
 |                |
 +----------------+ A
 |     Stack      | |
 +----------------+ 0x7FFFFFFF

Then does -0x10(%rbp) of movl $0xa,-0x10(%rbp) mean variable a is located 0x10(16) bytes far from the bottom of the stack area? If so, how can I explain the instruction movl $0x14,-0xc(%rbp)? 0xc is 12, and variable a already takes 16 bytes space.

 +----------------+
 |                |
 |                |
 |                |
 |                |
 |                |
 |----------------| <- 0x10
 |                | <- 0xc (!!) 
 |        a       |
 |                |
 +----------------+ <- rbp
assembly
x86-64
stackframe
asked on Stack Overflow Apr 27, 2019 by EnDelt64 • edited Apr 27, 2019 by Peter Cordes

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0