Nasm isn't willing to emit near jump

Programming, for all ages and all languages.
Post Reply
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Nasm isn't willing to emit near jump

Post 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:

Code: Select all

F4 E9 [b]FA FF FF FF [/b]
As you can see, this isn't a near jump but a short one. How can I bring nasm to emit a near jump?
Octocontrabass
Member
Member
Posts: 5513
Joined: Mon Mar 25, 2013 7:01 pm

Re: Nasm isn't willing to emit near jump

Post by Octocontrabass »

That is a near jump. What you want is a short jump.
Techel
Member
Member
Posts: 215
Joined: Fri Jan 30, 2015 4:57 pm
Location: Germany
Contact:

Re: Nasm isn't willing to emit near jump

Post by Techel »

Ah, I thought near means intrasegment absolute and short means relative, but near jumps can also be relative #-o
There isn't a jump instruction with a absolute immediate destination, except far jump? No there is none, I know
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: Nasm isn't willing to emit near jump

Post by Brendan »

Hi,
Roflo wrote:Ah, I thought near means intrasegment absolute and short means relative, but near jumps can also be relative #-o
"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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply