2

I have a jump like so:

jmp 0x8:label

I would like to replace the 0x8 constant with a value from for example the eax register:

jmp eax:label

Unfortunately NASM does not allow this. What alternative do I have to achieve this?

ecm
  • 2,583
  • 4
  • 21
  • 29
bmoxb
  • 33
  • 3
  • 2
    NASM doesn't support it because the processor doesn't support it. One method is to push the segment on the stack (eax), push the offset on the stack (label) and then do a far return. Doing a far return would act as a jump but this method allows a runtime value for the segment. – Michael Petch Oct 24 '22 at 16:00
  • @MichaelPetch Ah, very clever - I think that method will work for my use case. Thank you for the suggestion. – bmoxb Oct 24 '22 at 16:07
  • You could also push the values as mentioned in my first comment and do an indirect far jump using ESP as the address containing the address to jump to. I have an example of that in this answer (although it is in AT&T syntax). It could be converted to NASM. https://stackoverflow.com/a/49439075/3857942 – Michael Petch Oct 24 '22 at 16:09
  • 2
    You either need both values immediate, or both values in memory. – Peter Cordes Oct 24 '22 at 16:13

0 Answers0