tags:

views:

188

answers:

1

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?

+1  A: 

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.

tommieb75
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
tommieb75
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.
How do you perform a far jump in GAS?
TripShock
@TripShock: jmp $0x8:0x1000...see here for a quick reference on far jumps http://sig9.com/articles/att-syntax
tommieb75