Arithmetic and Decisions

Slides:



Advertisements
Similar presentations
Part 4: combinational devices
Advertisements

Combinational Circuits
Combinational Circuits
Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
L10 – Transistors Logic Math 1 Comp 411 – Spring /22/07 Arithmetic Circuits Didn’t I learn how to do addition in the second grade?
Comparator.
Arithmetic Functions and Circuits
Cosc 2150: Computer Organization Chapter 3: Boolean Algebra and Digital Logic.
Kevin Walsh CS 3410, Spring 2010 Computer Science Cornell University Arithmetic See: P&H Chapter 3.1-3, C.5-6.
Computer Structure - The ALU Goal: Build an ALU  The Arithmetic Logic Unit or ALU is the device that performs arithmetic and logical operations in the.
Chapter 10-Arithmetic-logic units
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Lecture # 12 University of Tehran
CS231: Computer Architecture I Laxmikant Kale Fall 2004.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Today’s Topics How information.
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
CS1Q Computer Systems Lecture 9 Simon Gay. Lecture 9CS1Q Computer Systems - Simon Gay2 Addition We want to be able to do arithmetic on computers and therefore.
Chapter 6-1 ALU, Adder and Subtractor
Digital Electronics and Computer Interfacing
IT253: Computer Organization Lecture 7: Logic and Gates: Digital Design Tonga Institute of Higher Education.
CDA 3101 Fall 2013 Introduction to Computer Organization The Arithmetic Logic Unit (ALU) and MIPS ALU Support 20 September 2013.
EE2174: Digital Logic and Lab Professor Shiyan Hu Department of Electrical and Computer Engineering Michigan Technological University CHAPTER 8 Arithmetic.
COMP541 Arithmetic Circuits
N, Z, C, V in CPSR with Adder & Subtractor Prof. Taeweon Suh Computer Science Education Korea University.
Logic Gates Informatics INFO I101 February 3, 2003 John C. Paolillo, Instructor.
CS 1308 – Computer Literacy and the Internet Building the CPU.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
Arithmetic-logic units1 An arithmetic-logic unit, or ALU, performs many different arithmetic and logic operations. The ALU is the “heart” of a processor—you.
Addition and multiplication Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
Addition and multiplication1 Arithmetic is the most basic thing you can do with a computer, but it’s not as easy as you might expect! These next few lectures.
Combinational Circuits
ECE 3130 Digital Electronics and Design
ECE 3130 Digital Electronics and Design
Negative Numbers and Subtraction
Hexadecimal, Signed Numbers, and Arbitrariness
Bitfields and Logic Basics
Minimization and Sequential Logic
Addition and multiplication
Binary Addition and Subtraction
CS231: Computer Architecture I
Digital Systems Section 8 Multiplexers. Digital Systems Section 8 Multiplexers.
University of Gujrat Department of Computer Science
Basics Combinational Circuits Sequential Circuits Ahmad Jawdat
Addition, Signed Numbers, and Overflow
5. Combinational circuits
Subtraction The arithmetic we did so far was limited to unsigned (positive) integers. Today we’ll consider negative numbers and subtraction. The main problem.
Bitwise Operations and Bitfields
Week 7: Gates and Circuits: PART II
EE207: Digital Systems I, Semester I 2003/2004
Digital Logic.
Instructor: Alexander Stoytchev
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Homework Reading Machine Projects Labs
Unit 10 Arithmetic-logic Units
FSMs, Multiplication, and Division
COMS 361 Computer Organization
Instructor: Alexander Stoytchev
Addition and multiplication
CS231: Computer Architecture I
Instructor: Alexander Stoytchev
Addition and multiplication
ECE 352 Digital System Fundamentals
Combinational Circuits
ECE 352 Digital System Fundamentals
ECE 352 Digital System Fundamentals
Instructor: Alexander Stoytchev
CS231: Computer Architecture I
Digital Circuits and Logic
Number Representation
Instructor: Michael Greenbaum
Presentation transcript:

Arithmetic and Decisions CS/COE 0447 Jarrett Billingsley

Class announcements hooooooOO! CS447

Binary addition, in logic CS447

A B C S 1 1 1 1 1 1 1 The Tables of Truth let's try to come up with a truth table for adding two bits each column will hold 1 bit let's name the outputs C and S, for Carry and Sum let's name the inputs A and B A B C S now let's fill in the output values for the input values, we count up in binary 1 1 hey, this C column looks familiar… what about S? 1 1 1 1 1 great! But this is wrong. - whenever making a truth table, ALWAYS count up in binary – so easy to miss cases if you jump around - C and S form a 2-bit number - C just looks like A & B - S looks like A xor B CS447

00111 110 1011 0010 +0010 1111 1110 0001 Co Ci A B S Half-truth tables what we just made was a half-adder it has a carry output but not a carry input (which might be useful for the lowest bit) to make a full adder, we need 3 input bits Ci A B Co S 1 1 Co Ci 1 1 00111 110 1011 0010 +0010 1111 1110 0001 1 1 1 A 1 1 B 1 1 1 1 1 1 S 1 1 1 1 1 CS447

The logic of it all Ci A B Co S 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 it looks a little messy, but it kinda makes sense if you think of it like this: it counts how many input bits are "1" if we look at the outputs in isolation: S is 1 if we have an odd number of "1s" Co is 1 if we have 2 or 3 "1s" there's a full adder example circuit for you Ci A B Co S 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 - Again, Co and S are a 2-bit number - it might not be obvious, but we can come up with a collection of gates that output each of these columns 1 1 1 1 1 CS447

Sweeping that under the rug… in programming, we use functions to be able to reuse code in logic diagrams, we can group these 5 gates into a component here's the symbol for a one-bit full adder + B A Ci Co S outputs are like return values now we don't have to care how it adds, just that it does inputs are like parameters unfortunately Logisim flips this upside down but whatever. CS447

Making a component in Logisim we can use Project > Add Circuit… to make a new component then we can edit it by double-clicking it on the left this is like editing a function's code a component has pins: its inputs and outputs one of the labs will go into more detail on how to make components. now we can place multiple instances of the component on the main circuit, like making function calls. CS447

Adding longer numbers CS447

1 0 1 1 0 0 1 0 +0 0 1 0 1 1 1 1 Where do the carries go? when you add one place, you might get a carry out that becomes the carry in for the next higher place 1 0 1 1 0 0 1 0 +0 0 1 0 1 1 1 1 Bit Bucket..? - what is this called? - how can we handle it? CS447

+ + + + A2 A1 A0 B2 B1 B0 S2 S1 S0 Ripple Carry A2 S2 B2 A1 S1 B1 A0 if we want to add two three-bit numbers, we'll need three one-bit adders we chain the carries from each place to the next higher place, like we do on paper we have to split the numbers up like so: + B2 A2 S2 + B1 A1 S1 A2 A1 A0 B2 B1 B0 S2 S1 S0 + B0 A0 S0 + - it's called ripple carry because the carry "ripples" from the LSB to the MSB one place at a time CS447

Gate Delay electrical signals can't move infinitely fast transistors can't turn on and off infinitely fast since each digit must wait for the next smaller digit to compute its carry… ripple carry is linear in the number of digits this is a diagram of how the outputs of a 16-bit ripple carry adder change over time they added 0xFFFF + 1 it's measured in picoseconds! so ~100ps total but if we went to 32 bits, it'd take 200ps and 64 bits, 400ps... there are more efficient ways of adding details, schmetails - look-ahead carry is faster but requires O(n^2) space 300 400 CS447 (courtesy of Kate Temkin)

+ + Flip side A1 S1 ~B1 A0 S0 ~B0 1 remember how we do subtraction? x - y = x + (-y) negation means NOT and add 1 NOT uses… NOT gates how do we add 1 without any extra circuitry? we use a full adder for the LSB, and when we're subtracting, set the "carry in" to 1 now we're doing x + (~y) + 1 which is x + (-y) ! + ~B1 A1 S1 + ~B0 A0 S0 1 CS447

Detecting unsigned overflow in hardware how did we detect unsigned overflow? if the sum is smaller than either of the addends. but there's an easier way… if we add two n bit numbers, and get an n + 1 bit number, what will the last carry be? 1! so we can look at the MSB's carry-out. if it's 1, it's an overflow. 1 if overflow! + B2 A2 S2 + B1 A1 S1 + B0 A0 S0 CS447

Detecting signed overflow in hardware how did we detect signed overflow? same input signs; different output sign. that feels truth-table-y. SA SB So O 1 1 when the input signs differ, we can't have an overflow, so those rows are all 0. 1 1 1 when the input signs match, overflow happens when the output sign differs. 1 1 1 1 1 1 1 1 1 CS447

What makes a good word size? can you think of an example of… 100 of something? a million of something? a billion? a quintillion (1018)? more? 28 = 256, 216 ≅ 65,000, 232 ≅ 4 billion, 264 ≅ 18 quintillion for a given word size, all the circuitry has to be built to support it 64 1-bit adders 128 wires going in 64 wires coming out CS447

A new way of thinking about making decisions CS447

How you're used to doing it how do we make decisions in programming? with if-elses, conditional loops, switches… if(mode == 1) return A + B; else return A - B; if mode == 1, is the else clause run? No. when you make a decision in software, only one code path is run; the others never happen. CS447

How hardware does it sum = A + B; diff = A – B; if(mode == 1) instead of making the decision first and then doing one thing… hardware does all possible things, then decides which to use. sum = A + B; diff = A – B; if(mode == 1) return sum; else return diff; this seems wasteful, but: these two paths can be run at the same time! when you make a decision in hardware, you do all possible things, then pick only the thing you need, and ignore the rest. CS447

Hardware that makes decisions CS447

Y A B S Y A B S=0 A Y B S=1 Multiplexers a multiplexer (mux) outputs one of its inputs based on a select. Y A B S Y A B S=0 A Y B S=1 the unselected input is ignored! This is the select input. - muxes are universal too! you can build any logic gate – and therefore an entire computer – out of muxes CS447

Big muxes a mux can have any (power-of-2) number of inputs here's one with 4 inputs! to choose among 4 values… how big does the select signal have to be now? 2 bits. A 00 B 01 Y C 10 D 11 2 S CS447

Mux anti-patterns A 1 A 1 ~A A B just like with gates, there are some "pointless" ways to use muxes. A 1 A 1 ~A A B this is an overcomplicated wire. this is an overcomplicated NOT gate. the select signal should never be a constant. CS447

they are pretty much useless for this class. Demultipliexers a demultiplexer is the opposite of a multiplexer, but... In S In S=0 In S=1 they are pretty much useless for this class. - please don't use them. okay? okay. 95% of the times I've seen people using them, they're pointless. so avoid them. CS447

Implementing this if-else now we have enough information to do this: if(mode == 1) return A + B; else return A - B; A - B mode result else if + the select signal is basically the condition. we send the input values to all possible branches. CS447