Author Topic: How to write jmp dword CSSelector:[offsets] in nasm?  (Read 4601 times)

Offline angwerto

  • Jr. Member
  • *
  • Posts: 3
How to write jmp dword CSSelector:[offsets] in nasm?
« on: January 04, 2015, 08:07:22 AM »
I have an offset stored in memory referring to an instruction I wanna jump to. So I try to write the command jmp dword CSSelector:[offsets] but this can not pass the compilation. The CSSelector is the selector of the instruction segment. And the offsets is the offset of the data segment storing the memory location address I want. So what's the right way to write such a instruction?

If this question is stupid I am quite sorry. Thanks in advance. :)

Offline angwerto

  • Jr. Member
  • *
  • Posts: 3
Re: How to write jmp dword CSSelector:[offsets] in nasm?
« Reply #1 on: January 04, 2015, 09:02:42 AM »
It seems that the Intel CPU does not support such instruction. So I think I need to first jump to the code segment and then jump to the offset.

Offline alexfru

  • Jr. Member
  • *
  • Posts: 17
Re: How to write jmp dword CSSelector:[offsets] in nasm?
« Reply #2 on: January 04, 2015, 12:45:21 PM »
You can create a far pointer in memory and jump using a far pointer.
Or you can push a far pointer to the stack and then do a far return.

Code: [Select]
bits 32

jmp far [fptr]

push 0x5e1e
push 0x0ff5ed
retf

fptr:
  dd 0x0ff5ed
  dw 0x5e1e

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2364
  • Country: us
Re: How to write jmp dword CSSelector:[offsets] in nasm?
« Reply #3 on: January 04, 2015, 01:34:44 PM »
Where are we?

Yeah, I think what Alexei says. If we have two immediates, we can do:
Code: [Select]
jmp 8:start32
Although this is a far jump, Nasm doesn't like the "far" keyword here. I don't think that's your situation.

I'd probably think first of the "retf" solution.
Code: [Select]
push CSSelector
push dword [offsets]
retf

Stuffing CSSelector into memory after "offsets" and "jmp far [offsets]" ought to work, too, if that's convenient for you. Note that Nasm doesn't know "fword" for this size, although other assemblers use it.

Let us know how you make out...

Best,
Frank


Offline angwerto

  • Jr. Member
  • *
  • Posts: 3
Re: How to write jmp dword CSSelector:[offsets] in nasm?
« Reply #4 on: January 05, 2015, 07:10:57 AM »
Thanks alexfru and Frank Kotler. Do learn something new.  ;)

I prefer using the retf method because I think it is easier to use. Declare the pointer doesn't fit naturally in my code. Actually when I got this question I searched the nasmdoc a lot but didn't find the answer. But when I see your answer and research the doc, I find it. It seems I have to read the doc more carefully.
« Last Edit: January 05, 2015, 07:24:04 AM by angwerto »