1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:

Slides:



Advertisements
Similar presentations
1 CONSTRUCTING AN ARITHMETIC LOGIC UNIT CHAPTER 4: PART II.
Advertisements

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates Invitation to Computer Science, C++ Version, Third Edition.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Assembly Language and Computer Architecture Using C++ and Java
1  2004 Morgan Kaufmann Publishers Chapter Three.
Assembly Language and Computer Architecture Using C++ and Java
1 Chapter 4: Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture Assembly Language and.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Arithmetic I CPSC 321 Andreas Klappenecker. Administrative Issues Office hours of TA Praveen Bhojwani: M 1:00pm-3:00pm.
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
1  1998 Morgan Kaufmann Publishers Chapter Four Arithmetic for Computers.
Chapter 3 Arithmetic for Computers. Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's.
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
+ CS 325: CS Hardware and Software Organization and Architecture Exam 1: Study Guide.
Chapter 3 Digital Logic Structures. Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 3-2 Building Functions.
Dr. Bernard Chen Ph.D. University of Central Arkansas
ES 244: Digital Logic Design Chapter 1 Chapter 1: Introduction Uchechukwu Ofoegbu Temple University.
Computers Organization & Assembly Language
1 Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2)
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Basic Arithmetic (adding and subtracting)
1  2004 Morgan Kaufmann Publishers Instructions: bne $t4,$t5,Label Next instruction is at Label if $t4≠$t5 beq $t4,$t5,Label Next instruction is at Label.
EGRE 426 Fall 09 Chapter Three
IT253: Computer Organization
Computing Systems Basic arithmetic for computers.
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
Chapter 6-1 ALU, Adder and Subtractor
07/19/2005 Arithmetic / Logic Unit – ALU Design Presentation F CSE : Introduction to Computer Architecture Slides by Gojko Babić.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Basic Arithmetic (adding and subtracting)
1 EGRE 426 Fall 08 Chapter Three. 2 Arithmetic What's up ahead: –Implementing the Architecture 32 operation result a b ALU.
1  1998 Morgan Kaufmann Publishers Arithmetic Where we've been: –Performance (seconds, cycles, instructions) –Abstractions: Instruction Set Architecture.
1 Digital Design: Number Systems Credits : Slides adapted from: J.F. Wakerly, Digital Design, 4/e, Prentice Hall, 2006 C.H. Roth, Fundamentals of Logic.
Csci 136 Computer Architecture II – Constructing An Arithmetic Logic Unit Xiuzhen Cheng
Charles Kime & Thomas Kaminski © 2004 Pearson Education, Inc. Terms of Use (Hyperlinks are active in View Show mode) Terms of Use Logic and Computer Design.
Computing Systems Designing a basic ALU.
1 Lecture 6 BOOLEAN ALGEBRA and GATES Building a 32 bit processor PH 3: B.1-B.5.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
The Karnaugh Map.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
 Lecture 2 Processor Organization  Control needs to have the  Ability to fetch instructions from memory  Logic and means to control instruction sequencing.
Digital Logic Lecture 3 Binary Arithmetic By Zyad Dwekat The Hashemite University Computer Engineering Department.
MIPS ALU. Building from the adder to ALU ALU – Arithmetic Logic Unit, does the major calculations in the computer, including – Add – And – Or – Sub –
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers Section 2 citation and following credit line is.
1  2004 Morgan Kaufmann Publishers Performance is specific to a particular program/s –Total execution time is a consistent summary of performance For.
1 ELEN 033 Lecture 4 Chapter 4 of Text (COD2E) Chapters 3 and 4 of Goodman and Miller book.
1  2004 Morgan Kaufmann Publishers Lets Build a Processor Almost ready to move into chapter 5 and start building a processor First, let’s review Boolean.
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
순천향대학교 정보기술공학부 이 상 정 1 3. Arithmetic for Computers.
Prof. Hsien-Hsin Sean Lee
Lec 11Systems Architecture1 Systems Architecture Lecture 11: Arithmetic for Computers Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan Some or all.
LECTURE 4 Logic Design. LOGIC DESIGN We already know that the language of the machine is binary – that is, sequences of 1’s and 0’s. But why is this?
Computer Arthmetic Chapter Four P&H. Data Representation Why do we not encode numbers as strings of ASCII digits inside computers? What is overflow when.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
MIPS ALU. Exercise – Design a selector? I need a circuit that takes two input bits, a and b, and a selector bit s. The function is that if s=0, f=a. if.
9/23/2004Comp 120 Fall September Chapter 4 – Arithmetic and its implementation Assignments 5,6 and 7 posted to the class web page.
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
May 2, 2001System Architecture I1 Systems Architecture I (CS ) Lecture 11: Arithmetic for Computers * Jeremy R. Johnson May 2, 2001 *This lecture.
1 CPTR 220 Computer Organization Computer Architecture Assembly Programming.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Dr. ClincyLecture 2 Slide 1 CS Chapter 2 (1 of 5) Dr. Clincy Professor of CS Note: Do not study chapter 2’s appendix (the topics will be covered.
Based on slides from D. Patterson and www-inst.eecs.berkeley.edu/~cs152/ COM 249 – Computer Organization and Assembly Language Chapter 3 Arithmetic For.
1 (Based on text: David A. Patterson & John L. Hennessy, Computer Organization and Design: The Hardware/Software Interface, 3 rd Ed., Morgan Kaufmann,
Arithmetic Logical Unit
CS/COE0447 Computer Organization & Assembly Language
CS/COE0447 Computer Organization & Assembly Language
Presentation transcript:

1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included: 'Copyright 1998 Morgan Kaufmann Publishers.' Permission is granted to alter and distribute this material provided that the following credit line is included: 'Adapted from Computer Organization & Design, The hardware/Software Interface, Patterson and Hennesy, second edition, Copyright 1998 Morgan Kaufmann Publishers.' " This material may not be copied or distributed for commercial purposes without express written permission of the copyright holder.

2 Modified from  Modified from 1998 Morgan Kaufmann Publishers Computer Arithmetic Overall Outline The outline for the entire subject of Computer Arithmetic is given below. However, for the sake of readability, the subject is divided into logical sections that can be presented together. The outline for each section will indicate what is covered in that specific section. Introduction Numbers and their representation 2’s Complement Detecting Overflow Basic Review –Binary Conversion –Binary Arithmetic –Hex & Octal Numbers –Basic Boolean Algebra Design Process Design of a “Fast” ALU for MIPS ISA Faster Design, Carry-Look-Ahead Adder

3 Modified from  Modified from 1998 Morgan Kaufmann Publishers Computer Arithmetic Overall Outline continued Additional MIPS Requirements Elements of Design Process Summary of Design Process MIPS Arithmetic Instructions Multiplication methods Division Methods Floating Point Summary

4 Modified from  Modified from 1998 Morgan Kaufmann Publishers Computer Arithmetic Section1 Outline In this unit we will cover: Introduction Numbers and their representation 2’s Complement Detecting Overflow Basic Review –Binary Conversion –Binary Arithmetic –Hex & Octal Numbers –Basic Boolean Algebra

5 Modified from  Modified from 1998 Morgan Kaufmann Publishers Introduction So far we have seen an introduction of how we might map an assembly language, MIPS, to a machine language. We have studied what a machine instruction might look like, how many fields it may have, what and how many instruction formats might be designed, and have seen addressing techniques that might be designed and implemented from the various fields of the instruction formats.

6 Modified from  Modified from 1998 Morgan Kaufmann Publishers Introduction continued What we need to do now, is to learn the basics of how arithmetic operations are done in a simple computer. This will mostly correspond to the “execute” portion of the “fetch & execute” cycle. Once we know how to design arithmetic operations, we can investigate the processor design (Chapter 5) so that the entire fetch & execute cycle can be implemented.

7 Modified from  Modified from 1998 Morgan Kaufmann Publishers Motivation Lets ask some questions, some you already know the answer to, and some that you will learn here: How are negative numbers represented in the computer? What is the largest number that can be represented in a word (integer, real)? What (should) happen if an operation results in a number larger that can be represented in a computer? How do we do arithmetic (add, subtract, multiply, divide, etc) in a computer?

8 Modified from  Modified from 1998 Morgan Kaufmann Publishers In a computer, every thing is represented in terms of bits. Bits are just bits (no inherent meaning) — conventions define relationship between bits and numbers Binary numbers (base 2) 0000, 0001, 0010, 0011, 0100, 0101, 0110, 0111, 1000, Decimal values: 0,..., 2 n -1 Of course it gets more complicated: numbers are finite (overflow) fractions and real numbers negative numbers e.g., no MIPS subi instruction; addi can add a negative number) How do we represent negative numbers? i.e., which bit patterns will represent which numbers? Numbers

9 Modified from  Modified from 1998 Morgan Kaufmann Publishers Number System = 1× × × ×2 3 = A number in different systems: Binary: Octal: Hexadecimal: 5 B 6

10 Modified from  Modified from 1998 Morgan Kaufmann Publishers Number System You should be able to convert Binary  Hex Binary  Octal You should know about BCD 4 bits/decimal digits, 6 extra codes You should know about ASCII character encoding of binary numbers in 7 bits

11 Modified from  Modified from 1998 Morgan Kaufmann Publishers Negative Numbers Complement in fixed point representation in three forms: Assume 7bits/word Signed Magnitude: Signed 1’s complement: Signed2’s complement:

12 Modified from  Modified from 1998 Morgan Kaufmann Publishers Sign Magnitude: One's Complement Two's Complement 000 = = = = = = = = = = = = = = = = = = = = = = = = -1 Sign Magnitude: use 1 bit for sign, the rest for magnitude. One's Complement: negative number, x, (a 1 in most significant bit position) are represented as 2 n -x-1 Two's Complement: 2 n -x, so only one zero, (0× =0) Possible Representations

13 Modified from  Modified from 1998 Morgan Kaufmann Publishers Possible Representations Issues: –Which bit should be the sign bit? –Arithmetic is complex, one extra hardware step may be needed for correct sign of the result –Two zero representations! –balance, number of zeros, ease of operations Which one is best? Why? –Come up with a solution that would make the hardware simple. –Leading zeros means positive and leading ones means negative.

14 Modified from  Modified from 1998 Morgan Kaufmann Publishers 32 bit 2’s complement numbers: two = 0 ten two = + 1 ten two = + 2 ten two = + 2,147,483,646 ten two = + 2,147,483,647 ten two = – 2,147,483,648 ten two = – 2,147,483,647 ten two = – 2,147,483,646 ten two = – 3 ten two = – 2 ten two = – 1 ten One larger negative number than positive (minint) maxint minint MIPS

15 Modified from  Modified from 1998 Morgan Kaufmann Publishers Negating a two's complement number: invert all bits and add 1 –remember: “negate” and “invert” are quite different! Converting n bit numbers into numbers with more than n bits: –MIPS 16 bit immediate gets converted to 32 bits for arithmetic –copy the most significant bit (the sign bit) into the other bits > > –"sign extension" (lbu vs. lb) Two's Complement Operations

16 Modified from  Modified from 1998 Morgan Kaufmann Publishers Just like in grade school (carry/borrow 1s) Two's complement operations easy –subtraction using addition of negative numbers Overflow (result too large for finite computer word): –e.g., adding two n-bit numbers does not yield an n-bit number Addition & Subtraction

17 Modified from  Modified from 1998 Morgan Kaufmann Publishers Addition & Subtraction In 2’s complement, add two numbers including the sign bit, discard any carry out of the sign bit In 1’s complement, add two numbers including the sign bit, if carry out of sign bit increment result by one, and discard carry

18 Modified from  Modified from 1998 Morgan Kaufmann Publishers Addition & Subtraction In signed magnitude, we have to compare the signs and do the corresponding operation to determine the sign of the result. The other advantage to 2’s complement arithmetic is that there is only one zero representation: Signed magnitude:0, 000,0001, 000,000 1’s complement:0, 000,0001, 111,111 2’s complement: 0, 000,000 0, 000,000

19 Modified from  Modified from 1998 Morgan Kaufmann Publishers Overflow Lets consider 7 bits + 1 for sign and see when overflow occurs while doing 2’s complement arithmetic: Overflow if carry into the sign bit position is different from the carry out of the sign bit position! carry into sign bit 1 0 Carry out of sign bit Sign is negative

20 Modified from  Modified from 1998 Morgan Kaufmann Publishers Overflow In general if two n-digit numbers of the same sign are added to produce an n+1 digit number, overflow occurs. In sign magnitude, the overflow is detected from the carry out bit.

21 Modified from  Modified from 1998 Morgan Kaufmann Publishers No overflow when adding a positive and a negative number No overflow when signs are the same for subtraction Overflow occurs when the value affects the sign: –overflow when adding two positives yields a negative –or, adding two negatives gives a positive –or, subtract a negative from a positive and get a negative –or, subtract a positive from a negative and get a positive Consider the operations A + B, and A – B –Can overflow occur if B is 0 ? –Can overflow occur if A is 0 ? Detecting Overflow

22 Modified from  Modified from 1998 Morgan Kaufmann Publishers Binary Conversion (review) Problem 1:

23 Modified from  Modified from 1998 Morgan Kaufmann Publishers Binary Conversion (review) Problem 2:

24 Modified from  Modified from 1998 Morgan Kaufmann Publishers Binary Conversion Problem 2 (cont.):

25 Modified from  Modified from 1998 Morgan Kaufmann Publishers Binary Arithmetic (review)

26 Modified from  Modified from 1998 Morgan Kaufmann Publishers Binary Arithmetic (review) Overflow Detection with Two’s Complement: If the CarryIn of the MSB equals the CarryOut of the MSB, no overflow occurs. Otherwise overflow occurs.

27 Modified from  Modified from 1998 Morgan Kaufmann Publishers Hexadecimal (Base 16) Numbers (review)

28 Modified from  Modified from 1998 Morgan Kaufmann Publishers Octal (Base 8) Numbers (review)

29 Modified from  Modified from 1998 Morgan Kaufmann Publishers Logic Review Now a quick review of logic gates and Boolean algebra. You may refer to Appendix B of your textbook for detailed study.

30 Modified from  Modified from 1998 Morgan Kaufmann Publishers Common Logical Gates (review) Truth table

31 Modified from  Modified from 1998 Morgan Kaufmann Publishers Demorgan’s Law (review)

32 Modified from  Modified from 1998 Morgan Kaufmann Publishers Problem: Consider a logic function with three inputs: A, B, and C. Output D is true if at least one input is true Output E is true if exactly two inputs are true Output F is true only if all three inputs are true Show the truth table for these three functions. Review: Boolean Algebra & Gates (review)

33 Modified from  Modified from 1998 Morgan Kaufmann Publishers Show the Boolean equations for these three functions. Show an implementation for each OP equation consisting of inverters, AND, and OR gates. Note: –All equations can be put in Sum of Products (SOP) form. –In this class, answers should always be given in the simplest SOP form (unless otherwise stated). Boolean Algebra & Gates (review) (cont.)

34 Modified from  Modified from 1998 Morgan Kaufmann Publishers To obtain simplest Sum of Products (SOP) boolean equation, use a Karnaugh map or boolean algebra. Boolean Algebra & Gates (review) (cont.) C B A

35 Modified from  Modified from 1998 Morgan Kaufmann Publishers Boolean Algebra & Gates (review) (cont.)

36 Modified from  Modified from 1998 Morgan Kaufmann Publishers Design A One-bit Full Adder Lets build the truth table for inputs A, B, and carry-in C in, generating the outputs S and carry-out, C out : A B C in C Cout S C in AB S C in AB C out

37 Modified from  Modified from 1998 Morgan Kaufmann Publishers Design A One-bit Full Adder Therefore for S we have: S = A’BC’ + AB’C’ + A’B’C + ABC =(A’B + AB’)C’ + (A’B’ + AB)C =(A  B)C’ + (A  B)’C =A  B  C And for C out we have: C out =AB + BC + AC OR C ou =AB + A’BC + AB’C =AB + C(A’B + AB’) =AB + C( A  B) This is a combinational circuit in which the output is a function of present inputs C in AB