Asm codnig floating point number
- BlueLed
- Sunday, November 16, 2014 1:39 AM
- 17
Dear MSDN Community
Very kindly pleasant information about coded floating point numer in asm eg 0.5 .
Best Regards
Rafał Bator
17 Answers
Further to my last link, also see: CONTENTS http://www.website.masmforum.com/tutorials/fptute/index.html Chap. 2 Data types used by the FPU and addressing modes http://www.website.masmforum.com/tutorials/fptute/fpuchap2.htm - Wayne
WayneAKing
Sunday, November 16, 2014 2:39 AM
thank You for Your answer .
Very kindly pleasant information about how coded two floating point numbers in asm and add this .
I have skeleton this :
#include <iostream> #include <conio.h> #include <stdio.h> using namespace std; extern "C" int Asm(); int main() { { cout<<"ASM said"<<Asm()<<endl; } system("pause"); return 0; } .586 .model flat,stdcall .code Asm proc C mov eax,4 mov ebx,2 add ebx,eax ret Asm endp endit is add two int numbers .How change it ?
RB _1
Sunday, November 16, 2014 8:21 PM
AsmFloatBasic sums 4.5 and 2.0. AsmFloat sums its two parameters.
.586 .model flat, stdcall .code FLOAT_4_5 dd 40900000h ; 4.5 FLOAT_2_0 dd 40000000h ; 2.0 AsmFloatBasic proc C fld dword ptr [FLOAT_4_5] fadd dword ptr [FLOAT_2_0] ret AsmFloatBasic endp AsmFloat proc C fld dword ptr [esp + 4] fadd dword ptr [esp + 8] ret AsmFloat endp end
usage:
extern "C" float AsmFloatBasic(); extern "C" float AsmFloat(float a, float b); int main() { cout << "ASM said " << AsmFloatBasic() << endl; cout << "ASM said " << AsmFloat(3.5, -2.1) << endl; system("pause"); return 0; }
BlueLed
Monday, November 17, 2014 9:02 AM
Thank You for Your answer
Very kindly pleasant about information about this :
FLOAT_4_5 dd 40900000h;4.5
FLOAT_2_0 dd 40000000h;2.0
are allocation and definition ?
RB _1
Monday, November 17, 2014 3:33 PM
Sir , please translate me 40900000h;40000000h;
How are translate this numbers ?
RB _1
Monday, November 17, 2014 9:30 PM
It's IEEE 754:
http://en.wikipedia.org/wiki/Single-precision_floating-point_format
You can find online converters.
BlueLed
Monday, November 17, 2014 10:40 PM
Thank You for Your answer .
It is a plenty of piece to read .
What is it DD before hex numbers ?
RB _1
Monday, November 17, 2014 11:56 PM
BlueLed
Tuesday, November 18, 2014 12:19 AM
Thank You for Your answer
how do I knowthat converterswritingthe truth ?
Cannot I find converters which convert e.g 0.5 decimal to hex . Ok , i have this converter .RB _1
Tuesday, November 18, 2014 12:23 AM
float x = 1.23; // replace 1.23 with the number you want to convert cout << hex << *(__int32 *)&x << endl;
BlueLed
Tuesday, November 18, 2014 12:34 AM
Thank You for Your answer .
What is Your result by pencil for 1.0;0.5;0.75; in hexadecimal for float single precision ?
RB _1
Tuesday, November 18, 2014 2:41 PM
Dear BlueLed & Community
Very kindly pleasant thank You for Your answer .
In material which gave me and in x86-32 where i work is different . I counting all from method and i must move all in right in order to had good result according computer method . e.g 1.5625 according material IEEE 754 method is 7c400000h , according to x86-32 is 3e200000h , next 0.75 -> 7e800000h -> 3f400000h . 0.5 ->7e000000h-> 3f000000h . Then i move all in right . Where is mistake ? i must move in right by one place of course . Good result according IEEE 754 method will when the result of computer method move by one place in left . I checked it for 4.5 and 2.0 and is the same .
this is counting for 3 examples 1.5625 ; 0.75 ; 0.5 ; Checked for first application in this correct replies , and for convert , and t's IEEE 754: http://en.wikipedia.org/wiki/Single-precision_floating-point_format , and Dell Inspiron 17 and Dell Precision T5600 (both Intel processor : notebook i5-3210M , workstation 2xXeon E2609 0 ) , VS C++ 2005 Professional ; Win 7 64 PL Professional (notebook ) Ultimate ( workstation ) ; addition counting for 4.5;2.0;
RB _1
Tuesday, November 18, 2014 4:05 PM
0.5 = 1 * 2^(-1) * (1 + 0)
compare with:
(-1)^sign * 2^(exp - 127) * (1 + frac)
hence:
(-1)^sign = 1 ==========> sign = 0
2^(exp - 127) = 2^(-1) =========> exp = 126 (0x7E)
(1 + frac) = 1 ===========> frac = 0
Thus:
"sign exp frac" is
0 01111110 00000000000000000000000
pack
0011 1111 0000 0000 0000 0000 0000 0000 bin =====> 3F000000 hex
///////////////////////////////////////////
0.75 = 1.5 / 2 = 1 * 2^(-1) * (1 + 0.5)
compare with:
(-1)^sign * 2^(exp - 127) * (1 + frac)
hence:
(-1)^sign = 1 ==========> sign = 0
2^(exp - 127) = 2^(-1) =========> exp = 126 (0x7E)
(1 + frac) = (1 + 0.5) ===========> frac = 0.5
Thus:
"sign exp frac" is
0 01111110 10000000000000000000000
pack
0011 1111 0100 0000 0000 0000 0000 0000 bin =====> 3F400000 hex
BlueLed
Tuesday, November 18, 2014 10:35 PM
Thank You for Your answer
What is diferrent between "sign exp frac" and pack ?I see this diferrent , and do not understand it .
RB _1
Wednesday, November 19, 2014 12:52 AM
"sign" requires 1 bit.
"exp" requires 8 bits.
"frac" 23 bits.
The total is 32, four bytes.
You write them side by side: "sign" "exp" "frac" and group them (pack) to get four bytes.
BlueLed
Wednesday, November 19, 2014 1:03 AM
Thank You for Your answer .
According me is : 0.75 = 7E8(...)h
[0111][1110][1000](...) - binary 32 bit
1+2^(-1)=1.5 [1000]=0.5 [8h] 1.5*2^(-1) - because (126-127) [0111][1110]=126 [0111]=[7h] [1110]=[Eh]
what do You think about it ? It is in IEEE 754 single precision binary floating-point format : binary 32
ok , i see my mistake , thank You .RB _1
Wednesday, November 19, 2014 1:27 AM
Notes about Floating-Point Numbers in Assembly Language
(32 bits): The first bit is the sign bit: 0 for positive and 1 for negative. The next 7 bits are the exponent: -64 to +63, stored as 0 to 127. We would like to show you a description here but the site won’t allow us.
Floating Point Assembly Language
Floating Point Assembly Language. The floating point unit (FPU) was a separate chip through the 80386+80387. It is now located on-chip, but the programming Dear Community Please kindly inform us about the number offloating-point addressing mode x64 Asm Best Regards Rafał Bator · Dear Community Very kindly pleasant information
Floating-Point Instructions
The ALU is only capable of dealing with integer values. While integers are sufficient for some applications, it is often necessary to use decimals. A highly To avoid confusion, a floating-point number is called "normalized" if the first digit in its fraction is not 0. (If it is 0, move the decimal point over and adjust the exponent.) If the fraction is exacly 0, this cannot be done. We have 4 floating-point registers, each 64 bits long, numbered 0, 2 4 and 6.
Floating Point Assembly Language http://cs.fit.edu/~mmahoney/cse3101/float.html SIMPLY FPU http://www.website.masmforum.com/tutorials/fptute/fpuchap8.htm - Wayne
WayneAKing
Sunday, November 16, 2014 2:28 AM