Basic Arithmetic (adding and subtracting)

Similar documents
LECTURE 4. Logic Design

To design a 4-bit ALU To experimentally check the operation of the ALU

Number System. Introduction. Decimal Numbers

Chapter 3 Arithmetic for Computers

Review. Steps to writing (stateless) circuits: Create a logic function (one per output)

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

Arithmetic Circuits. Nurul Hazlina Adder 2. Multiplier 3. Arithmetic Logic Unit (ALU) 4. HDL for Arithmetic Circuit

Chapter 3: part 3 Binary Subtraction

Binary Adders: Half Adders and Full Adders

Signed Binary Numbers

ECE468 Computer Organization & Architecture. The Design Process & ALU Design

Chapter 4 Arithmetic

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

Advanced Computer Architecture-CS501

Chapter 4. Combinational Logic

Chapter 4 Arithmetic Functions

EE292: Fundamentals of ECE

Experiment 7 Arithmetic Circuits Design and Implementation

CO Computer Architecture and Programming Languages CAPL. Lecture 9

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

ECE 30 Introduction to Computer Engineering

Chapter 2. Positional number systems. 2.1 Signed number representations Signed magnitude

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

CAD4 The ALU Fall 2009 Assignment. Description

ECE 341 Midterm Exam

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

Principles of Computer Architecture. Chapter 3: Arithmetic

CSE303 Logic Design II Laboratory 01

Combinational Logic II

THE LOGIC OF COMPOUND STATEMENTS

Number Systems and Computer Arithmetic

CPE 335 Computer Organization. MIPS Arithmetic Part I. Content from Chapter 3 and Appendix B

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

We are quite familiar with adding two numbers in decimal

Chapter 4. Operations on Data

Combinational Circuits

MIPS Integer ALU Requirements

Computer Architecture Set Four. Arithmetic

Week 7: Assignment Solutions

60-265: Winter ANSWERS Exercise 4 Combinational Circuit Design

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

Digital Logic Design Exercises. Assignment 1

1. Mark the correct statement(s)

Henry Lin, Department of Electrical and Computer Engineering, California State University, Bakersfield Lecture 7 (Digital Logic) July 24 th, 2012

Addition and multiplication

Le L c e t c ur u e e 2 To T p o i p c i s c t o o b e b e co c v o e v r e ed e Variables Operators

CMPE223/CMSE222 Digital Logic Design. Positional representation

1. NUMBER SYSTEMS USED IN COMPUTING: THE BINARY NUMBER SYSTEM

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

Code No: R Set No. 1

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

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

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Combinational Logic Use the Boolean Algebra and the minimization techniques to design useful circuits No feedback, no memory Just n inputs, m outputs

Arithmetic and Logical Operations

CS101 Lecture 04: Binary Arithmetic

CS/EE1012 INTRODUCTION TO COMPUTER ENGINEERING SPRING 2013 HOMEWORK I. Solve all homework and exam problems as shown in class and sample solutions

COMPUTER ARCHITECTURE AND ORGANIZATION Register Transfer and Micro-operations 1. Introduction A digital system is an interconnection of digital

637 has a 1 s place, 10 s place and 100 s place Show how to go from *256+7* =

Lecture 2: Number Systems

Chapter 1. Digital Systems and Binary Numbers

Part I: Translating & Starting a Program: Compiler, Linker, Assembler, Loader. Lecture 4

EE 109 Unit 6 Binary Arithmetic

Von Neumann Architecture

Digital Systems. John SUM Institute of Technology Management National Chung Hsing University Taichung, ROC. December 6, 2012

World Inside a Computer is Binary

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 3 DLD P VIDYA SAGAR

CS/COE 0447 Example Problems for Exam 2 Spring 2011

Binary Values. CSE 410 Lecture 02

ELEC 326: Class project

Chapter 3 Part 2 Combinational Logic Design

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


Arithmetic Logic Unit. Digital Computer Design

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

History of Computing. Ahmed Sallam 11/28/2014 1

Computer Organization

MC1601 Computer Organization

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

VTU NOTES QUESTION PAPERS NEWS RESULTS FORUMS Arithmetic (a) The four possible cases Carry (b) Truth table x y

UC Berkeley College of Engineering, EECS Department CS61C: Combinational Logic Blocks

UC Berkeley College of Engineering, EECS Department CS61C: Combinational Logic Blocks

ECE 331: N0. Professor Andrew Mason Michigan State University. Opening Remarks

Xuan Guo. Lecture XIV: Review of Chapter 3 & 4. CSC 3210 Computer Organization and Programming Georgia State University. March 5, 2015.

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

1 /10 2 /12 3 /16 4 /30 5 /12 6 /20

Binary. Hexadecimal BINARY CODED DECIMAL

CS 101: Computer Programming and Utilization

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

Chapter 3. ALU Design

COMPUTER ARCHITECTURE AND DIGITAL DESIGN

CS 64 Week 1 Lecture 1. Kyle Dewey

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

COMPUTER ORGANIZATION AND DESIGN. 5 th Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers Implementation

Injntu.com Injntu.com Injntu.com R16

Kinds Of Data CHAPTER 3 DATA REPRESENTATION. Numbers Are Different! Positional Number Systems. Text. Numbers. Other

CARLETON UNIVERSITY. Laboratory 2.0

that system. weighted value associated with it. numbers. a number. the absence of a signal. MECH 1500 Quiz 2 Review Name: Class: Date:

Integer Encoding and Manipulation

Lecture 21: Combinational Circuits. Integrated Circuits. Integrated Circuits, cont. Integrated Circuits Combinational Circuits

Transcription:

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

Digital Logic and (* or ^) A B A * B 0 0 0 0 1 0 1 0 0 1 1 1 A B out or ( ) A B A B 0 0 0 0 1 1 1 0 1 1 1 1 A B out

Digital Logic not (~,, ) A ~A 0 1 1 0 A out xor ( ) A B A B 0 0 0 0 1 1 1 0 1 1 1 0 A B out

Digital Logic nand A B A*B 0 0 1 0 1 1 1 0 1 1 1 0 A B out nor A B A nor B 0 0 1 0 1 0 1 0 0 1 1 0 A B out

Digital Logic Given the truth table: A B F A B A B A B A B 0 0 1 0 1 1 1 0 1 1 1 1 F = A B + A B + A B + A B Sum of products from the truth table. Often we can simplify.

Unsigned Binary Arithmetic The half adder is an example of a simple digital circuit built from two logic gates. half adder logic - two one-bit inputs (a, b) and two one-bit outputs (carry_out, sum) a 0 0 1 1 + b + 0 + 1 + 0 +1 carry_out sum 00 01 01 10

Unsigned Binary Arithmetic Binary Addition A B c out sum 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0 carry_out = a and b sum = a xor b A B Half Adder sum c out Input Output A B C out S 0 0 0 0 0 1 0 1 1 0 0 1 1 1 1 0

Unsigned Binary Arithmetic The problem with a half-adder is that it doesn't handle carries. Consider adding the following two numbers: 1 1 1 + 0 1 1 When we add the two numbers, we get 1 1 1 1 1 + 0 1 1 (1) 0 1 0 Look at the middle and leftmost columns. You add 3 bits. Half adders can only add two bits.

Unsigned Binary Arithmetic For adding multi-bit fields/words, e.g., 4 bits a 3 a 2 a 1 a 0 + b 3 b 2 b 1 b 0 --------------------------------------- sum 3 sum 2 sum 1 sum 0 we also need to add a carry_in with a i and b i, where i > 0

Unsigned Binary Arithmetic A full adder for a_i + b_i + carry_in is given in the figure below. three one-bit inputs (a, b, carry_in) and two one-bit outputs (carry_out, sum) cascade two half adders (sum output bit of first attached to one input line of the other) and then or together the carry_outs C in A B sum C out Input Output C in A B C out S 0 0 0 0 0 1 0 0 0 1 0 1 0 0 1 1 1 0 1 0 0 0 1 0 1 1 0 1 1 0 0 1 1 1 0 1 1 1 1 1

Full Adder An n-bit adder built by connecting n full adders carries propagate from right to left (i.e., connect the carry_out of an adder to the carry_in of the adder in the next leftmost bit position the initial, that is, rightmost, carry_in is zero) overflow occurs when a number is too large to represent. for unsigned arithmetic, overflow occurs when a carry out occurs from the most significant (i.e., leftmost) bit position

Full Adder (there are faster forms of addition hardware where the carries do not have to propagate from one side to the other, e.g., carry-lookahead adder)

fundamental idea #1 finite width arithmetic - modulus r n, where r is radix, n is number of digits wide - wraps around from biggest number to zero, ignoring overflow e.g., 4-bit arithmetic => modulus is 2 4 = 16 0, 1, 2,..., 15 then wrap around back to 0 thus an addition of r n to an n-digit finite width value has no effect on the n-digit value

fundamental idea #2 subtraction is equivalent to adding the negative of number e.g., a - b = a + (-b) observation a - b == a - b + r n == a + (r n - b) \ / \ / #1 #2 \ / this term is our representation for (-b) it turns out that we can more easily perform r n - b than a - b

digit complement for n digits == (r n - 1) - number in binary, this is called one's complement and equals a value of n ones minus the bits of the number for binary, one's complement (2 n - 1 - number) is equivalent to inverting each bit in decimal, this is called nine's complement and equals a value of n nines minus the digits of the number in hexadecimal, this is n f's (fifteens) minus the digits of the number

radix complement for n digits == (r n - 1) - number + 1 two's complement in binary ten's complement in decimal for binary, two's complement (2 n - 1 - number + 1) is equivalent to inverting each bit and adding one

We can easily make a full adder do subtraction by adding an inverter in front of each b i and setting carry into the rightmost adder to one

range for n-bit field: unsigned is [ 0, 2 n - 1 ] 2's compl. signed is [ -2 n-1, 2 n-1-1 ] signed overflow occurs whenever the sign bits of the two operands agree, but the sign bit of the result differs (i.e., add two positives and result appears negative, or add two negatives and result appears nonnegative) range diagrams for three bits unsigned 000 001 010 011 100 101 110 111 ------- ------- ------- ------- ------- ------- ------- 0 1 2 3 4 5 6 7 b 2 b 1 b 0 signed (2's compl) 100 101 110 111 000 001 010 011 ------- ------- ------- ------- ------- ------- ------- -4-3 -2-1 0 +1 +2 +3 sign b 1 b 0

modulo arithmetic (keep adding +1 and wrap around) 000 001 010 011 100 101 110 111 (unsigned) 0 1 2 3 4 5 6 7 (or 2's compl) 0 +1 +2 +3-4 -3-2 -1 ^^--carry occurs on wrap around

3-bit examples bits unsigned signed 111 = 7 = ( 1) +001 = +1 = +(+1) ----- --- ------- 000 0 (0) (carry) OVF ^^^-- this is what the ALU computes for either unsigned or signed. but, while it is an unsigned overflow, it is CORRECT for signed

3-bit examples Example 2 bits unsigned signed 011 3 = (+3) +001 = +1 = +(+1) ----- -- ----- 100 4 ( 4) OVF ^^^-- this is what the ALU computes for either unsigned or signed, but, while it is correct for unsigned, it is SIGNED OVERFLOW!

16-bit signed (2's complement) examples in 16-bit arithmetic, we can represent values as four hex digits; if the leading hex digit is between 0 and 7 (thus it has a leading bit of 0), it is a nonnegative value; if the leading hex digit is between 8 and f (thus it has a leading bit of 1), it is a negative value signed overflow occurs if a. (+) added with (+) gives a (-), or b. (-) added with (-) gives a (+)

hexadecimal hexadecimal decimal 0x7654 = 0x7654 = (+30292) +0xffed = +(-0x13) = +( 19) 0x7641 0x7641 (+30273) (carry) carry occurs but there is no signed overflow (thus carry is ignored) (+) added with (-) cancels out, so signed overflow is not possible

hex decimal 0x7654 = (+30292) +0x1abc = +( + 6844) ---------- ------------ 0x9110 (-28400) should be 37136, but is > max positive 32767 no carry occurs but there is signed overflow (+) added with (+) giving (-) => SIGNED OVERFLOW!

hex decimal 0x7654 = (+30292) +0x1abc = +( + 6844) 0x9110 (-28400) should be 37136, but is > max positive 32767 no carry occurs but there is signed overflow (+) added with (+) giving (-) => SIGNED OVERFLOW!

hexadecimal 0x7654 change subtraction to addition by ffff -0xff8d taking two's complement of 0xff8d -ff8d hexadecimal hexadecimal decimal 0x7654 = 0x7654 = (+30292) -0xff8d = +0x0073 = +( +115) 0x76c7 = (+30407) 0072 + 1 0073 no carry occurs and no signed overflow (+) added with (+) giving (+) => no signed overflow