Assembly Language for Intel-Based Computers, 5th Edition

Slides:



Advertisements
Similar presentations
Floating Point Unit. Floating Point Unit ( FPU ) There are eight registers, namely ST(0), ST(1), ST(2), …, ST(7). They are maintained as a stack.
Advertisements

Assembly Language for x86 Processors 6 th Edition Chapter 1: Introduction to ASM (c) Pearson Education, All rights reserved. You may modify and copy.
CSC 221 Computer Organization and Assembly Language Lecture 21: Conditional and Block Structures: Assembly Programs.
Assembly Language for x86 Processors 6th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy this slide.
ITCS 3181 Logic and Computer Systems 2015 B. Wilkinson slides3.ppt Modification date: March 16, Addressing Modes The methods used in machine instructions.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Conditional Loop Instructions LOOPZ and LOOPE LOOPNZ.
Irvine, Kip R. Assembly Language For Intel-Based Computers TYPE and SIZE Operators TYPE –returns the size, in bytes of a single element of a data label.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
CS2422 Assembly Language & System Programming October 3, 2006.
1 Lecture 5: Procedures Assembly Language for Intel-Based Computers, 4th edition Kip R. Irvine.
Assembly Language for Intel-Based Computers Chapter 16: Expert MS-DOS Programming (c) Pearson Education, All rights reserved. You may modify.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Stack Operations Runtime Stack PUSH Operation POP.
CS2422 Assembly Language and System Programming High-Level Language Interface Department of Computer Science National Tsing Hua University.
Assembly Language for x86 Processors 6th Edition
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 2: IA-32 Processor Architecture (c) Pearson Education, All rights reserved. You.
Instruction Set Design by Kip R. Irvine (c) Kip Irvine, All rights reserved. You may modify and copy this slide show for your personal use,
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 8: Advanced Procedures (c) Pearson Education, All rights reserved. You may.
CSC 221 Computer Organization and Assembly Language Lecture 12: Addressing Modes in Assembly.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
The x87 FPU Lecture 19 Fri, Mar 26, 2004.
Assembly Language for Intel-Based Computers Chapter 7: Integer Arithmetic (c) Pearson Education, All rights reserved. You may modify and copy.
Assembly Language for x86 Processors 7th Edition Chapter 13: High-Level Language Interface (c) Pearson Education, All rights reserved. You may modify.
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 4 th Edition Unpacked and Packed Integers (c) Pearson Education, All rights reserved. You may modify.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 19: Procedures Procedure’s parameters (c) Pearson Education, 2002.
CSC 221 Computer Organization and Assembly Language Lecture 16: Procedures.
CSC 221 Computer Organization and Assembly Language Lecture 15: STACK Related Instructions.
CSC 221 Computer Organization and Assembly Language Lecture 20: Conditional and Block Structures.
Assembly Language for Intel-Based Computers, 4 th Edition Lecture 22: Conditional Loops (c) Pearson Education, All rights reserved. You may modify.
Addressing Modes Dr. Hadi Hassan.  Two Basic Questions  Where are the operands?  How memory addresses are computed?  Intel IA-32 supports 3 fundamental.
ECE291 Computer Engineering II Lecture 11 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Chapter 14: The Arithmetic Coprocessor, MMX, and SIMID Technologies.
Chapter Overview General Concepts IA-32 Processor Architecture
CSC 221 Computer Organization and Assembly Language
Assembly Language for x86 Processors 6th Edition
Presentation on Real Mode Memory Addressing
Assembly Lab 3.
CSC 221 Computer Organization and Assembly Language
Chapter 9.
Microprocessor and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Assembly IA-32.
Assembly Language for x86 Processors
(The Stack and Procedures)
Microprocessor and Assembly Language
Assembly Language for Intel-Based Computers, 4th Edition
Computer Organization and Assembly Language
Chapter 4: Instructions
BIC 10503: COMPUTER ARCHITECTURE
Data-Related Operators and Directives
Computer Programming Machine and Assembly.
Using the 80x87 Math Chip in Assembly
Stack Frames and Advanced Procedures
The Instruction Set Architecture Level
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
(The Stack and Procedures)
Assembly Language for Intel-Based Computers, 5th Edition
Multi-modules programming
The x87 FPU Lecture 18 Wed, Mar 23, 2005.
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22
X86 Assembly Review.
Computer Architecture and System Programming Laboratory
(The Stack and Procedures)
By Nasser Halasa Assembly Language.
Assembly Language for Intel-Based Computers, 5th Edition
Computer Organization and Assembly Language
Computer Architecture and System Programming Laboratory
Copyright © 2013 Elsevier Inc. All rights reserved.
Presentation transcript:

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.