Page 1 of 1
Nasm isn't willing to emit near jump
Posted: Sun Jan 03, 2016 9:07 am
by Techel
Consider following code:
Code: Select all
org 0x12345
bits 32
lolo:
hlt
jmp near lolo
Then the code is compiled with nasm, the output is:
As you can see, this isn't a near jump but a short one. How can I bring nasm to emit a near jump?
Re: Nasm isn't willing to emit near jump
Posted: Sun Jan 03, 2016 9:56 am
by Octocontrabass
That is a near jump. What you want is a short jump.
Re: Nasm isn't willing to emit near jump
Posted: Sun Jan 03, 2016 10:08 am
by Techel
Ah, I thought near means intrasegment absolute and short means relative, but near jumps can also be relative
There isn't a jump instruction with a absolute immediate destination, except far jump?
No there is none, I know
Re: Nasm isn't willing to emit near jump
Posted: Sun Jan 03, 2016 5:38 pm
by Brendan
Hi,
Roflo wrote:Ah, I thought near means intrasegment absolute and short means relative, but near jumps can also be relative
"Short" is 1-byte (signed) displacement, "near" is 2-byte or 4-byte (signed) displacement.
Roflo wrote:There isn't a jump instruction with a absolute immediate destination, except far jump? No there is none, I know
You can jump to an absolute target in a register (e.g. "jmp eax") and you can use indirect jumps (e.g. "jmp [pointer]"); but there's no jumping to an absolute immediate.
Note that there's very few cases where "jump to absolute immediate" makes sense but can't be converted into a near jump. The only case I can think of is jumping from position independent code to code at a fixed/known address.
Cheers,
Brendan