Registers and Binary Arithmetic Prof. Sirer CS 316 Cornell University.

Slides:



Advertisements
Similar presentations
Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Advertisements

Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
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:
COE 202: Digital Logic Design Signed Numbers
Arithmetic Hakim Weatherspoon CS 3410, Spring 2012 Computer Science Cornell University See P&H 2.4 (signed), 2.5, 2.6, C.6, and Appendix C.6.
Numbers & Arithmetic Hakim Weatherspoon CS 3410, Spring 2011 Computer Science Cornell University See: P&H Chapter , 3.2, C.5 – C.6.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Arithmetic See: P&H Chapter 3.1-3, C.5-6.
James Tam Numerical Representations On The Computer: Negative And Rational Numbers How are negative and rational numbers represented on the computer? How.
King Fahd University of Petroleum and Minerals
CS 151 Digital Systems Design Lecture 3 More Number Systems.
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Binary Arithmetic, Subtraction The rules for binary arithmetic are: = 0, carry = = 1, carry = = 1, carry = = 0, carry =
Number Representation (1) Fall 2005 Lecture 12: Number Representation Integers and Computer Arithmetic.
Complements: different approaches for representing negative numbers
ENGIN112 L3: More Number Systems September 8, 2003 ENGIN 112 Intro to Electrical and Computer Engineering Lecture 3 More Number Systems.
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
9/15/09 - L15 Decoders, Multiplexers Copyright Joanne DeGroat, ECE, OSU1 Binary additon & subtraction.
1 Binary Numbers Again Recall that N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to bits.
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 Computer Science 210 Computer Organization.
NEGATIVE BINARY NUMBER – Digital Circuit 1 Choopan Rattanapoka.
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Computer Systems 1 Fundamentals of Computing Negative Binary.
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
Representing Integer Data Book : Chapter ( Subject has no point !! ) A99ACF.
Basic Arithmetic (adding and subtracting)
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.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Basic Arithmetic (adding and subtracting)
46 Number Systems Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs Display: Seven segment displays Inputs: Switches.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
ECEN 248 Lab 4: Multiplexer Based Arithmetic Logic Unit
ECE2030 Introduction to Computer Engineering Lecture 2: Number System Prof. Hsien-Hsin Sean Lee School of Electrical and Computer Engineering Georgia Tech.
Numbers and Arithmetic Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See: P&H Chapter , 3.2, C.5 – C.6.
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.
Operations on Bits Arithmetic Operations Logic Operations
CS Data representation 1 Ch. 2.1 Data Representation Unsigned and Signed Integers – representation, addition, subtraction.
Sep 29, 2004Subtraction (lvk)1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers – If we can represent negative.
08 ARTH Page 1 ECEn/CS 224 Number Representation and Binary Arithmetic.
Data Representation in Computer Systems. 2 Signed Integer Representation The conversions we have so far presented have involved only positive numbers.
Topics covered: Arithmetic CSE243: Introduction to Computer Architecture and Hardware/Software Interface.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
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 –
69 Decimal (Base 10) Numbers n Positional system - each digit position has a value n 2534 = 2*1, * *10 + 4*1 n Alternate view: Digit position.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 23: Aritmatika 18 Desember 2002 Bobby Nazief Johny Moningka
Addition, Subtraction, Logic Operations and ALU Design
Numbers and Arithmetic Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See: P&H Chapter , 3.2, C.5 – C.6.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
Two’s and one’s complement arithmetic CLOCK ARITHMETIC.
In decimal we are quite familiar with placing a “-” sign in front of a number to denote that it is negative The same is true for binary numbers a computer.
ECEN 248: INTRODUCTION TO DIGITAL SYSTEMS DESIGN Lecture 8 Dr. Shi Dept. of Electrical and Computer Engineering.
Number Representation (Part 2) Computer Architecture (Fall 2006)
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
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.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
Memory and Repetitive Arithmetic Machines Prof. Sirer CS 316 Cornell University.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Lecture 4: Digital Systems & Binary Numbers (4)
Addition and Subtraction
Numbers and Arithmetic
Numbers and Arithmetic
Unit 18: Computational Thinking
How are negative and rational numbers represented on the computer?
Memory and Repetitive Arithmetic Machines
Presentation transcript:

Registers and Binary Arithmetic Prof. Sirer CS 316 Cornell University

Recap We can build combinatorial circuits Gates, Karnaugh maps, minimization We can build stateful circuits Record 1-bit values in latches and flip-flops Powerful combination We can build real, useful devices But we will often need to perform arithmetic

Binary Arithmetic Arithmetic works the same way regardless of base Add the digits in each position Propagate the carry Unsigned binary addition is pretty easy Combine two bits at a time Along with a carry

1-bit Adder A 0 B 0 C out R0R0 A0A0 B0B0 R0R Adds two 1-bit numbers, computes 1-bit result and carry out Useful for the rightmost binary digit, not much else

1-bit Adder with Carry A i B i C in C out RiRi C in AiAi BiBi C out RiRi Adds two 1-bit numbers, along with carry-in, computes 1-bit result and carry out Can be cascaded to add N-bit numbers

4-bit Adder A 0 B 0 R0R0 Adds two 4-bit numbers, along with carry-in, computes 4-bit result and overflow Overflow indicates that the result does not fit in 4 bits A 1 B 1 R1R1 A 2 B 2 R2R2 A 3 B 3 R3R3 Over flow 0

Arithmetic with Negative Numbers Negative numbers complicate arithmetic Recall that for addition and subtraction, the rules are: Both positive => add, result positive One +, one - => subtract small number from larger one Both negative => add, result negative We could represent sign with an explicit bit the “sign-magnitude form” But arithmetic would be much easier to perform in hardware if we did not have to examine the operands’ signs Two’s complement representation enables arithmetic to be performed without examining the operands

Two’s Complement Nonnegative numbers are represented as usual 0 = = = = 0111 To negate a number, flip all bits, add one -1: 1  0001  1110  : 3  0011  1100  : 7  0111  1000  : 0  0000  1111  0000 (this is good, -0 = +0)

Two’s Complement Addition Perform addition as usual, regardless of sign 1 = 0001, 3 = 0011, 7 = 0111, 0 = = 1111, -3 = 1101, -7 = 1001 Examples = = 0000 (0) = = 1100 (-4) = = 1100 (-4)

Two’s Complement Facts Negative numbers have a leading 1 Similar to signed magnitude form Largest negative=1000…0; positive=0111…1 N bits can be used to represent unsigned: the range 0..2 N -1 ex: 8 bits  two’s complement: the range –(2 N-1 ).. (2 N-1 )-1 ex: 8 bits  ( )..( )  Overflow carry into most significant bit (msb) != carry out of msb

Two’s Complement Adder A 0 B 0 R0R0 Let’s build a two’s complement adder Already built, just needed to modify overflow checking A 1 B 1 R1R1 A 2 B 2 R2R2 A 3 B 3 R3R3 over flow 0

Two’s Complement Subtraction Subtraction is simply addition, where one of the operands has been negated Negation is done by inverting all bits and adding one R0R0 R1R1 R2R2 R3R3 1 A0A0 B0B0 A1A1 B1B1 A2A2 B2B2 A3A3 B3B3

A Calculator User enters the numbers to be added or subtracted using toggle switches User selects ADD or SUBTRACT Muxes feed A and B, or A and –B, to the 8-bit adder The 8-bit decoder for the hex display is straightforward (but not shown in detail) 0101 adder mux reg led-dec add/sub select … … doit

Summary We can now perform arithmetic And build basic circuits that operate on numbers