Home > database >  Why aren't instructions' adresses consecutive in machine code?
Why aren't instructions' adresses consecutive in machine code?

Time:01-17

I just compiled a CPP source code into an object .o file, and the first couple of lines are like the following:

Disassembly of section .text:

0000000000000000 <_Z8mainLoopv>:
   0:   f3 0f 1e fa             endbr64 
   4:   55                      push   %rbp
   5:   48 89 e5                mov    %rsp,%rbp
   8:   41 55                   push   %r13
   a:   41 54                   push   %r12
   c:   53                      push   %rbx
   d:   48 81 ec 88 00 00 00    sub    $0x88,%rsp
  14:   64 48 8b 04 25 28 00    mov    %fs:0x28,%rax

I am assuming the first column is the adress of the instructions, am I right? If so, why aren't they consecutive? Something like this:

   0:   f3 0f 1e fa             endbr64 
   1:   55                      push   %rbp
   2:   48 89 e5                mov    %rsp,%rbp
   3:   41 55                   push   %r13
   4:   41 54                   push   %r12
   5:   53                      push   %rbx
   6:   48 81 ec 88 00 00 00    sub    $0x88,%rsp
   7:   64 48 8b 04 25 28 00    mov    %fs:0x28,%rax

CodePudding user response:

The first column is the address of the instruction, calculated from the first one in a routine.

Because x86_64 instructions aren't the same length (like ARM64 for example), the value difference varies. The second column show the bytes of each instructions. Notice that they have different lengths.

CodePudding user response:

Each instruction can take more than one bytes of space. Here, the first instruction takes four bytes of space(f3 0f 1e fa) so the next instruction starts at byte 4.

  •  Tags:  
  • Related