0

I want to far jump:

jmp 0x0000:0x7EA5

That works fine. However, I want to store the 0x0000 segment and 0x7EA5 offset, then use that stored value instead of hardcoding 0x0000:0x7EA5.

Is that even possible? I'm pretty new to assembly, so I'm not sure if it's even possible.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Sure it's possible. The exact syntax may depend on your assembler, though; which one are you using? And where do you want to store the pointer? – Nate Eldredge Nov 08 '20 at 05:05
  • 2
    If it is NASM (I'll take a guess based on the syntax shown) you can use FAR on a memory address like this: https://pastebin.com/vijUmwDX . I gave an example as some bootloader code as an example although from the address you gave I was curious if you might be doing some kind of kernel and/or bootloader development. It is also possible to push the segment and then the offset on the stack and then do a `retf` instruction. – Michael Petch Nov 08 '20 at 05:10
  • @NateEldredge i'm using nasm, i have the wanted segment (0) and offset (7EA5) stored in their own dd variables already (near to the jmp instruction's segment) `returnOffset dd 0x7EA5 returnSeg dd 0x0000` i'd like the pointer to also be stored near the jmp instruction so that i can do something like 'jmp pointer', if possible – astralorchid Nov 08 '20 at 05:16
  • The pastebin link in my post offers up a couple ways to do it with NASM. One of the ways seems applicable to what you are doing – Michael Petch Nov 08 '20 at 05:20
  • 1
    @MichaelPetch Oh wow, thank you! That pastebin helped. I moved my stored values into ax then pushed ax and used retf, it's working with the stored values now – astralorchid Nov 08 '20 at 05:26
  • 1
    Note the segment and offset are 16 bits (I'm assuming 8086 or real mode) but `dd` indicates 32 bits, so that may be a mistake. But anyway, the one note is that the offset and segment have to be contiguous in memory, forming a single 32-bit doubleword. If you had `returnPtr dw 0x7ea5, 0x0000` you could simply do `jmp far [returnPtr]`. – Nate Eldredge Nov 08 '20 at 05:29
  • @MichaelPetch: Sure, but OP's previous comment had the segment and offset *each* as `dd` which is probably wrong. – Nate Eldredge Nov 08 '20 at 05:37
  • 1
    Also a duplicate of [Jumping to a far address in real mode](https://stackoverflow.com/q/31944041), but nobody's upvoted my answer so I can't add it as a duplicate. – Peter Cordes Nov 08 '20 at 07:33

0 Answers0