Im dissasembling something for a project, and I encountered with the following line
jmp *0x80498c0(,%eax,4)
What exactly is that jump instruction trying to do? This is in a gdb environment.
Thanks
In the x86 assembly language, the JMP instruction performs an unconditional jump. Such an instruction transfers the flow of execution by changing the program counter.
A jump instruction, like "jmp", just switches the CPU to executing a different piece of code. It's the assembly equivalent of "goto", but unlike goto, jumps are notconsidered shameful in assembly.
A short jump can be achieved using a relative offset from the current assembly instruction. For x86/32-bit, this is a 2 byte instruction, where the first byte is always EB , for short jump, and the second byte is the number of bytes before or after the current instruction to jump.
Short jump—A near jump where the jump range is limited to –128 to +127 from the current EIP value. Far jump—A jump to an instruction located in a different segment than the current code segment but at the same privilege level, sometimes referred to as an intersegment jump.
This is an indirect jump.
The instruction calculates the location [0x80498c0 + eax*4]
, loads the value stored there and jumps to the address stored at this location.
This kind of code is quite common seen in jumptables, often after a C switch
instruction or equivalent.
Edit: The *
is specific to the AT&T syntax. It's a mnemonic for dereference, like in C. It is needed in the case the part in the braces is missing - jmp 0x80498c0
would just jump to this address, where jmp *0x80498c0
jumps to the target of the pointer stored in 0x80498c0.
see the Referencing memory: section here
A 32-bit addressing can be seen as follows (AT&T format)
immed32(basepointer,indexpointer,indexscale)
This is translated as the value at address given by
immed32 + basepointer + indexpointer * indexscale
For example, to address a[i] where "a" is an array of integers, you could write
(%eax, %ebx, 4)
such that eax register holds the base pointer of a and ebx has the index i.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With