AM2: Protected-Mode Programming
AM2: Protected-Mode Programming
AM2: Protected-Mode Programming
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
ECP4166: Advanced Microprocessors<br />
<strong>AM2</strong><br />
1.3.1 Operands<br />
A floating-point instruction can have zero operands, one operand, or two operands. If there<br />
are two operands, one must be a floating-point register. There are no immediate operands, but<br />
certain predefined constants (such as 0.0, _and log2 10) can be loaded into the stack.<br />
General-purpose registers such as EAX, EBX, ECX, and EDX cannot be operands. (The only<br />
exception is FSTSW, which stores the FPU status word in AX.) Memory-to-memory<br />
operations are not permitted. Integer operands must be loaded into the FPU from memory<br />
(never from CPU registers); they are automatically converted to floating-point format.<br />
Similarly, when storing floating-point values into integer memory operands, the values are<br />
automatically truncated or rounded into integers.<br />
1.3.2 Initialization (FINIT)<br />
The FINIT instruction initializes the FPU. It sets the FPU control word to 037Fh, which<br />
masks (hides) all floating-point exceptions, sets rounding to nearest even, and sets the<br />
calculation precision to 64 bits. We recommend calling FINIT at the beginning of your<br />
programs, so you know the starting state of the processor.<br />
1.3.3 Floating-Point Data Types<br />
Let’s quickly review the floating-point data types supported by MASM (QWORD, TBYTE,<br />
REAL4, REAL8, and REAL10), listed in Table 1.2. You will need to use these types when<br />
defining memory operands for FPU instructions. For example, when loading a floating-point<br />
variable into the FPU stack, the variable is defined as REAL4, REAL8, or REAL10:<br />
.data<br />
bigVal REAL10 1.212342342234234243E+864<br />
.code<br />
fld bigVal ; load variable into stack<br />
Table 1.2: Intrinsic Data Types.<br />
Type Usage<br />
QWORD 64-bit integer<br />
TBYTE 80-bit (10-byte) integer<br />
REAL4 32-bit (4-byte) IEEE short real<br />
REAL8 64-bit (8-byte) IEEE long real<br />
REAL10 80-bit (10-byte) IEEE extended real<br />
1.3.4 Reading and Writing Floating-Point Values<br />
In this experiment, the following two procedures for floating-point input-output (created by<br />
William Barrett of San Jose State University) are used:<br />
ReadFloat: Reads a floating-point value from the keyboard and pushes it on the floatingpoint<br />
stack. It accepts a wide variety of floating-point formats. Some examples<br />
are shown below:<br />
35 3.5E005<br />
+35. -3.5E+5<br />
-3.5 3.5E-4<br />
.35 +3.5E-4<br />
3.5E5<br />
WriteFloat: Writes the floating-point value at ST(0) to the console window in exponential<br />
format.<br />
ShowFPUStack: Another useful procedure, written by James Brink of Pacific Lutheran<br />
University, displays the FPU stack. It is called with no parameters:<br />
call ShowFPUStack<br />
Page 4 of 14