Lecture 6: Signed Numbers & Arithmetic Circuits. BCD (Binary Coded Decimal) Points Addressed in this Lecture

Similar documents
Digital Logic Design (3)

Chapter 3: Arithmetic for Computers

ALU Design. 1-bit Full Adder 4-bit Arithmetic circuits. Arithmetic and Logic Unit Flags. Add/Subtract/Increament/Decrement Circuit

Fundamentals of Computer Systems

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

BINARY SYSTEM. Binary system is used in digital systems because it is:

Fundamentals of Computer Systems

Binary Adders: Half Adders and Full Adders

Number System. Introduction. Decimal Numbers

Logic Design (Part 2) Combinational Logic Circuits (Chapter 3)

Lecture 2: Number Systems

EE292: Fundamentals of ECE

Revision: August 31, E Main Suite D Pullman, WA (509) Voice and Fax

Basic Arithmetic (adding and subtracting)

World Inside a Computer is Binary

Chapter 3: part 3 Binary Subtraction

Real Digital Problem Set #6

Digital Logic Design Exercises. Assignment 1

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Chapter 4. Combinational Logic

ECE 2030D Computer Engineering Spring problems, 5 pages Exam Two 8 March 2012

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two Solutions 26 February 2014

Binary Arithmetic. Daniel Sanchez Computer Science & Artificial Intelligence Lab M.I.T.

Parallel logic circuits

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

Advanced Computer Architecture-CS501

Read-only memory Implementing logic with ROM Programmable logic devices Implementing logic with PLDs Static hazards

Microcomputers. Outline. Number Systems and Digital Logic Review

Digital Fundamentals. Lab 6 2 s Complement / Digital Calculator

CARLETON UNIVERSITY. Laboratory 2.0

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Combinational Circuits

Slide Set 1. for ENEL 339 Fall 2014 Lecture Section 02. Steve Norman, PhD, PEng

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-278: Digital Logic Design Fall Notes - Unit 4. hundreds.

Binary Multiplication

ELECTRICAL AND COMPUTER ENGINEERING DEPARTMENT, OAKLAND UNIVERSITY ECE-2700: Digital Logic Design Winter Notes - Unit 4. hundreds.

ECE 2030B 1:00pm Computer Engineering Spring problems, 5 pages Exam Two 10 March 2010

CHW 261: Logic Design

CS 31: Intro to Systems Digital Logic

EE 109 Unit 6 Binary Arithmetic

Experiment 7 Arithmetic Circuits Design and Implementation

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Boolean Unit (The obvious way)

ECE 2020B Fundamentals of Digital Design Spring problems, 6 pages Exam Two 26 February 2014

Department of Electrical and Computer Engineering University of Wisconsin - Madison. ECE/CS 352 Digital System Fundamentals.

Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Chapter 4 Arithmetic Functions

CS 64 Week 1 Lecture 1. Kyle Dewey

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

Chapter 10 Binary Arithmetics

Chapter 4: The Building Blocks: Binary Numbers, Boolean Logic, and Gates. Invitation to Computer Science, C++ Version, Third Edition

Number representations

CO Computer Architecture and Programming Languages CAPL. Lecture 9

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

Chapter 2 Bits, Data Types, and Operations

Digital Fundamentals

Introduction to Computers and Programming. Numeric Values

Octal and Hexadecimal Integers

CPS 104 Computer Organization and Programming

Rui Wang, Assistant professor Dept. of Information and Communication Tongji University.

CS 261 Fall Mike Lam, Professor Integer Encodings

1. Mark the correct statement(s)

Section 001. Read this before starting! You may use one sheet of scrap paper that you will turn in with your test.

Chapter 2 Bits, Data Types, and Operations

Arithmetic-logic units

Binary Values. CSE 410 Lecture 02

Representation of Non Negative Integers

Chapter 3 Arithmetic for Computers

Inf2C - Computer Systems Lecture 2 Data Representation

LECTURE 4. Logic Design

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

CMPE223/CMSE222 Digital Logic Design. Positional representation

CS 101: Computer Programming and Utilization

Computer Architecture and Organization

Combinational Logic Circuits

Chapter Three. Digital Components

Principles of Computer Architecture. Chapter 3: Arithmetic

Slide Set 1. for ENEL 353 Fall Steve Norman, PhD, PEng. Electrical & Computer Engineering Schulich School of Engineering University of Calgary


Positional notation Ch Conversions between Decimal and Binary. /continued. Binary to Decimal

Numbering systems. Dr Abu Arqoub

Data Representation COE 301. Computer Organization Prof. Muhamed Mudawar

Chapter 4. Operations on Data

NUMBER OPERATIONS. Mahdi Nazm Bojnordi. CS/ECE 3810: Computer Organization. Assistant Professor School of Computing University of Utah

CS101 Lecture 04: Binary Arithmetic

Chapter 2: Number Systems

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

Signed umbers. Sign/Magnitude otation

CSC 220: Computer Organization Unit 10 Arithmetic-logic units

Fundamentals of Programming Session 2

CS 5803 Introduction to High Performance Computer Architecture: Arithmetic Logic Unit. A.R. Hurson 323 CS Building, Missouri S&T

COMP 122/L Lecture 2. Kyle Dewey

Addition and multiplication

THE LOGIC OF COMPOUND STATEMENTS

T02 Tutorial Slides for Week 2

CS & IT Conversions. Magnitude 10,000 1,

D I G I T A L C I R C U I T S E E

Arithmetic Operations

Transcription:

Points ddressed in this Lecture Lecture 6: Signed Numbers rithmetic Circuits Professor Peter Cheung Department of EEE, Imperial College London (Floyd 2.5-2.7, 6.1-6.7) (Tocci 6.1-6.11, 9.1-9.2, 9.4) Representing signed numbers Two s complement Sign Extension ddition of signed numbers Multiplication by -1 Multiplication and division by integer powers of 2 dder subtractor circuits Comparators Decoders Encoders 6.1 6.2 inary Representations (Review) We have already seen how to represent numbers in binary Review (179) 10 is (10110011) 2 is (3) 16 is (263) 8 HEX: OCTL 1 0 1 1 3 1 0 1 1 0 0 0 1 1 0 1 1 CD (inary Coded Decimal) Each digit of a decimal number is coded using inary The 4 bit binary words are joined to make the full decimal number E.g. 987 in decimal 9 : 1001 8 : 1000 7 : 0111 So 987 in decimal becomes 1001 1000 0111 in CD 2 6 3 6.3 6.4

Summary Decimal inary HEX CD Octal 0 00000 0 0000 0000 0 1 00001 1 0000 0001 1 2 00010 2 0000 0010 2 3 00011 3 0000 0011 3 4 00100 4 0000 0100 4 5 00101 5 0000 0101 5 6 00110 6 0000 0110 6 7 00111 7 0000 0111 7 8 01000 8 0000 1000 10 9 01001 9 0000 1001 11 10 01010 0001 0000 12 11 01011 0001 0001 13 12 01100 C 0001 0010 14 13 01101 D 0001 0011 15 14 01110 E 0001 0100 16 15 01111 F 0001 0101 17 16 10000 10 0001 0110 20 Signed numbers asics So far, numbers are assumed to be unsigned (i.e. positive) How to represent signed numbers? Solution 1: Sign-magnitude - Use one bit to represent the sign, the remain bits to represent magnitude 0 = +ve 1 = -ve 7 s 6 magnitude 0 +27 = 0001 1011 b -27 = 1001 1011 b Problem: need to handle sign and magnitude separately. Solution 2: One s complement - If the number is negative, invert each bits in the magnitude +27 = 0001 1011 b -27 = 1110 0100 b Not convenient for arithmetic - add 27 to -27 results in 1111 1111 b Two zero values 6.5 6.6 Two s complement Solution 3: Two s complement - represent negative numbers by taking its magnitude, invert all bits and add one: Unsigned number Signed 2 s complement x= b Positive number +27 = 0001 1011 b Invert all bits 1110 0100 b dd 1-27 = 1110 0101 b 2 7-2 7 s 2 6 2 6 N 1 N 2 1 0 N 12 + bn 22 + + b1 2 + b0 2 2 0 2 0 Examples of 2 s Complement common method to represent -ve numbers: use half the possibilities for positive numbers and half for negative numbers to achieve this, let the MS have a negative weighting Construction of 2's Complement Numbers 4-bit example Decimal 2's Complement (Signed inary) -8 +4 +2 +1 5 0 1 0 1-5 1 0 1 1 7 0 1 1 1-3 1 1 0 1 6.7 6.8

Why 2 s complement representation? Comparison Table If we represent signed numbers in 2 s complement form, subtraction is the same as addition to negative (2 s complemented) number. 27 0001 1011 b - 17 0001 0001 b + 10 0000 1010 b +27 0001 1011 b + - 17 1110 1111 b +10 0000 1010 b Note that the range for 8-bit unsigned and signed numbers are different. 8-bit unsigned: 0 +255 8-bit 2 s complement signed number: -128 +127 Note the "wrap-around" effect of the binary representation i.e. The top of the table wraps around to the bottom of the table Unsigned inary 2 comp 7 0111 7 6 0110 6 5 0101 5 4 0100 4 3 0011 3 2 0010 2 1 0001 1 0 0000 0 15 1111-1 14 1110-2 13 1101-3 12 1100-4 11 1011-5 10 1010-6 9 1001-7 8 1000-8 6.9 6.10 Sign Extension Sign Extension How to translate an 8-bit 2 s complement number to a 16-bit 2 s complement number? This operation is known as sign extension. 6.11-2 7-215 duplicate sign bit s... s s 2 6 2 6 2 0 2 0 Sometimes we need to extend a number into more bits Decimal converting 12 into a 4 digit number gives 0012 we add 0's to the left-hand side Unsigned binary converting 0011 into an 8 bit number gives 00000011 we add 0's to the left-hand side For signed numbers we duplicate the sign bit (MS) Signed binary converting 0011 into 8 bits gives 00000011 (duplicate the 0 MS) converting 1011 into 8 bits gives 11111011 (duplicate the 1 MS) Called "Sign Extension" 6.12

Signed ddition The same hardware can be used for 2's complement signed numbers as for unsigned numbers this is the main advantage of 2's complement form Consider 4 bit numbers: the dder circuitry will "think" the negative numbers are 16 greater than they are in fact but if we take only the 4 LSs of the result (i.e. ignore the carry out of the MS) then the answer will be correct providing it is with the range: -8 to +7. To add 2 n-bit signed numbers without possibility of overflow we need to: sign extend to n+1 bits use an n+1 bit adder Multiplication of Signed Numbers by -1 Inverting all the bits of a 2's complement number X gives: -X-1 since adding it back onto X gives -1 E.g. 0101 5 X 1010-6 -X-1 1111-1 -1 Hence to multiply a signed number by -1: first invert all the bits then add 1 Exception: doesn't work for the maximum negative number e.g. doesn't work for -128 in a 8-bit system 6.13 6.14 Multiplication and Division by 2 N In decimal, multiplying by 10 can be achieved by shifting the number left by one digit adding a zero at the LS digit In binary, this operation multiplies by 2 In general, left shifting by N bits multiplies by 2 N zeros are always brought in from the right-hand end E.g. inary Decimal 1101 13 11010 26 110100 52 Right shifting by N bits divides by 2 N the bit which "falls off the end" is the remainder sign extension must be maintained for 2's complement numbers Decimal: (486) 10 divided by 10 gives 48 remainder 6 Unsigned: (110101) 2 divided by 2 gives 11010 remainder 1 (53) 10 (26) 10 (110101) 2 divided by 4 gives 1101 remainder 01 (53) 10 (13) 10 Signed 2's Complement: (110101) 2 divided by 2 gives 111010 remainder 1 (-11) 10 (-6) 10 (110101) 2 divided by 4 gives 111101 remainder 01 (-11) 10 (-3) 10 6.15 6.16

Summary of Signed and Unsigned Numbers Unsigned MS has a positive value (e.g. +8 for a 4-bit system) The carry-out from the MS of an adder can be used as an extra bit of the answer to avoid overflow To increase the number of bits, add zeros to the left-hand side Complementing and adding 1 converts X to (2N - X) Signed MS has a negative value (e.g. -8 for a 4-bit system) To avoid overflow in an adder, need to sign extend and use an adder with one more bit than the numbers to be added To increase the number of bits, sign extend by duplicating the MS Complementing and adding 1 converts X to -X inary ddition Recall the binary addition process 1 0 0 1 + 0 0 1 1 S 1 1 0 0 LS Column has 2 inputs 2 outputs Inputs: 0 0 Outputs: S 0 C 1 Other Columns have 3 inputs, 2 outputs Inputs: n n C n Outputs: S n C n+1 We use a "half adder" to implement the LS column We use a "full adder" to implement the other columns Each column feeds the next-most-significant column. 6.17 6.18 Half dder Full dder Truth Table oolean Equations S C 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1 S = + = C = Truth Table Ci S Co 0 0 0 0 0 0 0 1 1 0 0 1 0 1 0 0 1 1 0 1 1 0 0 1 0 1 0 1 0 1 1 1 0 0 1 1 1 1 1 1 Implementation Note also XOR implementation possible for S 1 S C oolean Equations S =.. Ci +.. Ci +.. Ci +.. Ci = Ci Co = Ci + Ci + Ci + Ci = + Ci + Ci = + Ci ( + ) 6.19 6.20

Complete circuitry for a F Implementation (using NND gates only) C i C out C i S C i C i C i C i 6.21 6.22 Full dder from Half dders Full dder from Half dders Truth Table H s H c C i S C o 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 0 0 1 1 0 1 0 1 1 0 1 0 0 1 0 1 0 1 0 1 0 1 1 1 0 1 0 0 1 1 1 0 1 1 1 1 6.24

Parallel dder Uses 1 full adder per bit of the numbers The carry is propagated from one stage to the next most significant stage takes some time to work because of the carry propagation delay which is n times the propagation delay of one stage. 4-bit Parallel inary dders 6.25 6.26 Parallel Subtraction using Parallel dder Subtraction can be achieve by adding the complement E.g.: 6-3 = 6 + (-3) = 3 2's complement :- invert all bits and then add 1 Use Carry-in of first stage for the "add 1" Invert all the inputs bits of 1-it Comparator Comparators The output is 1 when the inputs are equal n n 2 2 1 1 "1" 2-it Comparator Ci Ci Ci Co Σ Co Σ Co Σ S n+1 Sn S2 S1 The output is 1 when 0 = 0 ND 1 = 1 6.27 6.28

4-it Comparator Comparators One of three outputs will be HIGH: greater than ( > ) equal to ( = ) less than ( < ) inary decoder The output is 1 only when: 0 = 1 2 = 0 3 = 0 4 = 1 Decoders This is only one of an infinite number of examples 6.29 6.30 Decoders Decoders 4-bit decoder 4-bit decoder inary inputs ctive-low outputs Logic Diagram Truth Table 6.31 6.32

Decoders CD-to-decimal decoder CD-to-7 Segment Display Decoder LCD or LED displays can display digits made of up to 7 segments or lines Decode 4 bits CD into 7 control signals using a CD/7SEG decoder f e d g a c b 6.33 6.34 Decoders Decoders CD-to-7-segement decoder CD-to-7-segement decoder Logic Diagram Truth Table 6.35 6.36

Encoders Decimal-to-CD encoder 6.37