Hardware Reference
In-Depth Information
The destination for all LOOP instructions must be within 128 bytes of the cur-
rent position of the program counter because the instruction contains an 8-bit
signed offset. The number of instructions (as opposed to bytes) that can jumped
over cannot be calculated exactly because different instructions have different
lengths. Usually, the first byte defines the type of an instruction, and so some
instructions take only one byte in the code segment. Often, the second byte is used
to define the registers and register modes of the instruction, and if the instructions
contain displacements or immediate data, the instruction length can increase to
four or six bytes. The average instruction length is typically about 2.5 bytes per
instruction, so the LOOP cannot jump further back than approximatel 50 instruc-
tions.
There also exist some special string instruction looping mechanisms. These
are REP , REPZ , and REPNZ . Similarly, the five string instructions in the next block
of Fig. C-4 all have implied addresses and all use auto increment or auto decrement
mode on the index registers. In all of these instructions, the SI register points into
the data segment , but the DI register refers to the extra segment , which is based
on ES . Together with the REP instruction, the MOVSB can be used to move com-
plete strings in one instruction. The length of the string is contained in the CX reg-
ister. Since the MOVSB instruction does not affect the flags, it is not possible to
check for an ASCII zero byte during the copy operation by means of the REPNZ ,
but this can be fixed by using first a REPNZ SCASB to get a sensible value in CX
and later a REP MOVSB . This point will be illustrated by the string copy example
in Sec. C.8. For all of these instructions, extra attention should be paid to the seg-
ment register ES , unless ES and DS have the same value. In the interpreter a small
memory model is used, so that ES = DS = SS .
C.4.4 Jump and Call Instructions
The last block is about conditional and unconditional jumps, subroutine calls,
and returns. The simplest operation here is the JMP instruction. It can have a label
as destination or the contents of any effective address. A distinction is made
between a near jump and a far jump . In a near jump, the destination is in the cur-
rent code segment, which does not change during the operation. In a far jump, the
CS register is changed during the jump. In the direct version with a label, the new
value of the code segment register is supplied in the call after the label, in the
effective address version, a long is fetched from memory, such that the low word
corresponds to the destination label, and the high word to the new code segment
register value.
It is, of course, not surprising, that such a distinction exists. To jump to an
arbitrary address within a 20-bit address space, some provision has to be made for
specifying more than 16 bits. The way it is done is by giving new values for CS
and PC .
 
 
Search WWH ::




Custom Search