87 examples. Getting sqrt call readint fstcw control;;;store current control word or control,0800h;set bit 11 clear bit 10 to round up fldcw control;;load.

Slides:



Advertisements
Similar presentations
Link list/file stamps/clusters Odds and ends remaining for test 2.
Advertisements

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.
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.
COMP 2003: Assembly Language and Digital Logic
8087 instruction set and examples
Department of Computer Science and Software Engineering
Computer Organization & Assembly Language
Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
Runtime Stack Managed by the CPU, using two registers
Assembly Language for Intel-Based Computers
Accessing parameters from the stack and calling functions.
Flow Control Instructions
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures (c) Pearson Education, All rights reserved. You may modify and copy.
Coding.
Web siteWeb site ExamplesExamples Irvine, Kip R. Assembly Language for Intel-Based Computers, Defining and Using Procedures Creating Procedures.
Implementing a FIR-filter algorithm using MMX instructions by Lars Persson.
Simple Data Type Representation and conversion of numbers
Assembly Language for x86 Processors 6th Edition
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Floating Point Arithmetic
High-Level Language Interface Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/15 with slides by Kip Irvine.
FLOATING POINT ARITHMETIC. TOPICS Binary representation of floating point Numbers Computer representation of floating point numbers Floating point instructions.
Assembly Language for Intel-Based Computers, 6 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
Chapter 12: High-Level Language Interface. 2 Why Link ASM and HLL Programs? Use high-level language for overall project development Relieves programmer.
The x87 FPU Lecture 19 Fri, Mar 26, 2004.
THE 8087 MATH COPROCESSOR Data Types 3 Types 1. Binary integer 2. Packed Decimal 3. Real.
Arithmetic Flags and Instructions
Sahar Mosleh California State University San MarcosPage 1 Nested Procedure calls and Flowcharts.
Binary Number Output To display a number in binary format, a program looks at each bit in the number and sends the ASCII equivalent of a ‘1’ (31h) or a.
ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS, PROCEDURES.
Decision Structures – Code Generation Lecture 24 Mon, Apr 18, 2005.
26-Nov-15 (1) CSC Computer Organization Lecture 6: Pentium IA-32.
1 Logic, Shift, and Rotate Instructions Read Sections 6.2, 7.2 and 7.3 of textbook.
Lecture 21. _getproc proc near pushf ;Secure flag register contents push di ;== Determine whether model came before or after === xor ax,ax ;Set.
Assembly Language. Symbol Table Variables.DATA var DW 0 sum DD 0 array TIMES 10 DW 0 message DB ’ Welcome ’,0 char1 DB ? Symbol Table Name Offset var.
The x86 Instruction Set Lecture 16 Mon, Mar 14, 2005.
Computer Organization and Assembly Languages Yung-Yu Chuang 2006/11/13
LEA instruction The LEA instruction can be used to get the offset address of a variable Example ORG 100h MOV AL, VAR1 ; check value of VAR1 by moving it.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 5: Procedures Lecture 18 Linking to External Library The Book’s Link Library Stack Operations.
October 1, 2003Serguei A. Mokhov, 1 SOEN228, Winter 2003 Revision 1.2 Date: October 25, 2003.
Irvine, Kip R. Assembly Language for Intel-Based Computers. Chapter 7: Integer Arithmetic Slides to Accompany Assembly Language for Intel-Based Computers,
Real Numbers SignExponentMantissa.
Real Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2006/12/11.
Computer Organization & Assembly Language University of Sargodha, Lahore Campus Prepared by Ali Saeed.
Assembly Programming Practical2. Initialising Variables (Recap) Initialising variables are done in the.data section Initialising variables are done in.
Computer and Information Sciences College / Computer Science Department CS 206 D Computer Organization and Assembly Language.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
Subword Parallellism Graphics and audio applications can take advantage of performing simultaneous operations on short vectors – Example: 128-bit adder:
Paradyn Project Paradyn / Dyninst Week Madison, Wisconsin April 12-14, 2010 Paradyn Project Safe and Efficient Instrumentation Andrew Bernat.
Chapter 8 String Operations. 8.1 Using String Instructions.
Chapter 14: The Arithmetic Coprocessor, MMX, and SIMID Technologies.
Computer Architecture and Assembly Language
Assembly Language Lab 9.
Chapter R Prealgebra Review Decimal Notation.
Aaron Miller David Cohen Spring 2011
Assembly IA-32.
Assembly Language Lab (4).
Assembly Language Programming Part 2
Assembly Language for Intel-Based Computers, 5th Edition
Lesson How do you add and subtract fractions?
Fundamentals of Computer Organisation & Architecture
Shift & Rotate Instructions)
The x87 FPU Lecture 18 Wed, Mar 23, 2005.
Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22
X86 Assembly Review.
Assembly Language for Intel-Based Computers, 4th Edition
Computer Architecture and System Programming Laboratory
ICS51 Introductory Computer Organization
Computer Architecture and System Programming Laboratory
Presentation transcript:

87 examples

Getting sqrt call readint fstcw control;;;store current control word or control,0800h;set bit 11 clear bit 10 to round up fldcw control;;load new control word mov num,eax fild num fsqrt fistp sqr fwait mov edx, offset prompt2 call writestring mov eax,sqr call writeint

Rounding set to round up c:\Masm615>primes enter an integer125 sqrt of integer+12

Add code to check for prime and print divisors for composites mov eax,num call crlf mov ebx,2;;;first divisor top: xor edx,edx push eax div ebx;;divide mov divi,ebx cmp edx,0 je notprime inc ebx cmp ebx,sqr jg prime pop eax jmp top notprime: call writedec call crlf mov eax,divi call writedec call crlf mov edx,offset f call writestring prime: mov edx,offset t call writestring

Output from primes enter an integer not a prime c:\Masm615>primes enter an integer not a prime c:\Masm615>primes enter an integer not a prime c:\Masm615>primes enter an integer prime c:\Masm615>

factorials call readint mov num,eax call crlf fld1 ;;load a 1 for subtacting and comparing..this will be st(2) fld1 ;;prod value initialized in st(1) fild num;;;multiplier... need to count down and multiply st by st(1) theloop: ftst ;;is st==0? fstsw status and status, 4100h;check bits c3 and c0...c3=0 c0=1 means st<source cmp status,4000h;;st==source jz done fmul st(1),st ;;leave prod in st(1) fsub st,st(2) jmp theloop done: fistp dummy fistp answer mov edx,offset p2 call writestring call crlf fwait mov eax,answer call writedec

factorials c:\Masm615>factorials enter an integer6 factorial is 720 c:\Masm615>factorials enter an integer7 factorial is 5040 c:\Masm615>factorials enter an integer20 factorial is c:\Masm615>

Fibonacci values mov edx, offset prompt call crlf call writestring call readint call crlf fld1 ;;load a 1 for subtacting and comparing..this will be st(2) fld1 ;;prod value initialized in st(1) top: cmp eax,0 je done fadd st(1),st fsubr st,st(1);;;reverse subtract!!!! cute huhn?st=st(1)-st dec eax jmp top done: fistp dummy fistp answer mov edx,offset p2 call writestring call crlf fwait mov eax,answer call writedec

Fibonacci c:\Masm615>fibs enter an integer4 fib is 8 c:\Masm615>fibs enter an integer6 fib is 21 c:\Masm615>fibs enter an integer7 fib is 34 c:\Masm615>fibs enter an integer100 fib is c:\Masm615>

Mimicking real io You can output reals by outputting first the integer part, subtracting this from the original value, then repeatedly multiplying the fraction by ten, (subtracting this off from the remainder) and outputting this sequence of fractional digits. This is NOT an IEEE f-p conversion routine!

Rounding control & the int part fstcw control or control,0C00h ;;;chop or truncate fldcw control fild ten ;;ten is in st(1) fild num ;;num is in st(0) fsqrt ;;sqrt in st fist intsqr ;;;store chopped result, don’t pop call crlf mov edx,offset message call writestring fwait mov ax,intsqr ;;write the int part call writedec

realio mov edx,offset dot;;decimal point call writestring fisub intsqr ;;subtract from sqrt the int part leaving fractional part ;now loop & store 5 decimal places mov edi, offset decimals mov ecx, 5 up: fmul st,st(1) ;;multiply by 10 to shift dec point fist digit ;store truncated int fisub digit ;;subtract it off of the total fwait mov ax,digit add al,48 mov byte ptr [edi],al ;;store this digit inc edi loop up

Run of realio c:\Masm615>realio enter an integer: 121 sqrt of integer c:\Masm615>realio enter an integer: 123 sqrt of integer c:\Masm615>realio enter an integer: 143 sqrt of integer c:\Masm615>