Basic Arithmetic (adding and subtracting)

Slides:



Advertisements
Similar presentations
Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
Advertisements

EET 1131 Unit 7 Arithmetic Operations and Circuits
EE1A2 Microprocessor Systems & Digital Logic Part I Digital Electronic System Design Dr. T. Collins.
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:
Arithmetic Operations and Circuits
Parallel Adder Recap To add two n-bit numbers together, n full-adders should be cascaded. Each full-adder represents a column in the long addition. The.
Henry Hexmoor1 Chapter 5 Arithmetic Functions Arithmetic functions –Operate on binary vectors –Use the same subfunction in each bit position Can design.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
ECE C03 Lecture 61 Lecture 6 Arithmetic Logic Circuits Hai Zhou ECE 303 Advanced Digital Design Spring 2002.
Chapter # 5: Arithmetic Circuits Contemporary Logic Design Randy H
Lecture 8 Arithmetic Logic Circuits
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Design of Arithmetic Circuits – Adders, Subtractors, BCD adders
ECE 301 – Digital Electronics
Lecture 3. Boolean Algebra, Logic Gates
Chapter 7 Arithmetic Operations and Circuits Hexadecimal Arithmetic 4 binary bits represent a single hexadecimal digit Addition –Add the digits.
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.
Building Adders & Sub tractors Dr Ahmed Telba. Introducing adder circuits Adder circuits are essential inside microprocessors as part of the ALU, or arithmetic.
CS 105 Digital Logic Design
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
1 CHAPTER 4: PART I ARITHMETIC FOR COMPUTERS. 2 The MIPS ALU We’ll be working with the MIPS instruction set architecture –similar to other architectures.
Logic Design CS221 1 st Term combinational circuits Cairo University Faculty of Computers and Information.
Binary Numbers.
Binary Addition CSC 103 September 17, 2007.
1 Modified from  Modified from 1998 Morgan Kaufmann Publishers Chapter Three: Arithmetic for Computers citation and following credit line is included:
Digital Computer Concept and Practice Copyright ©2012 by Jaejin Lee Logic Circuits I.
Basic Arithmetic (adding and subtracting)
+ CS 325: CS Hardware and Software Organization and Architecture Combinational Circuits 1.
Digital Arithmetic and Arithmetic Circuits
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Chapter # 5: Arithmetic Circuits
Chapter 6-1 ALU, Adder and Subtractor
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
5-1 Programmable and Steering Logic Chapter # 5: Arithmetic Circuits.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
Numbers and Arithmetic Hakim Weatherspoon CS 3410, Spring 2013 Computer Science Cornell University See: P&H Chapter , 3.2, C.5 – C.6.
DIGITAL CIRCUITS David Kauchak CS52 – Fall 2015.
Digital Logic. 2 Abstractions in CS (gates) Basic Gate: Inverter IO IO GNDI O Vcc Resister (limits conductivity) Truth Table.
Logic and computers 2/6/12. Binary Arithmetic /6/ Only two digits: the bits 0 and 1 (Think: 0 = F, 1.
Kavita Bala CS 3410, Spring 2014 Computer Science Cornell University.
COMP541 Arithmetic Circuits
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.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
1 IKI20210 Pengantar Organisasi Komputer Kuliah No. 23: Aritmatika 18 Desember 2002 Bobby Nazief Johny Moningka
1. Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 2.
Logic Design CS221 1 st Term combinational circuits Cairo University Faculty of Computers and Information.
Addition, Subtraction, Logic Operations and ALU Design
Number Representation (Part 2) Computer Architecture (Fall 2006)
CPS120: Introduction to Computer Science Computer Math: Addition and Subtraction.
Lecture #23: Arithmetic Circuits-1 Arithmetic Circuits (Part I) Randy H. Katz University of California, Berkeley Fall 2005.
1 Ethics of Computing MONT 113G, Spring 2012 Session 4 Binary Addition.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
Simple ALU  Half adder  Full adder  Constructing 4 bits adder  ALU does several operations  General ALU structure  Timing diagram of adder  Overflow.
MicroProcessors Lec. 4 Dr. Tamer Samy Gaafar. Course Web Page —
EE204 L03-ALUHina Anwar Khan EE204 Computer Architecture Lecture 03- ALU.
President UniversityErwin SitompulDigital Systems 7/1 Lecture 7 Digital Systems Dr.-Ing. Erwin Sitompul President University
Computing Systems Lecture 3 Binary Representation & Boolean Logic Binary and Logic 1.
Electrical Engineering Engineering the Future Digital Circuits Fundamentals Hands-on Full-Adder Simulation (afternoon)
LOGIC CIRCUITLOGIC CIRCUIT. Goal To understand how digital a computer can work, at the lowest level. To understand what is possible and the limitations.
ETE 204 – Digital Electronics Combinational Logic Design Single-bit and Multiple-bit Adder Circuits [Lecture: 9] Instructor: Sajib Roy Lecturer, ETE,ULAB.
Arithmetic Circuits I. 2 Iterative Combinational Circuits Like a hierachy, except functional blocks per bit.
Addition and Subtraction
Combinational Circuits
Fundamentals & Ethics of Information Systems IS 201
King Fahd University of Petroleum and Minerals
Digital Logic.
COSC 2021: Computer Organization Instructor: Dr. Amir Asif
Digital Systems Section 12 Binary Adders. Digital Systems Section 12 Binary Adders.
Digital Logic.
Combinational Circuits
Presentation transcript:

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 1 out or ( ) A B A B 1 out A B A 1 A B out or ( ) A B A B 1 A B out

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

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

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

Unsigned Binary Arithmetic Binary Addition A B cout sum 1 Input Output A B S C 1 A B sum cout Half Adder

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 carry_out = a and b sum = a xor b

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   Input Output C A B S 1 Cin A B sum Cout

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)

Signed Binary Addition/Subtraction fundamental idea #1 finite width arithmetic - modulus rn, 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 24 = 16 0, 1, 2, ..., 15 then wrap around back to 0 thus an addition of rn to an n-digit finite width value has no effect on the n-digit value 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 (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)

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

Signed Binary Addition/Subtraction digit complement for n digits == (rn - 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 (2n - 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

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

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

Signed Binary Addition/Subtraction range for n-bit field: unsigned is [ 0, 2n - 1 ] 2's compl. signed is [ -2n-1, 2n-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 000 001 010 011 100 101 110 111 |------- |------- |------- |------- |------- |------- |-------| 0 1 2 3 4 5 6 7 100 101 110 111 000 001 010 011 -4 -3 -2 -1 0 +1 +2 +3 unsigned signed (2's compl) b2 b1 b0 sign b1 b0

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

Signed Binary Addition/Subtraction 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

Signed Binary Addition/Subtraction 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!

Signed Binary Addition/Subtraction 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 (+)  

Signed Binary Addition/Subtraction 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

Signed Binary Addition/Subtraction 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!

Signed Binary Addition/Subtraction 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!

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