Intel 80286, 80287 manual Chapter Numeric Programming Examples

Models: 80287 80286

1 515
Download 515 pages 45.04 Kb
Page 457
Image 457

CHAPTER 4

NUMERIC PROGRAMMING EXAMPLES

The following sections contain examples of numeric programs for the 80287 NPX written in ASM286. These examples are intended to illustrate some of the techniques for programming the 80287 comput- ing system for numeric applications.

CONDITIONAL BRANCHING EXAMPLES

As discussed in Chapter Two, several numeric instructions post their results to the condition code bits of the 80287 status word. Although there are many ways to implement conditional branching following a comparison, the basic approach is as follows:

Execute the comparison.

Store the status word. (80287 allows storing status directly into AX register.)

Inspect the condition code bits.

Jump on the result.

r

Figure 4-1 is a code fragment that illustrates how two memory-resident long real numbers might be compared (similar code could be used with the FTST instruction). The numbers are called A and B, and the comparison is A to B.

The comparison itself requires loading A onto the top of the 80287 register stack and then comparing it to B, while popping the stack with the same instruction. The status word is then written into the 80286 AX register.

A and B have four possible orderings, and bits C3, C2, and CO of the condition code indicate which ordering holds. These bits are positioned in the upper byte of the NPX status word so as to correspond to the CPU's zero, parity, and carry flags (ZF, PF, and CF), when the byte is written into the flags. The code fragment sets ZF, PF, and CF of the CPU status word to the values of C3, C2, and CO of the NPX status word, and then uses the CPU conditional jump instructions to test the flags. The resulting codi: is extremely compact, requiring only seven instructions.

The FXAM instruction updates all four condition code bits. Figure 4-2 shows how a jump table can be used to determine the characteristics of the value examined. The jump table (FXA~TBL) is initial- ized to contain the 16-bit displacement of 16 labels, one for each possible condition code setting. Note that four of the table entries contain the same value, because four condition code settings correspond to "empty."

The program fragment performs the FXAM and stores the status word. It then manipulates the condi- tion code bits to finally produce a number in register BX that equals the condition code times 2. This involves zeroing the unused bits in the byte that contains the code, shifting C3 to the right so that it is adjacent to C2, and then shifting the code to multiply it by 2. The resulting value is used as an index that selects one of the displacements from FXA~TBL (the multiplication of the condition code is required because of the 2-byte length of each value in FXAM_TBL). The unconditional JMP instruc- tion effectively vectors through the jump table to the labelled routine that contains code (not shown in the example) to process each possible result of the FXAM instruction.

4-1

Page 457
Image 457
Intel 80286, 80287 manual Chapter Numeric Programming Examples