1 Number Systems and Computer Arithmetic Counting to four billion two fingers at a time
2 What do all those bits mean now? bits ( ) instruction R-format I-format... integer data number text chars... floating point signed unsigned single precision double precision
3 Questions About Numbers How do you represent negative numbers? fractions? really large numbers? really small numbers? How do you do arithmetic? identify errors (e.g. overflow)? What is an ALU and what does it look like? ALU=arithmetic logic unit
4 Review: Binary Numbers Consider a 4-bit binary number Decimal Binary Decimal Binary Examples of binary arithmetic: = =
5 Negative Numbers? We would like a number system that provides obvious representation of 0,1,2... uses adder for addition single value of 0 equal coverage of positive and negative numbers easy detection of sign easy negation
6 Some Alternatives Sign Magnitude -- MSB is sign bit, rest the same -1 == == 1101 One s complement -- flip all bits to negate -1 == == 1010
7 Two s Complement Representation 2 s complement representation of negative numbers Take the bitwise inverse and add 1 Biggest 4-bit Binary Number: 7 Smallest 4-bit Binary Number: -8 Decimal Two s Complement Binary
8 Two s Complement Arithmetic Decimal 2 s Complement Binary Decimal s Complement Binary Examples: 7-6 = 7 + (- 6) = = 3 + (- 5) =
9 Some Things We Want To Know About Our Number System negation sign extension +3 => 0011, , => 1101, , overflow detection
10 Overflow Detection So how do we detect overflow?
11 Instruction Fetch Arithmetic -- The heart of instruction execution Instruction Decode Operand Fetch a operation Execute 32 ALU result Result Store b Next Instruction
12 Designing an Arithmetic Logic Unit ALUop 3 A N Zero B N ALU N CarryOut Result Overflow ALU Control Lines (ALUop) Function 000 And 001 Or 010 Add 110 Subtract 111 Set-on-less-than
13 A One Bit ALU This 1-bit ALU will perform AND, OR, and ADD
14 A 32-bit ALU 1-bit ALU 32-bit ALU
15 How About Subtraction? Keep in mind the following: (A - B) is the same as: A + (-B) 2 s Complement negate: Take the inverse of every bit and add 1 Bit-wise inverse of B is!b: A - B = A + (-B) = A + (!B + 1) = A +!B
16 Overflow Detection Logic Carry into MSB! = Carry out of MSB For a N-bit ALU: Overflow = CarryIn[N - 1] XOR CarryOut[N - 1] CarryIn0 A0 B0 A1 B1 A2 B2 A3 B3 1-bit ALU CarryOut0 CarryIn1 Result0 1-bit Result1 ALU CarryOut1 CarryIn2 CarryIn3 1-bit ALU 1-bit ALU CarryOut2 Result2 Result3 X Y X XOR Y Overflow CarryOut3
17 Zero Detection Logic Zero Detection Logic is just one BIG NOR gate Any non-zero input to the NOR gate will cause its output to be zero CarryIn0 A0 B0 A1 B1 A2 B2 A3 B3 CarryIn1 CarryIn2 CarryIn3 1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU CarryOut0 CarryOut1 CarryOut2 CarryOut3 Result0 Result1 Result2 Result3 Zero
18 Set-on-less-than Do a subtract use sign bit route to bit 0 of result all other bits zero
19 Full ALU give signals for: neg oper add? sub? and? or? beq? slt? sign bit (adder output from bit 31)
20 The Disadvantage of Ripple Carry The adder we just built is called a Ripple Carry Adder The carry bit may have to propagate from LSB to MSB Worst case delay for an N-bit RC adder: 2N-gate delay CarryIn0 A0 B0 A1 B1 A2 B2 A3 B3 CarryIn1 CarryIn2 CarryIn3 1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU CarryOut0 CarryOut1 CarryOut2 Result0 Result1 Result2 Result3 CarryIn A B CarryOut CarryOut3 Ripple carry adders are slow. Faster addition schemes are possible that accelerate the movement of the carry from one end to the other.
21 MULTIPLY Paper and pencil example: Multiplicand 1000 Multiplier x 1011 Product =? m bits x n bits = m+n bit product Binary makes it easy: 0 => place 0 ( 0 x multiplicand) 1 => place multiplicand ( 1 x multiplicand) we ll look at a couple of versions of multiplication hardware
23 Multiply Algorithm Version 1 Multiplier Multiplicand Product
24 Observations on Multiply Version 1 1 clock per cycle => 100 clocks per multiply Ratio of multiply to add 100:1 1/2 bits in multiplicand always 0 => 64-bit adder is wasted 0 s inserted in left of multiplicand as shifted => least significant bits of product never changed once formed Instead of shifting multiplicand to left, shift product to right? Wasted space (zeros) in product register exactly matches meaningful bits of multiplier at all times. Combine?
26 Observations on Multiply Version 2 2 steps per bit because Multiplier & Product combined 32-bit adder MIPS registers Hi and Lo are left and right half of Product Gives us MIPS instruction MultU What about signed multiplication? easiest solution is to make both positive & remember whether to complement product when done.
27 Divide: Paper & Pencil Quotient Divisor Dividend Remainder See how big a number can be subtracted, creating quotient bit on each step Binary => 1 * divisor or 0 * divisor Dividend = Quotient * Divisor + Remainder
29 Divide Algorithm Version 1 Takes n+1 steps for n-bit Quotient & Rem. Quotient Divisor Remainder Start 1. Subtract the Divisor register from the Remainder register, and place the result in the Remainder register. Remainder >= 0 Test Remainder Remainder < 0 2a. Shift the Quotient register to the left setting the new rightmost bit to 1. 2b. Restore the original value by adding the Divisor register to the Remainder register, and place the sum in the Remainder register. Also shift the Quotient register to the left, setting the new least significant bit to Shift the Divisor register right 1 bit. 33rd repetition? No: < 33 repetitions Done Yes: 33 repetitions
30 Divide Hardware Version 1 Again, 64-bit adder is unnecessary. Quotient grows as remainder shrinks
32 Observations on Divide Version 2 Same Hardware as Multiply: just need ALU to add or subtract, and 63-bit register to shift left or shift right Hi and Lo registers in MIPS combine to act as 64-bit register for multiply and divide Signed Divides: Simplest is to remember signs, make positive, and complement quotient and remainder if necessary Note: Dividend and Remainder must have same sign Note: Quotient negated if Divisor sign & Dividend sign disagree
33 Key Points Instruction Set drives the ALU design ALU performance, CPU clock speed driven by adder delay Multiplication and division take much longer than addition, requiring multiple addition steps.
34 So Far Can do logical, add, subtract, multiply, divide,... But... what about fractions? what about really large numbers?
35 Binary Fractions = 1x x x x2 0 so = 1x x x x x x2-3 e.g.,.75 = 3/4 = 3/2 2 = 1/2 + 1/4 =.11
36 Recall Scientific Notation decimal point exponent sign x x 10 Mantissa radix (base) Issues: Arithmetic (+, -, *, / ) Representation, Normal form Range and Precision Rounding Exceptions (e.g., divide by zero, overflow, underflow) Errors Properties ( negation, inversion, if A = B then A - B = 0 )
37 Floating-Point Numbers Representation of floating point numbers in IEEE 754 standard: single precision sign S E M exponent: excess 127 binary integer (actual exponent is e = E - 127) mantissa: sign + magnitude, normalized binary significand w/ hidden integer bit: 1.M N = (-1) S 2 E-127 (1.M) 0 < E < = = = X 2 0 = X 2 8 = = X 2 0 = X 2-3 = range of about 2 X to 2 X always normalized (so always leading 1, thus never shown) special representation of 0 (E = ) (why?) can do integer compare for greater-than, sign
38 What do you notice? * * * * Does this work with negative numbers, as well?
39 Double Precision Floating Point Representation of floating point numbers in IEEE 754 standard: double precision sign S E M 32 M actual exponent is e = E exponent: excess 1023 binary integer mantissa: sign + magnitude, normalized binary significand w/ hidden integer bit: 1.M N = (-1) S 2 E-1023 (1.M) 0 < E < (+1) bit mantissa range of about 2 X to 2 X
40 Floating Point Addition How do you add in scientific notation? x x 10 2 Basic Algorithm 1. Align 2. Add 3. Normalize 4. Round
41 FP Addition Hardware
42 Floating Point Multiplication How do you multiply in scientific notation? (9.9 x 10 4 )(5.2 x 10 2 ) = x 10 7 Basic Algorithm 1. Add exponents 2. Multiply 3. Normalize 4. Round 5. Set Sign
43 FP Accuracy Extremely important in scientific calculations Very tiny errors can accumulate over time IEEE 754 FP standard has four rounding modes always round up (toward + ) always round down (toward - ) truncate round to nearest => in case of tie, round to nearest even Requires extra bits in intermediate representations
44 Extra Bits for FP Accuracy Guard bits -- bits to the right of the least significant bit of the significand computed for use in normalization (could become significant at that point) and rounding. IEEE 754 has two extra bits and calls them guard and round.
45 When Keepin' it Real Goes Wrong Machine FP only approximates the real numbers Just calculating extra bits of precision is often enough but not always! knowing when, how to tell, and what to do about it can be subtle analysis involves algorithm, program implementation, and hardware "How JAVA's Floating-Point Hurts Everyone Everywhere" "Roundoff Degrades an Idealized Cantilever" (and lots more)
46 Key Points Floating Point extends the range of numbers that can be represented, at the expense of precision (accuracy). FP operations are very similar to integer, but with pre- and post-processing. Rounding implementation is critical to accuracy over time.
Tailoring the 32-Bit ALU to MIPS MIPS ALU extensions Overflow detection: Carry into MSB XOR Carry out of MSB Branch instructions Shift instructions Slt instruction Immediate instructions ALU performance
Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Instructor: Nicole Hynes firstname.lastname@example.org 1 Fixed Point Numbers Fixed point number: integer part
Floating Point Arithmetic CS 365 Floating-Point What can be represented in N bits? Unsigned 0 to 2 N 2s Complement -2 N-1 to 2 N-1-1 But, what about? very large numbers? 9,349,398,989,787,762,244,859,087,678
1 Floating Point The World is Not Just Integers Programming languages support numbers with fraction Called floating-point numbers Examples: 3.14159265 (π) 2.71828 (e) 0.000000001 or 1.0 10 9 (seconds in
0. Unit 0 Signed Representation Systems Binary Arithmetic 0.2 BINARY REPRESENTATION SYSTEMS REVIEW 0.3 Interpreting Binary Strings Given a string of s and 0 s, you need to know the representation system
Questions About Numbers Number Systems nd Arithmetic or Computers go to elementry school How do you represent negtive numbers? frctions? relly lrge numbers? relly smll numbers? How do you do rithmetic?
Computer Arithmetic Ch 8 ALU Integer Representation Integer Arithmetic Floating-Point Representation Floating-Point Arithmetic 1 Arithmetic Logical Unit (ALU) (2) Does all work in CPU (aritmeettis-looginen
CPS 104 Computer Organization and Programming Lecture 9: Integer Arithmetic. Robert Wagner CPS104 IMD.1 RW Fall 2000 Overview of Today s Lecture: Integer Multiplication and Division. Read Appendix B CPS104
182.092 Computer Architecture Chapter 3: Arithmetic for Computers Adapted from Computer Organization and Design, 4 th Edition, Patterson & Hennessy, 2008, Morgan Kaufmann Publishers and Mary Jane Irwin
Numeric Encodings Prof. James L. Frankel Harvard University Version of 10:19 PM 12-Sep-2017 Copyright 2017, 2016 James L. Frankel. All rights reserved. Representation of Positive & Negative Integral and
CS 320 Ch 10 Computer Arithmetic The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop. Signed integers are typically represented in sign-magnitude
Department of Electr rical Eng ineering, Chapter 3 Arithmetic for Computers (Part 2) 王振傑 (Chen-Chieh Wang) email@example.com ncku edu Depar rtment of Electr rical Eng ineering, Feng-Chia Unive
Arithmetic Logic Unit A.R. Hurson Department of Computer Science Missouri University of Science & Technology A.R. Hurson 1 Arithmetic Logic Unit It is a functional bo designed to perform "basic" arithmetic,
Chapter 3 Arithmetic for Computers 1 Arithmetic Where we've been: Abstractions: Instruction Set Architecture Assembly Language and Machine Language What's up ahead: Implementing the Architecture operation
N Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as: a n a a a The value of this number is given by: = a n Ka a a a a a
Signed umbers So far we have discussed unsigned number representations. In particular, we have looked at the binary number system and shorthand methods in representing binary codes. With m binary digits,
Chapter 03: Computer Arithmetic Lesson 09: Arithmetic using floating point numbers Objective To understand arithmetic operations in case of floating point numbers 2 Multiplication of Floating Point Numbers
CS/COE 0447 Example Problems for Exam 2 Spring 2011 1) Show the steps to multiply the 4-bit numbers 3 and 5 with the fast shift-add multipler. Use the table below. List the multiplicand (M) and product
Arithmetic and Logical Operations 2 CMPE2c x +y + sum Or in tabular form Binary Addition Carry Out Sum B A Carry In Binary Addition And as a full adder a b co ci sum 4-bit Ripple-Carry adder: Carry values
D I G I T A L C I R C U I T S E E Digital Circuits Basic Scope and Introduction This book covers theory solved examples and previous year gate question for following topics: Number system, Boolean algebra,
1 EE 109 Unit 19 IEEE 754 Floating Point Representation Floating Point Arithmetic 2 Floating Point Used to represent very small numbers (fractions) and very large numbers Avogadro s Number: +6.0247 * 10
CO20-320241 Computer Architecture and Programming Languages CAPL Lecture 15 Dr. Kinga Lipskoch Fall 2017 How to Compute a Binary Float Decimal fraction: 8.703125 Integral part: 8 1000 Fraction part: 0.703125
UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS (09 periods) Computer Arithmetic: Data Representation, Fixed Point Representation, Floating Point Representation, Addition and
Data Representation At its most basic level, all digital information must reduce to 0s and 1s, which can be discussed as binary, octal, or hex data. There s no practical limit on how it can be interpreted
Inf2C - Computer Systems Lecture 2 Data Representation Boris Grot School of Informatics University of Edinburgh Last lecture Moore s law Types of computer systems Computer components Computer system stack
Floating Point Numbers Lecture 9 CAP 3103 06-16-2014 Review of Numbers Computers are made to deal with numbers What can we represent in N bits? 2 N things, and no more! They could be Unsigned integers:
Arithmetic for Computers Hwansoo Han Arithmetic for Computers Operations on integers Addition and subtraction Multiplication and division Dealing with overflow Floating-point real numbers Representation
Floating point Today! IEEE Floating Point Standard! Rounding! Floating Point Operations! Mathematical properties Next time! The machine model Chris Riesbeck, Fall 2011 Checkpoint IEEE Floating point Floating
Floating-point Arithmetic Reading: pp. 312-328 Floating-Point Representation Non-scientific floating point numbers: A non-integer can be represented as: 2 4 2 3 2 2 2 1 2 0.2-1 2-2 2-3 2-4 where you sum
Chapter 4 Section 2 Operations on Decimals Addition and subtraction of decimals To add decimals, write the numbers so that the decimal points are on a vertical line. Add as you would with whole numbers.
Contents Number systems and conversion Binary arithmetic Representation of negative numbers Addition of two s complement numbers Addition of one s complement numbers Binary s Readings Unit.~. UNIT NUMBER
CS 101: Computer Programming and Utilization Jul-Nov 2017 Umesh Bellur (firstname.lastname@example.org) Lecture 3: Number Representa.ons Representing Numbers Digital Circuits can store and manipulate 0 s and 1 s.
IT 1204 Section 2.0 Data Representation and Arithmetic 2009, University of Colombo School of Computing 1 What is Analog and Digital The interpretation of an analog signal would correspond to a signal whose
3-1 Chapter 3 - Arithmetic Computer Architecture and Organization Miles Murdocca and Vincent Heuring Chapter 3 Arithmetic 3-2 Chapter 3 - Arithmetic Chapter Contents 3.1 Fixed Point Addition and Subtraction
Chapter 4: Data Representations Integer Representations o unsigned o sign-magnitude o one's complement o two's complement o bias o comparison o sign extension o overflow Character Representations Floating
Chapter 2 Data Representation in Computer Systems Chapter 2 Objectives Understand the fundamentals of numerical data representation and manipulation in digital computers. Master the skill of converting
Floating Point Arithmetic Clark N. Taylor Department of Electrical and Computer Engineering Brigham Young University email@example.com 1 Introduction Numerical operations are something at which digital
9 Multiplication and Division Multiplication is done by doing shifts and additions. Multiplying two (unsigned) numbers of n bits each results in a product of 2n bits. Example: 0110 x 0011 (6x3) At start,
CS429: Computer Organization and Architecture Dr. Bill Young Department of Computer Sciences University of Texas at Austin Last updated: September 18, 2017 at 12:48 CS429 Slideset 4: 1 Topics of this Slideset
Floating point Today IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Next time The machine model Fabián E. Bustamante, Spring 2010 IEEE Floating point Floating point
Chapter 2 Float Point Arithmetic Topics IEEE Floating Point Standard Fractional Binary Numbers Rounding Floating Point Operations Mathematical properties Real Numbers in Decimal Notation Representation
CS101 Lecture 04: Binary Arithmetic Binary Number Addition Two s complement encoding Briefly: real number representation Aaron Stevens (firstname.lastname@example.org) 25 January 2013 What You ll Learn Today Counting in binary
Binary Adders: Half Adders and Full Adders In this set of slides, we present the two basic types of adders: 1. Half adders, and 2. Full adders. Each type of adder functions to add two binary bits. In order
Systems I Floating Point Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties IEEE Floating Point IEEE Standard 754 Established in 1985 as uniform standard for
1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM 1.1 Introduction Given that digital logic and memory devices are based on two electrical states (on and off), it is natural to use a number
Data Representations & Arithmetic Operations Hiroaki Kobayashi 7/13/2011 7/13/2011 Computer Science 1 Agenda Translation between binary numbers and decimal numbers Data Representations for Integers Negative
4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.
class04.ppt 15-213 The course that gives CMU its Zip! Topics Floating Point Jan 22, 2004 IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Floating Point Puzzles For
EE 109 Unit 6 Binary Arithmetic 1 2 Semester Transition Point At this point we are going to start to transition in our class to look more at the hardware organization and the low-level software that is
Floating Point Numbers Summer 8 Fractional numbers Fractional numbers fixed point Floating point numbers the IEEE 7 floating point standard Floating point operations Rounding modes CMPE Summer 8 Slides
Basic Arithmetic (adding and subtracting) Digital logic to show add/subtract Boolean algebra abstraction of physical, analog circuit behavior 1 0 CPU components ALU logic circuits logic gates transistors
Review from last time CS152 Computer Architecture and Engineering Lecture 6 Verilog (finish) Multiply, Divide, Shift February 11, 2004 John Kubiatowicz (www.cs.berkeley.edu/~kubitron) lecture slides: http://www-inst.eecs.berkeley.edu/~cs152/
System Programming CISC 360 Floating Point September 16, 2008 Topics IEEE Floating Point Standard Rounding Floating Point Operations Mathematical properties Powerpoint Lecture Notes for Computer Systems:
C NUMERIC FORMATS Figure C-. Table C-. Listing C-. Overview The DSP supports the 32-bit single-precision floating-point data format defined in the IEEE Standard 754/854. In addition, the DSP supports an
ECE257 Numerical Methods and Scientific Computing Error Analysis Today s s class: Introduction to error analysis Approximations Round-Off Errors Introduction Error is the difference between the exact solution
EC2303-COMPUTER ARCHITECTURE AND ORGANIZATION QUESTION BANK UNIT-II 1. What are the disadvantages in using a ripple carry adder? (NOV/DEC 2006) The main disadvantage using ripple carry adder is time delay.
Floating Point Representation in Computers Floating Point Numbers - What are they? Floating Point Representation Floating Point Operations Where Things can go wrong What are Floating Point Numbers? Any
4 Operations On Data 4.1 Foundations of Computer Science Cengage Learning Objectives After studying this chapter, the student should be able to: List the three categories of operations performed on data.
CSCE 230J Computer Organization Floating Point Dr. Steve Goddard email@example.com http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for this lecture are based
CS31 Introduction to Numerical Methods Lecture 1 Number Representations and Errors Professor Jun Zhang Department of Computer Science University of Kentucky Lexington, KY 40506 0633 August 5, 017 Number
CS 265 Computer Architecture Wei Lu, Ph.D., P.Eng. 1 Part 1: Data Representation Our goal: revisit and re-establish fundamental of mathematics for the computer architecture course Overview: what are bits
IEEE 754 Standard - Overview Frozen Content Modified by on 13-Sep-2017 Before discussing the actual WB_FPU - Wishbone Floating Point Unit peripheral in detail, it is worth spending some time to look at
Characters, Strings, and Floats CS 350: Computer Organization & Assembler Language Programming 9/6: pp.8,9; 9/28: Activity Q.6 A. Why? We need to represent textual characters in addition to numbers. Floating-point
Signed Binary Numbers Unsigned Binary Numbers We write numbers with as many digits as we need: 0, 99, 65536, 15000, 1979, However, memory locations and CPU registers always hold a constant, fixed number
Computer Science 52 Logic, Words, and Integers 1 Words and Data The basic unit of information in a computer is the bit; it is simply a quantity that takes one of two values, 0 or 1. A sequence of k bits
Binary Addition & Subtraction Unsigned and Sign & Magnitude numbers Addition and subtraction of unsigned or sign & magnitude binary numbers by hand proceeds exactly as with decimal numbers. (In fact this
Lecture 14: Recap Today s topics: Recap for mid-term No electronic devices in midterm 1 Modern Trends Historical contributions to performance: Better processes (faster devices) ~20% Better circuits/pipelines
An Efficient Implementation of Double Precision Floating Point Multiplier Using Booth Algorithm Pallavi Ramteke 1, Dr. N. N. Mhala 2, Prof. P. R. Lakhe M.Tech [IV Sem], Dept. of Comm. Engg., S.D.C.E, [Selukate],
Floating Point Arithmetic Jinkyu Jeong (firstname.lastname@example.org) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu EEE3050: Theory on Computer Architectures, Spring 2017, Jinkyu Jeong (email@example.com)
IEEE Standard for Floating-Point Arithmetic: 754 G.E. Antoniou G.E. Antoniou () IEEE Standard for Floating-Point Arithmetic: 754 1 / 34 Floating Point Standard: IEEE 754 1985/2008 Established in 1985 (2008)
Data Representation Floating Point CSCI 2400 / ECE 3217: Computer Architecture Instructor: David Ferry Slides adapted from Bryant & O Hallaron s slides via Jason Fritts Today: Floating Point Background:
On a 64-bit CPU. Size/Range vary by CPU model and Word size. unsigned short x; //range 0 to 65553 signed short x; //range ± 32767 short x; //assumed signed There are (usually) no unsigned floats or doubles.
Up next Midterm Next Friday in class Exams page on web site has info + practice problems Excited for you to rock the exams like you have been the assignments! Today s lecture Back to numbers, bits, data
A Computer Arithmetic by David Goldberg (Xerox Palo Alto Research Center) The Fast drives out the Slow even if the Fast is wrong. W. Kahan A.1 Introduction A-1 A.2 Basic Techniques of Integer Arithmetic
Architecture and Design of Generic IEEE-754 Based Floating Point Adder, Subtractor and Multiplier Sahdev D. Kanjariya VLSI & Embedded Systems Design Gujarat Technological University PG School Ahmedabad,