Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22

Slides:



Advertisements
Similar presentations
CH10 Instruction Sets: Characteristics and Functions
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.
Machine Instructions Operations
Week 3. Assembly Language Programming  Difficult when starting assembly programming  Have to work at low level  Use processor instructions >Requires.
Comp Sci Floating Point Arithmetic 1 Ch. 10 Floating Point Unit.
80x86 Instruction Set Dr. Qiang Lin.
Prof. Muhammad Saeed II. 1/27/2015 Computer Architecture & Assembly Language 2.
Assembly Language for Intel-Based Computers, 4 th Edition Chapter 6: Conditional Processing (c) Pearson Education, All rights reserved. You may modify.
1 ICS 51 Introductory Computer Organization Fall 2006 updated: Oct. 2, 2006.
Assembly Language for Intel-Based Computers
Assembly Language for Intel-Based Computers Chapter 2: IA-32 Processor Architecture Kip Irvine.
What is an instruction set?
Assembly Language for x86 Processors 6th Edition
CEG 320/520: Computer Organization and Assembly Language ProgrammingIntel Assembly 1 Intel IA-32 vs Motorola
Sahar Mosleh California State University San MarcosPage 1 CPU Flags and Boolean Instructions.
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CS-334: Computer.
Computer Architecture and Operating Systems CS 3230 :Assembly Section Lecture 10 Department of Computer Science and Software Engineering University of.
Floating Point Arithmetic
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.
Computer Architecture and Organization
1 ICS 51 Introductory Computer Organization Fall 2009.
Microprocessors The ia32 User Instruction Set Jan 31st, 2002.
Decision Structures – Code Generation Lecture 24 Mon, Apr 18, 2005.
26-Nov-15 (1) CSC Computer Organization Lecture 6: Pentium IA-32.
Computer Architecture EKT 422
What is a program? A sequence of steps
Real Numbers SignExponentMantissa.
Real Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2006/12/11.
Microprocessor & Assembly Language Arithmetic and logical Instructions.
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures.
Assembly Language for Intel-Based Computers, 4 th Edition Week 10: Conditional Processing Slides modified by Dr. Osama Younes.
ECE291 Computer Engineering II Lecture 11 Dr. Zbigniew Kalbarczyk University of Illinois at Urbana- Champaign.
Chapter Overview General Concepts IA-32 Processor Architecture
CSC 221 Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Instruction set Architecture
Data Transfers, Addressing, and Arithmetic
Part of the Assembler Language Programmers Toolbox
Homework Reading Labs PAL, pp
Microprocessor and Assembly Language
Introduction to 8085 Instructions
Assembly IA-32.
Assembly Language Programming Part 2
Chapter 6 Floating Point
Computer Organization and Assembly Language (COAL)
Introduction to Assembly Language
Computer Organization and Assembly Language
Assembly Language for Intel-Based Computers, 5th Edition
Using the 80x87 Math Chip in Assembly
Introduction to Intel IA-32 and IA-64 Instruction Set Architectures
CS 301 Fall 2002 Computer Organization
Fundamentals of Computer Organisation & Architecture
Homework Reading Machine Projects Labs PAL, pp
The x87 FPU Lecture 18 Wed, Mar 23, 2005.
Introduction to Microprocessor Programming
X86 Assembly Review.
Review In last lecture, done with unsigned and signed number representation. Introduced how to represent real numbers in float format.
Computer Architecture and System Programming Laboratory
CSC 497/583 Advanced Topics in Computer Security
Chapter 8: Instruction Set 8086 CPU Architecture
Computer Organization and Assembly Language
Computer Operation 6/22/2019.
Computer Architecture and Assembly Language
Computer Organization
Computer Architecture and System Programming Laboratory
Computer Architecture and System Programming Laboratory
Chapter 10 Instruction Sets: Characteristics and Functions
Presentation transcript:

Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22 Real Arithmetic Computer Organization and Assembly Languages Yung-Yu Chuang 2005/12/22

Announcement Grade for homework #3 is online You are encouraged to work in pairs for your final project You will have to schedule a demo session with your TA for your final project The final project will be due on the week after final week

Binary real numbers Binary real to decimal real Decimal real to binary real 4.5625 = 100.10012

IEEE floating point format IEEE defines two formats with different precisions: single and double 23.85 = 10111.1101102=1.0111110110x24 e = 127+4=83h 0 100 0001 1 011 1110 1100 1100 1100 1100

IEEE floating point format IEEE double precision special values

Denormalized numbers Number smaller than 1.0x2-126 can’t be presented by a single with normalized form. However, we can represent it with denormalized format. 1.001x2-129=0.01001x2-127

IA-32 floating point architecture Original 8086 only has integers. It is possible to simulate real arithmetic using software, but it is slow. 8087 floating-point processor was sold separately at early time. Later, FPU (floating-point unit) was integrated into CPU.

FPU data types Three floating-point types

FPU data types Four integer types

Data registers Load: push, TOP-- Store: pop, TOP++ Instructions access the stack using ST(i) relative to TOP If TOP=0 and push, TOP wraps to R7 If TOP=7 and pop, result in an exception Floating-point values are transferred to and from memory and stored in 10-byte temporary format. When storing, convert back to integer, long, real, long real.

Special-purpose registers

Special-purpose registers Last data pointer stores the memory address of the operand for the last non-control instruction. Last instruction pointer stored the address of the last non-control instruction. Both are 48 bits, 32 for offset, 16 for segment selector. 1 1 0 1 1

Status register

Control register Initial 037Fh

Instruction format Begin with ‘F’. The second letter could be ‘B’ (binary-coded decimal), ‘I’ (binary integer) or none (real). Up to two operands, at least one of them is a floating-point register. Hence, no memory-memory operation. No immediate and CPU register operands.

Instruction format {…}: implied operands

Classic stack ST(0) as source, ST(1) as destination. Result is stored at ST(1) and ST(0) is popped, leaving the result on the top.

Real memory and integer memory ST(0) as the implied destination. The second operand is from memory.

Register and register pop Register: operands are FP data registers, one must be ST. Register pop: the same as register with a ST pop afterwards.

Example: evaluating an expression

Load FLDPI stores π FLDL2T stores log2(10) FLDL2E stores log2(e) FLDLG2 stores log10(2) FLDLN2 stores ln(2)

Store

Register

Addition

Addition

Subtraction

Example: array sum .data N = 20 array REAL8 N DUP(1.0) sum REAL8 0.0 .code mov ecx, N mov esi, OFFSET array fldz ; ST0 = 0 lp: fadd REAL8 PTR [esi] ; ST0 += *(esi) add esi, 8 ; move to next double loop lp fstp sum ; store result

Multiplication FMULP ST(1)=ST(0)*ST(1), pop ST(0)

Division

Comparisons

Comparisons The above instructions change FPU’s status register of FPU and the following instructions are used to transfer them to CPU. SAHF copies C0 into carry, C2 into parity and C3 to zero. Since the sign and overflow flags are not set, use conditional jumps for unsigned integers (ja, jae, jb, jbe, je, jz).

Comparisons

Example: comparison .data x REAL8 1.0 y REAL8 2.0 .code ; if (x>y) return 1 else return 0 fld x ; ST0 = x fcomp y ; compare ST0 and y fstsw ax ; move C bits into FLAGS sahf jna else_part ; if x not above y, ... then_part: mov eax, 1 jmp end_if else_part: mov eax, 0 end_if:

Pentium Pro new comparison Pentium Pro supports two new comparison instructions that directly modify CPU’s FLAGS. The format should be FCOMI ST(0), src FCOMIP ST(0), src

Example: max=max(x,y) .686 .data x REAL8 1.0 y REAL8 2.0 max REAL8 ? .code fld y fld x ; ST0=x, ST1=y fcomip st(0), st(1) jna y_bigger fcomp st(0) ; pop y from stack fld x ; ST0=x y_bigger: fstp max

Miscellaneous instructions .data x REAL4 2.75 five REAL4 5.2 .code fld five ; ST0=5.2 fld x ; ST0=2.75, ST1=5.2 fscale ; ST0=2.75*32=88 ; ST1=5.2

Example: quadratic formula

Example: quadratic formula

Example: quadratic formula