Assembly Language for Intel-Based Computers, 5th Edition Kip R. Irvine Floating-Point Processing for Assignment One By Sai-Keung Wong, NCTU (c) Pearson Education, 2006-2007. All rights reserved. You may modify and copy this slide show for your personal use, or for use in the classroom, as long as this copyright statement, the author's name, and the title are not changed.
FPU Register Stack Eight individually addressable 80-bit data registers named R0 through R7 Three-bit field named TOP in the FPU status word identifies the register number that is currently the top of stack. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Load A Floating Point Number .data myFloat01 REAL8 3.141592654 .code finit ;where is this number stored? ST(7) ST(6) ST(5) ST(4) ST(3) ST(2) ST(1) ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Load A Floating Point Number .data myFloat01 REAL8 3.141592654 .code finit fld myFloat01 ;where is this number stored? ST(7) ST(6) ST(5) ST(4) ST(3) ST(2) ST(1) 3.141592654 ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Load Two Numbers .data myFloat01 REAL8 3.141592654 myFloat02 REAL8 2.781281828 .code finit fld myFloat01 fld myFloat02 ; Where are these two numbers stored? ST(7) ST(6) ST(5) ST(4) ST(3) ST(2) 3.141592654 ST(1) 2.781281828 ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Load Three Numbers .data myFloat01 REAL8 3.141592654 myFloat02 REAL8 2.781281828 m_one REAL8 -1.0 .code finit fld myFloat01 fld myFloat02 fld m_one ; Where are these three numbers stored? ST(7) ST(6) ST(5) ST(4) ST(3) 3.141592654 ST(2) 2.781281828 ST(1) -1.0 ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Display a number in ST(0) .data v REAL8 -1.0 .code finit fld v call WriteFloat Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Store ST(0) into memory .data v REAL8 ? fArray REAL8 99 DUP(?) .code fst v ;direct addressing mov esi, offset fArray ;indirect addressing fst REAL8 PTR [esi] fst REAL8 PTR [esi + 8] Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Add Two Numbers .data v0 REAL8 -1.0 v1 REAL8 -2.0 .code finit fld v0 fld v1 fadd ST(0), ST(1) ; where is the result stored? ST(7) ST(6) ST(5) ST(4) ST(3) ST(2) -1.0 ST(1) -3.0 ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Product of Two Numbers .data v0 REAL8 -1.0 v1 REAL8 -2.0 .code finit fld v0 fld v1 fmul ST(0), ST(1) ; where is the result stored? ST(7) ST(6) ST(5) ST(4) ST(3) ST(2) -1.0 ST(1) 2.0 ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
1/n .data one REAL8 1.0 n REAL8 128.123 result REAL8 ? .code mov esi, offset n mov edi, result fld one fdiv REAL8 PTR [esi] ; ST(0) = ST(0) / REAL8 PTR [esi] fst REAL8 PTR [edi] ; store ST(0) to REAL PTR [edi] Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Generation the numbers between 0…N Generation the numbers between 0…N. Convert them into floating numbers and store them in an array. e.g. N = 10 0.0, 1.0, 2.0, 3.0, …, 10.0.
Generation the numbers between 0…N .data fArray REAL8 1000 DUP(?) one REAL8 1.0 zero REAL8 0.0 .code ;assume ecx = N inc ecx mov esi, offset fArray finit fld one fld zero L0: fst REAL8 PTR [esi] fadd ST(0), ST(1) add esi, 8 loop L0 Generation the numbers between 0…N ST(7) ST(6) ST(5) ST(4) ST(3) ST(2) 1.0 ST(1) 0.0 ST(0)
Factorial of A Number 0! = 1 1! = 1 2! = 1 x 2 3! = 1x2x3 4! = 1x2x3x4 … N! = ? Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
… … Factorial of A Number 1 2 3 4 1 1 ? ? ? 0! = 1 1! = 1 2! = 1 x 2 3! = 1x2x3 4! = 1x2x3x4 … N! = (N-1)! x N … 1 2 3 4 N … 1 1 ? ? ? N! Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Compute the factorials for the numbers between 0…N .data fArray REAL8 1000 DUP(?) ftArray REAL8 1, 1, 1000 DUP(?) .code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;assume ecx = N inc ecx mov esi, offset fArray mov edi, offset ftArray add edi, 8 add esi, 8*2 L1: finit fld REAL8 PTR [esi] fld REAL8 PTR [edi] fmul ST(0), ST(1) fst REAL8 PTR [edi+8] add esi, 8 loop L1 Compute the factorials for the numbers between 0…N esi … 1 2 3 4 fArray … 1 1 ? ? ? ftArray edi
Compute the factorials for the numbers between 0…N .data fArray REAL8 1000 DUP(?) ftArray REAL8 1.0, 1.0, 1000 DUP(?) .code …… inc ecx???? mov esi, offset fArray mov edi, offset ftArray add edi, 8 add esi, 8*2 L1: finit fld REAL8 PTR [esi] fld REAL8 PTR [edi] fmul ST(0), ST(1) fst REAL8 PTR [edi+8] add esi, 8 loop L1 Error? Compute the factorials for the numbers between 0…N esi … 1 2 3 4 fArray … 1 1 ? ? ? ftArray edi 17
… … Compute 1/N! 1 1 2 6 24 ? ? ? ? ? ftArray reciprocal esi edi .data fArray REAL8 1000 DUP(?) ftArray REAL8 1, 1, 1000 DUP(?) reciprocal REAL8 1000 DUP(?) one REAL8 1 .code ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;assume that ecx is set properly mov esi, offset ftArray mov edi, offset reciprocal L2: finit fld one fdiv REAL8 PTR [esi] fst REAL8 PTR [edi] add esi, 8 add edi, 8 loop L2 Compute 1/N! esi … 1 1 2 6 24 ftArray … ? ? ? ? ? reciprocal edi Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Read CMP, JE and JNE, etc. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.