CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.

Slides:



Advertisements
Similar presentations
ELEC353 S. al Zahir UBC Sign-Magnitude Representation High order bit is sign: 0 = positive (or zero), 1 = negative Low order bits represent the magnitude:
Advertisements

Computer Engineering (Logic Circuits) Dr. Tamer Samy Gaafar Lec. # 2
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Arithmetic See: P&H Chapter 3.1-3, C.5-6.
Arithmetic & Logic Unit Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point.
Chapter 6 Arithmetic. Addition Carry in Carry out
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Digital Arithmetic Wen-Hung Liao, Ph.D.. Objectives Perform binary addition, subtraction, multiplication, and division on two binary numbers. Add and.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
Prof. Hakim Weatherspoon CS 3410, Spring 2015 Computer Science Cornell University See: P&H Chapter 2.4, 3.2, B.2, B.5, B.6.
Number Systems Lecture 02.
Dr. Bernard Chen Ph.D. University of Central Arkansas
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Computer Organization and Architecture Computer Arithmetic Chapter 9.
Computer Arithmetic Nizamettin AYDIN
Computer Arithmetic. Instruction Formats Layout of bits in an instruction Includes opcode Includes (implicit or explicit) operand(s) Usually more than.
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Basic Arithmetic (adding and subtracting)
Computer Arithmetic.
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter 6-1 ALU, Adder and Subtractor
Introduction to Computer Engineering ECE/CS 252, Fall 2010 Prof. Mikko Lipasti Department of Electrical and Computer Engineering University of Wisconsin.
CH09 Computer Arithmetic  CPU combines of ALU and Control Unit, this chapter discusses ALU The Arithmetic and Logic Unit (ALU) Number Systems Integer.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
Basic Arithmetic (adding and subtracting)
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
ECE 456 Computer Architecture
Computer Organization Department of CSE, SSE Mukka Chapter 6 : ARITHMETIC | Website for students | VTU NOTES.
Computer Arithmetic See Stallings Chapter 9 Sep 10, 2009
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
COE 308: Computer Architecture (T032) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
Dr Mohamed Menacer College of Computer Science and Engineering Taibah University CE-321: Computer.
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
ECE DIGITAL LOGIC LECTURE 3: DIGITAL COMPUTER AND NUMBER SYSTEMS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2016, 01/19/2016.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Integer Operations Computer Organization and Assembly Language: Module 5.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
1 Digital Logic Design (41-135) Chapter 5 Number Representation & Arithmetic Circuits Younglok Kim Dept. of Electrical Engineering Sogang University Spring.
1 CE 454 Computer Architecture Lecture 4 Ahmed Ezzat The Digital Logic, Ch-3.1.
Chapter 9 Computer Arithmetic
William Stallings Computer Organization and Architecture 8th Edition
Cosc 2150: Computer Organization
Addition and Subtraction
CHAPTER 9 COMPUTER ARITHMETIC - ALU
William Stallings Computer Organization and Architecture 7th Edition
Computer Organization and ASSEMBLY LANGUAGE
ECEG-3202 Computer Architecture and Organization
Chapter 8 Computer Arithmetic
Presentation transcript:

CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering

Outline Integer Representation —Sign-Magnitude, Two’s Complement Integer Arithmetic —Negation, Addition, Subtraction —Multiplication, Division Floating-Point Representation Floating-Point Arithmetic

Arithmetic & Logic Unit (ALU) Does the calculations. Everything else in the computer is there to service this unit. Handles integers. Handles real (floating point) numbers.

ALU Inputs and Outputs Data Results e.g., overflow flag Operation & data in/out Registers Control unit Flags

Integer Representation General-case number: – Only have 0 & 1 to represent everything. — No minus sign. — No period (radix point). Positive integer numbers are stored in binary. — An 8-bit word can represent the numbers: — e.g., 41= Signed integer numbers — Sign-Magnitude — Two’s complement

Sign-Magnitude vs. 2’s Complement Decimal Representation Sign-Magnitude Representation 2’s Complement Representation (-A) 10  2 4 – A(-A) 10  A

Sign-Magnitude Representation Left most bit is sign bit. —0 means positive. —1 means negative. Example:  +18 =  –18 = Problems — Need to consider both sign and magnitude in arithmetic. — Two representations of zero (+0 and –0)  more difficult to test for 0.  one wasted bit combination!

Two’s Complement Representation Like sign-magnitude representation, leftmost bit is used as a sign bit. Differs from sign-magnitude representation in how the remaining bits are interpreted. Positive number: convert to binary Negative number: 2’s complement e.g., 8-bit 2’s complement representation +3 = = = = –1 = –2 = –3 =

n-bit Two’s Complement Representation Length of number (in bits) is first specified. Assume n-bit numbers. We have 2 n different combinations of size n bits  we can represent 2 n different numbers. Assign the value 0 to the combination 00…0. We have 2 n –1 different combinations left. Assign the values 1, 2, …, 2 n–1 –1 to 1, 2,.., 2 n–1 –1. Assign the values –2 n–1, –2 n–1 +1, …, –1 to 2 n–1, 2 n–1 +1, …, 2 n –1 Getting the 2’s comp. of A is equivalent to 2 n – A –2 n – 1 ≤ A ≤ 2 n – 1 – 1

Characteristics of 2’s Comp. Rep. & Arithmetic 1’s complement Consider n-bit 2’s complement representation Equivalent to: 2 n – A

Benefits One representation of zero. Arithmetic works easily (see later). Negating is fairly easy — 3 = — Boolean (one’s) complement gives — Add 1 to LSB — This is equivalent to 2 8 – 3 = 253 = ’s complement of 3

Conversion between 2’s Comp. & Decimal Value Box 0 +8 Result obtained using value box is correct because:  Sign bit is 1  Number = -(2’s comp. of ) = -( ) = -125

Conversion Between Lengths Positive numbers  pack with leading zeros  +18 =  +18 = Negative numbers  pack with leading ones  -18 =  -18 = i.e. pack with MSB (sign bit)  Sign extension

Addition and Subtraction Addition  Normal binary addition.  Monitor sign bit for overflow. Subtraction  Take two’s complement of subtrahend and add to minuend  A – B = A + (–B) So we only need addition and complement circuits.

Addition of Numbers in 2’s Comp. Rep. 4-bit 2’s comp. rep. 4-bit 2’s comp. representation

Binary Addition/Subtraction Logic Circuit. Addition  Add/sub control = 0. Subtraction  Add/sub control = 1

At the stage i: Input: x i is i th bit of x y i is i th bit of y c i is carry-in from stage i-1 Output: s i is the sum c i+1 carry-out to stage i+1 1-Bit Addition (Full Adder)

Full Adder (FA): Symbol for the complete circuit for a single stage of addition. Addition Logic for a Single Stage SumCarry

An n-bit Ripple-Carry Adder Cascade n full adder (FA) blocks to form a n-bit adder. Carries propagate or ripple through this cascade  n-bit ripple carry adder. Carry-in c 0 into the LSB position provides a convenient way to perform subtraction.

Cascade of k n-bit Adders k n-bit numbers can be added by cascading k n-bit adders. Each n-bit adder forms a block, so this is cascading of blocks. Carries ripple or propagate through blocks  Blocked Ripple Carry Adder.