Near and Far JMPs

NEAR is in the same segment while FAR is another segment.

A near jump jumps to a location within the current code segment (pointed to by cs). A far jump is normally used to jump to a location within a different code segment, but it can jump to a location within the current segment as well, if the segment selector in the far address coincides with the value in cs.

From what I understand there are no segments in linux virtual memory?

I wouldn't be surprised to find Linux ports to CPUs using some kind of segmented memory. So, I'd say it depends. You're unlikely to see Linux use segments on the x86 platform, though. But again, you or someone else could make a small Linux running in real mode and using segments.

Also how do we know if my program's code is laid out in multiple segments?

You check the CPU and OS. Naturally, if you write portable C code, this should be of no concern to you.


It hasn't been segments for a long time now. The correct term in protected mode x86 is selector.

Having said that, the difference between a near jump and a far one is that the former maintains the same code selector cs while the latter (usually) changes it.

In a flat memory model, the former case is almost always how it's done.

You could have an operating system where the flat memory model is served by multiple selectors but I can't see a useful use case for it, and it's not the way Linux works, at least on x86.

Tags:

Assembly

X86

Nasm