Author Topic: relative calls  (Read 6415 times)

Offline florian

  • Jr. Member
  • *
  • Posts: 4
relative calls
« on: September 01, 2011, 08:00:49 PM »
Hi
I was wondering how to use relative calls.
If I assemble this:
Code: [Select]
section .text
global _main
_main:
mov eax, 2
call xy
xy:
pop eax
It gets translated with a fixed address:
Code: [Select]
00000000  66B802000000      mov eax,0x2
00000006  E80000            call word 0x9
00000009  6658              pop eax

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: relative calls
« Reply #1 on: September 01, 2011, 08:15:26 PM »
We write "call xy", and it gets disassembled as "call (address of) xy", but if you look at the actual encoding, it's "call" (e8) distance (plus or minus) to xy (0000, in this case).

Best,
Frank


Offline florian

  • Jr. Member
  • *
  • Posts: 4
Re: relative calls
« Reply #2 on: September 01, 2011, 08:24:01 PM »
Hmmm so I actualy already got what I wanted and I was just to stupid to see it :D

thank you for your help anyway :)

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: relative calls
« Reply #3 on: September 01, 2011, 08:34:25 PM »
It's not an obvious thing!

Best,
Frank