2

In x86 assembly, how can I perform an unconditional jump from one section another?

Eg:

.section .text
main:    ...
         jmp here
         ...

.section .another
here:    ...

I guess this is a far jump. I get a segfault when trying to run this. Any workaround?

1201ProgramAlarm
  • 32,384
  • 7
  • 42
  • 56
TripShock
  • 4,081
  • 5
  • 30
  • 39

1 Answers1

1

Since you did not specify what assembler type (nasm, gas, masm, tasm)

If you know what segment is the the here part is, for example, if the .section part is in code segment 0x8, then you could do this:

jmp 0x8:here

You could define the constant to specify the segment and use that also...again your mileage will vary depending on the assembler..

Hope this helps, Best regards, Tom.

t0mm13b
  • 34,087
  • 8
  • 78
  • 110
  • 1
    Also, see here for another way of doing it, push the segment on the stack, push the address of the label on the stack and issue a far return as shown http://stackoverflow.com/questions/1398034/inline-assembly-jump-error – t0mm13b Jan 25 '10 at 03:22
  • 2
    Though keep in mind that issuing a return without a corresponding call is likely going to mess up the internal stack in the branch predictor, which screws with function call performance. You should use a far return to return from a far call, and a far jump otherwise. – Anon. Jan 25 '10 at 03:29
  • How do you perform a far jump in GAS? – TripShock Jan 26 '10 at 13:19
  • 2
    @TripShock: jmp $0x8:0x1000...see here for a quick reference on far jumps http://sig9.com/articles/att-syntax – t0mm13b Jan 26 '10 at 13:52