Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between long and short jump (x86)

I've read that short jumps are to be used when the relative jump is less than 124 in address, and long jumps should be used otherwise.

What is the difference in terms of operations performed in the CPU / performance between the two types of jumps on x86?

like image 420
nadavge Avatar asked Mar 28 '15 10:03

nadavge


Video Answer


1 Answers

There are actually three types of JMP instructions; short, near and far (long).

A short JMP is the relative JMP that you refer to. It is encoded as a two bytes; the actual JMP and the number of bytes +/- relative to the current IP.

A near jump allows you to jump within the current "segment" (using real mode terms) or within the currently selected memory area in the CS selector.

A long or Far JMP additionally includes a selector (or segment in real mode)

You can look up the timings for yourself. The biggest difference related to time is caused by the different numbers of bytes that must be read to accomplish the JMP.

like image 137
David Hoelzer Avatar answered Dec 15 '22 17:12

David Hoelzer