News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Near and Far jumps?

Started by liamo1, September 08, 2010, 06:44:27 PM

Previous topic - Next topic

liamo1

can someone please explain when to use near(>) and far(>>) jumps.

Thanks in advance
Liam

ecube

you can use far jump at all times if you like but the difference is if the jumps further than 127 bytes you have to use far. in terms of opcodes a far jump is larger than a near, it's 5 bytes where as a near(short jump) is only 2 I believe. Or if the jumps larger than 4 gigabytes I think an absolute jump(which is 10 or 16 bytes depending on if its 32bit or 64bit) is used but you don't have to worry about that on 32bit systems.

liamo1

Thanks for your response E^cube. Does that apply to 64bit GoASM progs as well?

Liam

ecube

Quote from: liamo1 on September 08, 2010, 07:09:43 PM
Thanks for your response E^cube. Does that apply to 64bit GoASM progs as well?

Liam

in GoASM > and >> work the same, as far as the jumps I don't know. I've only seen absolute jumps in x64 but i'd imagine regular ones work aswell.

dedndave

SHORT branches are -128 to +127 bytes distant
NEAR branches are within the same code segment
FAR branches are to a different code segment

for win32, SHORT or NEAR are what you will use most of the time
FAR branches might be for things like KMD's or switching priviledge level - not "normal" code

older processors require conditional branches be SHORT distance
newer processors have extended instruction sets to allow NEAR conditionals
there is an advantage in loops if you keep the branches SHORT
for one thing, the instruction is shorter
another advantage, with some newer processors, is target label alignment
NEAR branch targets like to be 4-aligned - maybe even 16-aligned
SHORT branches don't seem to care too much about target alignment
this seems to vary widely from CPU to CPU