Introduction to 8086 Assembly

Similar documents
Chapter 03: Computer Arithmetic. Lesson 09: Arithmetic using floating point numbers

Programming Language A

COMP1917 Computing 1 Written Exam Sample Questions

COSC 243. Data Representation 3. Lecture 3 - Data Representation 3 1. COSC 243 (Computer Architecture)

Structured programming. Exercises 3

Introduction to Programming II W4260. Lecture 2

Applied Programming and Computer Science, DD2325/appcs15 PODF, Programmering och datalogi för fysiker, DA7011

CS Fall 2007 Homework #5

Sample Examination. Family Name:... Other Names:... Signature:... Student Number:...

Lecture 3. More About C

Arithmetic Expressions in C

Introduction to C++ Introduction to C++ Week 6 Dr Alex Martin 2013 Slide 1

CS Spring 2018 Homework #5

Principles of C and Memory Management

Introduction to Programming. Lecture 2: Introduction to C

The Newton Method as a Short WEB Example

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

Basic Assignment and Arithmetic Operators

Programming & Data Structure: CS Section - 1/A DO NOT POWER ON THE MACHINE

Fundamental of Programming (C)

ALGORITHM 2-1 Solution for Exercise 4

Unit 3. Operators. School of Science and Technology INTRODUCTION

Day05 A. Young W. Lim Sat. Young W. Lim Day05 A Sat 1 / 14

Tail recursion. Decision. Assignment. Iteration

Structured programming

Fundamentals of Programming

f(0.2) < 0 and f(0.3) > 0 f(1.2) > 0 and f(1.3) < 0 f(1) = 1 > 0 and f(2) 0.

Fundamental of Programming (C)

Fundamentals of Programming

1.3b Type Conversion

Week 3 More Formatted Input/Output; Arithmetic and Assignment Operators

Introduction to Programming

W4260: Modeling the Universe. Lecture 4

Lecture 9 - C Functions

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

Beginning C Programming for Engineers

Example C++ Program Demonstrating Usage of a Pointer to a Function in the Call to Another Function

Question Bank (SPA SEM II)

F28HS2 Hardware-Software Interface. Lecture 1: Programming in C 1

ECE 15 Fall 15 Midterm Solutions

Fundamental of Programming (C)

2. Numbers In, Numbers Out

C OVERVIEW. C Overview. Goals speed portability allow access to features of the architecture speed

Note: unless otherwise stated, the questions are with reference to the C Programming Language. You may use extra sheets if need be.

CPS104 Recitation: Assembly Programming

MA 511: Computer Programming Lecture 3: Partha Sarathi Mandal

for Loop Lesson 3 Outline

slicing An example of slicing Consider the following example:

C/Java Syntax. January 13, Slides by Mark Hancock (adapted from notes by Craig Schock)

C/Java Syntax. Lecture 02 Summary. Keywords Variable Declarations Data Types Operators Statements. Functions. if, switch, while, do-while, for

Chapter 1. Numeric Artifacts. 1.1 Introduction

3. EXPRESSIONS. It is a sequence of operands and operators that reduce to a single value.

C: How to Program. Week /Mar/05

These are reserved words of the C language. For example int, float, if, else, for, while etc.

Expressions. Arithmetic expressions. Logical expressions. Assignment expression. n Variables and constants linked with operators

Dept. of CSE, IIT KGP

C Programming Lecture V

Fundamentals of Programming

Variables Data types Variable I/O. C introduction. Variables. Variables 1 / 14

Slide Set 11. for ENCM 369 Winter 2015 Lecture Section 01. Steve Norman, PhD, PEng

The C language. Introductory course #1

Fundamental of Programming (C)

Name Roll No. Section

Part I Part 1 Expressions

Writing Program in C Expressions and Control Structures (Selection Statements and Loops)

Information Science. No. For each question, choose one correct answer and write its symbol (A E) in the box.

2. Numbers In, Numbers Out

Operators and Expressions:

Chapter 2 - Introduction to C Programming

INTRODUCTION TO C++ C FORMATTED INPUT/OUTPUT. Dept. of Electronic Engineering, NCHU. Original slides are from

Department of Computer Science & Engineering Indian Institute of Technology Kharagpur. Practice Sheet #06

int main() { return 0; }

Expression and Operator

As stated earlier, the declaration

SECTION A TRUE / FALSE QUESTIONS (10 MARKS) (INSTRUCTION: Please answer all 10 questions)

Basic C Programming (2) Bin Li Assistant Professor Dept. of Electrical, Computer and Biomedical Engineering University of Rhode Island

Chapter 4: Expressions. Chapter 4. Expressions. Copyright 2008 W. W. Norton & Company. All rights reserved.

Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26

Formatted Input/Output

Physics 306 Computing Lab 5: A Little Bit of This, A Little Bit of That

Intermediate Programming

Recap. ANSI C Reserved Words C++ Multimedia Programming Lecture 2. Erwin M. Bakker Joachim Rijsdam

for Loop Lesson 2 Outline

Expressions and Statementst t. Assignment Operator. C Programming Lecture 6 : Operators. Expression

Computer System and programming in C

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

AMCAT Automata Coding Sample Questions And Answers

Operators. Lecture 3 COP 3014 Spring January 16, 2018

C LANGUAGE A Short Course

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

Reals 1. Floating-point numbers and their properties. Pitfalls of numeric computation. Horner's method. Bisection. Newton's method.

Lecture 02 Summary. C/Java Syntax 1/14/2009. Keywords Variable Declarations Data Types Operators Statements. Functions

REU C Programming Tutorial: Part I FIRST PROGRAM

C OVERVIEW BASIC C PROGRAM STRUCTURE. C Overview. Basic C Program Structure

Lecture 9. Assignment. Logical Operations. Logical Operations - Motivation 2/8/18

Lecture 5: C programming

Lesson #3. Variables, Operators, and Expressions. 3. Variables, Operators and Expressions - Copyright Denis Hamelin - Ryerson University

Indian Institute of Technology, Kharagpur

ECE 15 Fall 15 Final Solutions

Number Systems. TA: Mamun. References: Lecture notes of Introduction to Information Technologies (ITEC 1011) by Dr Scott MacKenzie

Transcription:

Introduction to 8086 Assembly Lecture 19 Introduction to Floating Point

How to represent rational/real numbers Decimal 78.173 = 7 * 10 1 + 8 * 10 0 + 1 * 10-1 + 7 * 10-2 + 3 * 10-3 Binary 1001.1011 =?

How to represent rational/real numbers Decimal 78.173 = 7 * 10 1 + 8 * 10 0 + 1 * 10-1 + 7 * 10-2 + 3 * 10-3 Binary 1001.1011 = 1 * 2 3 + 0 * 2 2 + 0 * 2 1 + 1 * 2 0 + 1*2-1 + 0 * 2-2 + 1 * 2-3 + 1 * 2-4

Convert decimal to binary

Convert decimal to binary

Convert decimal to binary

Convert decimal to binary

Fixed point representation 1 2 3 1 2 7 8 4 1231.2784

Fixed point representation https://goo.gl/egnmxc https://goo.gl/nsbgxj https://goo.gl/yjpbnm 0.0000023718 m 53.2843453 m 12742345.23 m

Floating point representation https://goo.gl/egnmxc https://goo.gl/nsbgxj https://goo.gl/yjpbnm 0.0000023718 m 2.3718 * 10-6 53.2843453 m 5.3284 * 10 1 12742345.23 m 1.2742 * 10 7

IEEE 754 standard floating point representation single precision (32 bits) double precision (64 bits) look at http://cs.boisestate.edu/~alark/cs354/lectures/ieee754.pdf

Floating point arithmetic add subtract multiply divide

floating point range 32 bit int: up to 2.1*10 9 32 bit float: up to +3.4*10 38?

Example #include <stdio.h> float3.c int main() { float x = 1e12; float y = 1e-12; float z = x+y; printf("x= %e\n", x); printf("y= %e\n", y); printf("z= %e\n", z); printf("%d\n", x==z); return 0;

Example #include <stdio.h> float3.c int main() { float x = 1e12; float y = 1e-12; float z = x+y; printf("x= %e\n", x); printf("y= %e\n", y); printf("z= %e\n", z); printf("%d\n", x==z); return 0;

Example #include <stdio.h> float4.c int main() { int a = 88888888; int b = 88888889; float x = a; float y = b; printf("x=%.10f\n", x); printf("y=%.10f\n", y); printf("%d\n", x==y); return 0;

Example #include <stdio.h> float4.c int main() { int a = 88888888; int b = 88888889; float x = a; float y = b; printf("x=%.10f\n", x); printf("y=%.10f\n", y); printf("%d\n", x==y); return 0;

Example #include <stdio.h> float5.c int main() { float x = 88888888; printf("x=%f\n", x); for (int i = 0; i < 100000; i++) x++; printf("x=%f\n", x); return 0;

Example #include <stdio.h> float5.c int main() { float x = 88888888; printf("x=%f\n", x); for (int i = 0; i < 100000; i++) x++; printf("x=%f\n", x); return 0;

Example: Newton's method double h(double x) { return x*x*x*x*x - 1.25; int main() { double x = newton(h, 2); if (fabs(h(x)) == 0) printf("root= %e\n", x); else printf("root not found!\n"); return 0; test_root1.c x t+1 = x t - f(x t ) / f'(x t ) double newton(double (*f)(double x), double x0) { double x = x0; const double delta = 1e-7; while (f(x)!= 0 ) { double df_dx = (f(x+delta)-f(x))/delta; x = x - f(x) / df_dx; printf("%.10f, %e\n", x, f(x)); return x; test_root1.c

Example: Newton's method double newton(double (*f)(double x), double x0) { double x = x0; const double delta = 1e-7; while ( f(x)!= 0 ) { double df_dx = (f(x+delta)-f(x))/delta; x = x - f(x) / df_dx; printf("%.10f, %e\n", x, f(x)); return x; test_root1.c double newton(double (*f)(double x), double x0) { double x = x0; const double delta = 1e-7; while ( fabs(f(x)) >= 1e-10 ) { double df_dx = (f(x+delta)-f(x))/delta; x = x - f(x) / df_dx; printf("%.10f, %e\n", x, f(x)); return x; test_root2.c

Example: Newton's method int main() { double x = newton(h, 2); test_root1.c int main() { double x = newton(h, 2); test_root2.c if (fabs(h(x)) == 0) printf("root= %e\n", x); else printf("root not found!\n"); if ( fabs(h(x)) < 1e-10 ) printf("root= %e\n", x); else printf("root not found!\n"); return 0; return 0;

Example: Computing Convergent Series

Example: Convergent Series - forward summation #include <stdio.h> #include <math.h> float6.c int main() { double sum = 1; double p_factorial = 1; int max_itr = 20; for (int p = 1; p <= max_itr; p++) { p_factorial *= p; sum += 1/p_factorial; printf("sum= %.20f\n", sum); printf(" e = %.20f\n", M_E); printf(" sum-e =%e\n", fabs(sum-m_e)); return 0;

Example: Convergent Series - forward summation #include <stdio.h> #include <math.h> float6.c int main() { double sum = 1; double p_factorial = 1; int max_itr = 20; for (int p = 1; p <= max_itr; p++) { p_factorial *= p; sum += 1/p_factorial; printf("sum= %.20f\n", sum); printf(" e = %.20f\n", M_E); printf(" sum-e =%e\n", fabs(sum-m_e)); return 0;

Example: Convergent Series - backward summation #include <stdio.h> #include <math.h> float7.c int main() { double p_factorial = 1; int max_itr = 21; for (int p = 1; p <= max_itr; p++) p_factorial *= p; double sum = 0; for (int p = max_itr; p >= 0; p--) { sum += 1/p_factorial; p_factorial /= p; printf("sum= %.20f\n", sum); printf(" e = %.20f\n", M_E); printf(" sum-e =%e\n", fabs(sum-m_e)); return 0;

Example: Convergent Series - backward summation #include <stdio.h> #include <math.h> float7.c int main() { double p_factorial = 1; int max_itr = 21; for (int p = 1; p <= max_itr; p++) p_factorial *= p; double sum = 0; for (int p = max_itr; p >= 0; p--) { sum += 1/p_factorial; p_factorial /= p; printf("sum= %.20f\n", sum); printf(" e = %.20f\n", M_E); printf(" sum-e =%e\n", fabs(sum-m_e)); return 0;