0
   1                                  section     .data
     2 00000000 00                      sum: db 0
     3 00000001 [10000000]              tbl: dd L
     4                                  section     .text
     5                                  global      _start                              
     6                                  _start:
     7 00000000 31C0                    xor eax, eax
     8 00000002 B002                    mov al,2
     9 00000004 BB[00000000]            mov ebx,sum
    10 00000009 B200                    mov dl,0 
    11 0000000B B9[01000000]            mov ecx,tbl
    12                                  align 16
    13 00000010 01C0                    L:   add eax,eax
    14 00000012 FEC2                         inc dl
    15 00000014 01C0                         add eax,eax
    16 00000016 0103                         add [ebx],eax
    17 00000018 FF21                         jmp dword [ecx]     
    18 0000001A 0013                         add byte [ebx],dl
    19                                  next:

if the loader will change the position in the memory of the text section to a different one from what the compiler set is line 9 still be correct? (the address of sum and tbl will be OK?)

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
GO VEGAN
  • 1,113
  • 3
  • 15
  • 44
  • 1
    If your loader does not do runtime relocations, then it will only load the sections to the given addresses. Note that the linker will adjust these addresses first. – Jester Jun 27 '20 at 18:56
  • what is the parentheses around the number mean? (lines 3,9,11) – GO VEGAN Jun 27 '20 at 20:40
  • 1
    exact duplicate of [Why \`define dd\` convert to machine code in this way?](https://stackoverflow.com/q/62614017) which is answered in comments. – Peter Cordes Jun 27 '20 at 20:49
  • Relocated absolute addresses get printed in `[]`, unresolved relative addresses in `()` e.g. `E9(00000000) jmp foo` – Jester Jun 27 '20 at 22:25

0 Answers0