Assembly Language for Beginners

(Jeff_L) #1

1.19. FLOATING-POINT UNIT


The FPU has a stack capable to holding 8 80-bit registers, and each register can hold a number in the IEEE
754111 format.


They areST(0)..ST(7). For brevity,IDAand OllyDbg showST(0)asST, which is represented in some
textbooks and manuals as “Stack Top”.


1.19.3 ARM, MIPS, x86/x64 SIMD


In ARM and MIPS the FPU is not a stack, but a set of registers, which can be accessed randomly, likeGPR.


The same ideology is used in the SIMD extensions of x86/x64 CPUs.


1.19.4 C/C++


The standard C/C++ languages offer at least two floating number types,float(single-precision^112 , 32 bits)


(^113) anddouble(double-precision (^114) , 64 bits).
In [Donald E. Knuth,The Art of Computer Programming, Volume 2, 3rd ed., (1997)246] we can find the
single-precisionmeans that the floating point value can be placed into a single [32-bit] machine word,
double-precisionmeans it can be stored in two words (64 bits).
GCC also supports thelong doubletype (extended precision^115 , 80 bit), which MSVC doesn’t.
Thefloattype requires the same number of bits as theinttype in 32-bit environments, but the number
representation is completely different.


1.19.5 Simple example


Let’s consider this simple example:


#include <stdio.h>


double f (double a, double b)
{
return a/3.14 + b*4.1;
};


int main()
{
printf ("%f\n", f(1.2, 3.4));
};


x86


MSVC


Compile it in MSVC 2010:


Listing 1.201: MSVC 2010:f()

CONST SEGMENT
real@4010666666666666 DQ 04010666666666666r ; 4.1
CONST ENDS
CONST SEGMENT
real@40091eb851eb851f DQ 040091eb851eb851fr ; 3.14
CONST ENDS
_TEXT SEGMENT


(^111) wikipedia.org/wiki/IEEE_floating_point
(^112) wikipedia.org/wiki/Single-precision_floating-point_format
(^113) the single precision floating point number format is also addressed in theHandling float data type as a structure(1.24.6 on
page 373) section
(^114) wikipedia.org/wiki/Double-precision_floating-point_format
(^115) wikipedia.org/wiki/Extended_precision

Free download pdf