ARCHITECTURE AND INSTRUCTIONS

before being stored in a second string, or before being operated upon in some other fashion. The translation is performed by using the value in the AL register as an index into a table pointed at by the BX register. The translated value obtained from the table then replaces the value initially in the AL register.

Here is an example problem solved by use of primitive string operations and iteration con- trol operations to implement a complex string operation: An input driver must trans- late a buffer of EBCDIC characters into ASCII, and transfer characters until one of several EBCDIC control characters is encoun- tered. The transferred ASCII string is to be terminated with an EOT character.

To initialize the translation sequence, SI points to the beginning of the EBCDIC buffer, DI points to the beginning of the receiving ASCII buffer, BX points to an EBCDIC-to-ASCII translation table, and CX contains the length of the EBCDIC buffer (possibly empty). The translation table contains the ASCII equivalent for each EBCDIC character, perhaps with ASCII NULs for illegal characters. The EOT code is placed into the table corresponding to EBCDIC stop characters. The 8088 instruc- tion sequence to implement this example is the following:

Next:

 

 

JCXZ

Empty

;skip if input buffer empty

LODS

Ebcbuf

;fetch next EBCDIC character

XLAT

Table

;translate it to ASCII

CMP

AL, EOT

;test for the EOT

STOS

Ascbuf

;transfer ASCII character

LOOPNE

Next

;continue if not EOT

Empty:

The body of this loop requires seven bytes of code.

CONTROL TRANSFER INSTRUCTIONS

Four classes of control transfer operations

may be distinguished:

I)calls, jumps, and returns;

2)conditional transfers;

3)iteration control; and

4)interrupts.

All control transfer operations cause the pro- gram execution to continue at some new location in memory, possibly in a new code segment.

Calls, Jumps, and Returns

Two basic varieties of call jumps, and returns are provided - those which transfer control within the current code segment, and those which transfer control to an arbitrary code segment, which then becomes the current code segment. Both direct and indirect transfers are supported; indirect transfers make use of the standard addressing modes.

The three transfer operations are described below:

CALL pushes the offset address of the next instruction onto the stack (in the case of an inter-segment transfer the CS segment regis- ter is pushed first) and then transfers control to the target operand.

JMP transfers control to the target operand.

RET transfers control to the return address saved by a previous CALL operation, and optionally may adjust theSP register to dis- card stacked parameters.

Intra-segment direct calls and jumps specify a self-relative direct replacement, thus allowing position independent code. A short jump instruction (optional use) transfers -128 to

+127 bytes from the current instruction for code compaction.

Conditional Jumps

The conditional transfers of control perform a jump continuing upon various Boolean functions of the flag registers. The destination must be within -128 to +127 bytes from the instruction.

2-15

Page 50
Image 50
Intel 210200-002 manual Body of this loop requires seven bytes of code