I'm looking at some practice code for assembly, and the assignment is basically to replace one jump point with another.
The original jmp is a SHORT jmp, and the end point I need to approach cannot be reached with this instruction.
I have three options now, I either remove 'SHORT', I insert 'LONG' or I insert 'FAR'.
If there's documentation anywhere that indicates the differences between them, I haven't found it yet. Can anyone be of assistance here?
I've read that short jumps are to be used when the relative jump is less than 124 in address, and long jumps should be used otherwise.
Far jump—A jump to an instruction located in a different segment than the current code segment but at the same privilege level, sometimes referred to as an intersegment jump.
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 .
Near pointer is used to store 16 bit addresses means within current segment on a 16 bit machine. The limitation is that we can only access 64kb of data at a time. A far pointer is typically 32 bit that can access memory outside current segment.
I'm assuming your question pertains to the x86 architecture; you haven't specified in your question.
A SHORT
jump is a jump to a particular offset from the current instruction pointer address. A LONG
jump can use a larger offset value, and so can jump further away from the current instruction pointer address. Both of these jump types are usually relative - that is, the operand is an offset from the current instruction pointer (though in assembly source, you normally provide the target label - the assembler or linker then computes the offset). Neither of them jump to a different code segment, so they are both 'near' jumps.
A FAR
jump specifies both a segment and offset, which are both absolute in the sense that they specify the required code segment and instruction pointer, rather than an offset relative to the current code segment / instruction pointer.
To summarise, there are three types of direct jump: short and long, which are both near jumps capable of jumping different relative distances with the same code segment, and far, which can jump to any absolute address (segment and offset).
(Note that it is also possible to perform an indirect absolute jump, where you specify an operand that holds the absolute address that you wish to jump to. In this case the jump can either be near or far - i.e. it can include or not include the required code segment).
If you don't specify the jump 'distance', it is up to the assembler whether you get a short, long or far jump. Most modern assemblers are "two-pass" and will use a short jump if possible, or a long or far jump otherwise - the latter only if required.
See wikipedia's entry on x86 memory segmentation if you need help with understanding what I mean by 'segment'.
See this description of the x86 JMP instruction for full details of the possible JMP instruction addressing modes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With