Download presentation
Presentation is loading. Please wait.
1
Using the 80x87 Math Chip in Assembly
Bill Stockwell 11/21/2018
2
The Math Chip is builtin
Since the 486-DX, the IEEE math chip has been an integral part of the Intel processors. Before that, the math chip was a separate (and often expensive) add-on. 11/21/2018
3
Declaring Variables Use DQ in Nasm to declare floating point constants and variables. For example: x dq DQ describles an 8-byte quantity which will be discussed next. 11/21/2018
4
The IEEE format (DQ) Floating point numbers are stored as
+/- 1.m x 2^p where m is a 52 bit “mantissa” and p is an exponent that places the radix point. What is stored in the 64 bits is then s exp mantissa With s = sign bit, exp = 11 bit exponent, and mantissa the 52 bits with the numbers’ value. 11/21/2018
5
More on the IEEE format Again, +/- 1.m x 2^p is stored as
s exp mantissa (64 bits altogether) s = 0 for positive, 1 for negative exp = p , stored in 11 bits m is the 52 bit mantissa. Note the exponent is stored so no sign is needed, the 1023 is added for that purpose. 11/21/2018
6
Actual Math Chip Architecture
There are 8 80-bit registers, organized as a stack. These are referred to in Nasm code by st0, st1, …, st7. However, when you load a value onto the math chip stack, it is pushed onto the next available location, so often no direct reference to the registers is needed. 11/21/2018
7
Some instructions All the math chip instructions begin with the letter ‘F’. FLD – to push a value onto the math chip stack. FST – opposite of FLD, it gets a value from the top of the math chip stack. FADD – used to do floating point addition 11/21/2018
8
Some examples If x is defined as a DQ, we might have
fld qword [x]; push x onto math stack fadd qword [x]; add x to TOS and push this. So now the stack has 2x on the top and x below that. fmul qword [x]; This multiplies x by the TOS (2x) getting 2x^2 and pushes this. 11/21/2018
9
Some builtin constants
Various constants can be pushed as with fldz ; push floating point zero fld1 ; push 1.0 fldpi ; push PI ( to 20 places) and there are others – these are the most useful. 11/21/2018
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.