| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The JMP statement can take any one of the following forms:
In its simplest form, the JMP statement is similar to the GOTO statement in high level languages.
GOTO statement = JMP statement
It has the following syntax:
JMP [operator] destination where operator can be:
Relative AddressA jump is called a forward jump if the target address is larger than the address of the jump instruction. However, it is called a backward jump if the target address is less than or equal the address of the jump instruction. The next example illustrates both types of jumps.
In 16-bit addressing, 16-bits are required to store the offset address i.e. 2 bytes. However, analyzing most of the jumps occurring in a program, it can be observed that they are within a close distance to the jump instruction. Thus, to reduce the code size of the jump instruction we can encode the target address with one byte instead of two bytes. This can be achieved by storing the difference target - IP in the instruction instead of storing the actual target address. The difference can fit in a byte if it is within the range -128 to +127. When the CPU executes the jump instruction, it will get the difference target-IP from the instruction and will add to it IP, i.e., target-IP+IP=target, and will obtain the required target address. Jump instructions with the difference target-IP fitting in one byte are called short jumps.
A jump is called a near jump if the target address is in the same code segment
at any location ranging from -32,768 to +32,767 bytes from the IP.
The jump is a far jump if the target address is in a different code segment. In this case, the assembler stores the code segment and the offset of the target address within that segment in the instruction. The table below summarizes all the addressing modes used with the unconditional jump instruction.
The assembler can automatically select the SHORT jump and allocate one byte, if appropriate. So, we do not need to explicitly specify SHORT or NEAR PTR for addresses in the same segment as the assembler will select the appropriate type. The next example demonstrates the encodings of short, near, and far jumps.
As can be seen from the example, for both forward and backward jumps that
can be encoded as short will be allocated one byte by the assembler.
For example, the address of the label Forward
is 001A. The IP address after the instruction JMP Forward has the value
000A. Thus, the difference 001A-000A=0010. Since the difference can fit
in a byte, 10 is what is stored in the instruction.
|