Download presentation
Presentation is loading. Please wait.
Published byYuliana Sudjarwadi Modified over 6 years ago
1
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, 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.
2
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.
3
Load A Floating Point Number
.data myFloat01 REAL 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.
4
Load A Floating Point Number
.data myFloat01 REAL code finit fld myFloat01 ;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.
5
Load Two Numbers .data myFloat01 REAL myFloat02 REAL code finit fld myFloat01 fld myFloat02 ; Where are these two numbers 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.
6
Load Three Numbers .data myFloat01 REAL myFloat02 REAL m_one REAL 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) ST(2) ST(1) -1.0 ST(0) TOP Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
7
Display a number in ST(0)
.data v REAL code finit fld v call WriteFloat Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
8
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.
9
Add Two Numbers .data v0 REAL v1 REAL 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.
10
Product of Two Numbers .data v0 REAL v1 REAL 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.
11
1/n .data one REAL8 1.0 n REAL 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.
12
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 = , 1.0, 2.0, 3.0, …, 10.0.
13
Generation the numbers between 0…N
.data fArray REAL DUP(?) one REAL8 1.0 zero REAL 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)
14
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.
15
… … 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.
16
Compute the factorials for the numbers between 0…N
.data fArray REAL 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
17
Compute the factorials for the numbers between 0…N
.data fArray REAL 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
18
… … Compute 1/N! 1 1 2 6 24 ? ? ? ? ? ftArray reciprocal esi edi
.data fArray REAL DUP(?) ftArray REAL8 1, 1, 1000 DUP(?) reciprocal REAL 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.
19
Read CMP, JE and JNE, etc. Irvine, Kip R. Assembly Language for Intel-Based Computers 5/e, 2007.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.