flat assembler
Message board for the users of flat assembler.

Index > Main > near far jums calls

Author
Thread Post new topic Reply to topic
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 14 Feb 2005, 10:21
what's a different in calls to far or near addresses?

is it any difference in protected mode?

what about calls and stack ?

_________________
Microsoft: brings power of yesterday to computers of today.
Post 14 Feb 2005, 10:21
View user's profile Send private message Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 602
Location: Germany
MCD 14 Feb 2005, 10:46
That's a quiet nebie question, but I will try to answer it anyway.

Near addresses have only an offset value, whereas far addresses have a (always) 16bit segment value/selector too.

Thus, there are 6 basic possibilites for the call instruction with direct values:
Code:
in RM:
call 16bit_offset    1+2 bytes
call 16bit_segment_value:16bit_offset    1+2+2 bytes

in 16bit PM:
call 16bit_offset    1+2 bytes
call 16bit_segment_selector:16bit_offset    1+2+2 bytes

in 32bit PM:
call 32bit_offset    1+4 bytes
call 16bit_segment_selector:32bit_offset    1+2+4 bytes
    

Note that you can (try to) code calls with 32bit offsets in both RM and 16bit PM, but they won't usually work (CPU limited code <1Mb). You can also try to code calls with 16bit offsets in 32bit PM. I both of these cases, where you call an offset with another size, the machine instruction needs an additional prefix, e.g. the addr. size 67h.

So, there are far calls in PM, but you usually don't use them in PM, since most 32bit PM OSes user code uses a rather flat memory approach and thus you don't need segment selectors. It's usually reserved for the Kernel and some drivers.
Post 14 Feb 2005, 10:46
View user's profile Send private message Reply with quote
Madis731



Joined: 25 Sep 2003
Posts: 2139
Location: Estonia
Madis731 14 Feb 2005, 11:05
I think you haven't done your homework Smile
but the general rule is when the address that is being jumped to is ±127 bytes, then you can use near jump, otherwise you need more bytes to describe how far you'd like to jump.

Totally different is absolute jump that doesn't add to(sub from) but replaces the address of the destination with (E)IP.

calls and stack? What about them?
Post 14 Feb 2005, 11:05
View user's profile Send private message Visit poster's website Yahoo Messenger MSN Messenger Reply with quote
HarryTuttle



Joined: 26 Sep 2003
Posts: 211
Location: Poland
HarryTuttle 14 Feb 2005, 14:42
is it true that if I calls far procedure then CS is pushed on the stack after offset?

_________________
Microsoft: brings power of yesterday to computers of today.
Post 14 Feb 2005, 14:42
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen 17 Feb 2005, 16:58
That's not true, CS is always pushed before EIP. Note that in 32-bit protected mode is pushed CS padded with 16 high-order bits.
Post 17 Feb 2005, 16:58
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.