Download WINDOWS ASSEMBLY LANGUAGE & SYSTEMS PROGRAMMING

Transcript
42 Windows Assembly Language & Systems Programming
ibbP PLACE1
;using a l a b e l .
However, by writing the code in “proper” assembly language, we
do not need to know actual addresses. The second example here
shows how a proper assembler can have a symbolic address
marker, in this case PLACE1 .
JMP
instructiofl
In Figure 2.2, we looked at a CALL instruction, but there is also a
JMP (jump) instruction that transfers execution to the address
specified in its operand in the same manner as the CALL
instruction, but with a major difference: no return address is saved
on the stack. This is because JMP is used when you do not want
execution to come back.
SHORT,
NEAR, and
FAR
It was also explained above that the CALL can be NEAR or FAR,
but the JMP can be SHORT, NEAR, or FAR.
The example code below shows a JMP to a label. Usually, an
assembler defaults to a NEAR jump, as the destination is usually
in the same segment.
jmp PLACE1
;code l a b e l .
;arbitrary i n s t r u c t i o n .
PLiCEl:
mov ax,0
At this point, it is instructive to consider how the assembler will
assemble this .lMP instruction into memory. Obviously, it has to
be converted to “machine language”, or binary bits. That is what
any compiler or assembler does.
Figure 2.3: Generation of machine code, NEAR jump.
Increasing
addresses
downward
In Figure 2.3 you can see the basic scenario. The first one (or
sometimes two) memory location(s) contain the instruction-code,
or operation-code, often referred to as the op-code, that identifies
this as a JMP instruction (or whatever), while the following zero
or more bytes are the operand.
NEARJMP
In the case of the NEAR jump instruction, the operand contains a
16-bit offset, which is the place to jump to. But, and this is most
important, the addressing structure of all the Intel x86 CPUs uses