OSDev.org

The Place to Start for Operating System Developers
It is currently Tue Apr 23, 2024 9:42 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Nasm isn't willing to emit near jump
PostPosted: Sun Jan 03, 2016 9:07 am 
Offline
Member
Member

Joined: Fri Jan 30, 2015 4:57 pm
Posts: 215
Location: Germany
Consider following code:
Code:
org 0x12345
bits 32
lolo:
hlt
jmp near lolo


Then the code is compiled with nasm, the output is:
Code:
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?


Top
 Profile  
 
 Post subject: Re: Nasm isn't willing to emit near jump
PostPosted: Sun Jan 03, 2016 9:56 am 
Online
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5143
That is a near jump. What you want is a short jump.


Top
 Profile  
 
 Post subject: Re: Nasm isn't willing to emit near jump
PostPosted: Sun Jan 03, 2016 10:08 am 
Offline
Member
Member

Joined: Fri Jan 30, 2015 4:57 pm
Posts: 215
Location: Germany
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


Top
 Profile  
 
 Post subject: Re: Nasm isn't willing to emit near jump
PostPosted: Sun Jan 03, 2016 5:38 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 47 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group