Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assembly jmp memory expression

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

like image 762
leonsas Avatar asked Apr 18 '12 02:04

leonsas


People also ask

How does jmp work in assembly?

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.

What is jump in assembly language?

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.

What is short 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.

What is near jump and far 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.


2 Answers

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.

like image 176
Gunther Piez Avatar answered Oct 23 '22 09:10

Gunther Piez


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.

like image 30
ango Avatar answered Oct 23 '22 08:10

ango