The MASM Forum Archive 2004 to 2012

Project Support Forums => GoAsm Assembler and Tools => Topic started by: liamo1 on September 08, 2010, 06:44:27 PM

Title: Near and Far jumps?
Post by: liamo1 on September 08, 2010, 06:44:27 PM
can someone please explain when to use near(>) and far(>>) jumps.

Thanks in advance
Liam
Title: Re: Near and Far jumps?
Post by: ecube on September 08, 2010, 06:49:47 PM
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.
Title: Re: Near and Far jumps?
Post by: 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
Title: Re: Near and Far jumps?
Post by: ecube on September 08, 2010, 07:11:25 PM
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.
Title: Re: Near and Far jumps?
Post by: dedndave on September 09, 2010, 02:21:47 PM
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