Arithmetic Operations

Slides:



Advertisements
Similar presentations
ECE2030 Introduction to Computer Engineering Lecture 13: Building Blocks for Combinational Logic (4) Shifters, Multipliers Prof. Hsien-Hsin Sean Lee School.
Advertisements

©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
Binary Addition Rules Adding Binary Numbers = = 1
Assembly Language and Computer Architecture Using C++ and Java
Fixed-Point Arithmetics: Part I
Chapter 5 Arithmetic and Logical Operations. x y+0001 sum 0100 Or in tabular form… Carry in a b sum carry out
Chapter 4 Operations on Bits
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
Arithmetic and Logical Operations
Data Representation. CMPE12cGabriel Hugh Elkaim 2 Data Representation Goal: Store numbers, characters, sets, database records in the computer. What we.
Overview Iterative combinational circuits Binary adders
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Computer ArchitectureFall 2007 © August 29, 2007 Karem Sakallah CS 447 – Computer Architecture.
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.
Mantıksal Tasarım – BBM231 M. Önder Efe
Operations on data CHAPTER 4.
4 Operations On Data Foundations of Computer Science ã Cengage Learning.
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
Arithmetic for Computers
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
1 Arithmetic and Logical Operations - Part II. Unsigned Numbers Addition in unsigned numbers is the same regardless of the base. Given a pair of bit sequences.
Data Representation – Binary Numbers
Computer Arithmetic Nizamettin AYDIN
Computer Architecture Lecture 3: Logical circuits, computer arithmetics Piotr Bilski.
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
CMPE 325 Computer Architecture II Cem Ergün Eastern Mediterranean University Integer Representation and the ALU.
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Logic and Digital System Design - CS 303
1 Homework Turn in HW2 tonight HW3 is on-line already Questions?
Chapter 4 – Arithmetic Functions and HDLs Logic and Computer Design Fundamentals.
Charles Kime & Thomas Kaminski © 2008 Pearson Education, Inc. (Hyperlinks are active in View Show mode) Chapter 4 – Arithmetic Functions Logic and Computer.
Topic: Arithmetic Circuits Course: Digital Systems Slide no. 1 Chapter # 5: Arithmetic Circuits.
Oct. 18, 2007SYSC 2001* - Fall SYSC2001-Ch9.ppt1 See Stallings Chapter 9 Computer Arithmetic.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
BR 8/99 Binary Numbers Again Recall than N binary digits (N bits) can represent unsigned integers from 0 to 2 N bits = 0 to 15 8 bits = 0 to 255.
Positional Number Systems
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.
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
©Brooks/Cole, 2003 Chapter 4 Operations on Bits. ©Brooks/Cole, 2003 Apply arithmetic operations on bits when the integer is represented in two’s complement.
1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.
IT253: Computer Organization
Digital Representations ME 4611 Binary Representation Only two states (0 and 1) Easy to implement electronically %0= (0) 10 %1= (1) 10 %10= (2) 10 %11=
Bits, Data types, and Operations: Chapter 2 COMP 2610 Dr. James Money COMP
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.
Data Representation. Goal: Store numbers, characters, sets, database records in the computer. What we got: Circuit that stores 2 voltages, one for logic.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
Negative binary numbers 1 Computer Architectures M.
Integers’ Representation. Binary Addition. Two's Complement. Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers.
Integer Operations Computer Organization and Assembly Language: Module 5.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
BINARY SYSTEMS ENGR. KASHIF SHAHZAD 1. BINARY NUMBERS 1/2 Internally, information in digital systems is of binary form groups of bits (i.e. binary numbers)
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Chapter 4 Operations on Bits.
Integers’ Representation. Binary Addition. Two's Complement.
Chapter 14 Bitwise Operators Objectives
Computer Organization and Design
Overview Part 1 – Design Procedure Part 2 – Combinational Logic
COMS 361 Computer Organization
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Bit Manipulations CS212.
Presentation transcript:

Arithmetic Operations addition subtraction multiplication division Each of these operations on the integer representations: unsigned two's complement

Addition One bit of binary addition carry in a carry out + b sum bit

Addition Truth Table Carry In a b Carry Out Sum Bit 1

Addition Unsigned and 2's complement use the same addition algorithm Due to the fixed precision, throw away the carry out from the msb 00010111 + 10010010

Two’s Complement Addition 1 ( ) +  

Overflow The condition in which the result of an arithmetic operation cannot fit into the fixed number of bits available. For example: +8 cannot fit into a 3-bit, unsigned representation. It needs 4 bits: 1000

Overflow Detection Most architectures have hardware that detects when overflow has occurred (for arithmetic operations). The detection algorithms are simple.

Unsigned Overflow Detection 6-bit examples: 1 +   I wasn’t sure if you wanted to have the answers in this one or not, so slides 8 and 9 are the same one shown differently. - Jean Carry out from msbs is overflow in unsigned

Unsigned Overflow Detection 6-bit examples: 1 + No Overflow Overflow! I wasn’t sure if you wanted to have the answers in this one or not, so slides 8 and 9 are the same one shown differently. - Jean Overflow! Carry out from msbs is overflow in unsigned

Two’s Complement Overflow Detection When adding 2 numbers of like sign + to + - to – and the sign of the result is different! + - Overflow! Overflow!

Addition ( ) ( ) 100000 111111 + 011111 ( ) + 111111 ( ) ( ) ( ) ( ) Overflow detection: 2’s complement 6-bit examples 100000 ( ) 111111 ( ) ( ) + 011111 ( ) + 111111 ( ) ( ) 011111 ( ) + 011111 ( ) ( )

Subtraction 0 – 0 = 0 1 – 0 = 1 1 – 1 = 0 0 – 1 = ? BORROW! 111000 basic algorithm is like decimal… 0 – 0 = 0 1 – 0 = 1 1 – 1 = 0 0 – 1 = ? BORROW! 111000 - 010110

Subtraction For two’s complement representation The implementation redefines the operation: a – b becomes a + (-b) This is a 2-step algorithm: 1. “take the two’s complement of b” (common phrasing for: find the additive inverse of b) 2. do addition

Subtraction ( ) 001111 - 111100 ( ) ( ) 000010 - 011100 ( ) 6-bit, 2’s complement examples 001111 ( ) - 111100 ( ) 000010 ( ) - 011100 ( )

Subtraction ( ) 100000 - 000010 ( ) Overflow detection: 2’s complement If the addition causes overflow, so does the subtraction! 100000 ( ) - 000010 ( )

Multiplication Same algorithm as decimal… There is a precision problem 0 × 0 = 0 0 × 1 = 0 1 × 0 = 0 1 × 1 = 1 Same algorithm as decimal… There is a precision problem n bits * n bits n + n bits may be needed

In HW, space is always designated for a larger precision product. 32 bits * 32 bits 64 bits

Unsigned Multiplication 01111 * 01101

Unsigned Multiplication 11111 * 11111

Two’s Complement Slightly trickier: must sign extend the partial products (sometimes!)

OR Sign extend multiplier and multiplicand to full width of product _ _ _ _ _ _ * _ _ _ _ _ _ And, use only exact number of lsbs of product product

Multiplication + - + - + - × + × + × - × - OK × + × + OK sign ext. partial product reverse additive inverses or find additive inverses + × + - × + OK

Unsigned Division 11 11001 25/3

Sign Extension 0 0 1 0 1 (5 bits) _ _ _ 0 0 1 0 1 (8 bits) The operation that allows the same 2's complement value to be represented, but using more bits. 0 0 1 0 1 (5 bits) _ _ _ 0 0 1 0 1 (8 bits) 1 1 1 0 (4 bits) _ _ _ _ 1 1 1 0 (8 bits)

Zero Extension 0 0 1 0 1 (5 bits) _ _ _ 0 0 1 0 1 (8 bits) The same type of thing as sign extension, but used to represent the same unsigned value, but using more bits 0 0 1 0 1 (5 bits) _ _ _ 0 0 1 0 1 (8 bits) 1 1 1 1 (4 bits) _ _ _ _ 1 1 1 1 (8 bits)

Truth Table for a Few Logical Operations X Y X and Y X nand Y X or Y X xor Y 1

Logical Operations Logical operations are done bitwise on every computer Invented example: Assume that X,Y, and Z are 8-bit variables and Z, X, Y If X is 0 0 0 0 1 1 1 1 Y is 0 1 0 1 0 1 0 1 then Z is _ _ _ _ _ _ _ _

To selectively clear bit(s) clear a bit means make it a 0 First, make a mask: (the generic description of a set of bits that do whatever you want them to) Within the mask, 1‘s for unchanged bits 0‘s for cleared bits To clear bits numbered 0,1, and 6 of variable X mask 1 . . 1 0 1 1 1 1 0 0 and use the instruction and result, X, mask

To selectively set bit(s) set a bit means make it a 1 First, make a mask: 0‘s for unchanged bits 1‘s for set bits To set bits numbered 2,3, and 4 of variable X mask 0 . . 0 0 0 1 1 1 0 0 and use the instruction or result, X, mask

Shift Moving bits around 1) arithmetic shift 2) logical shift 3) rotate Bits can move right or left

Arithmetic Shift Right sign extension! Left

Logical Shift Right Left Logical left is the same as arithmetic left.

Rotate Right Left No bits lost, just moved

Assume a set of 4 chars. are in an integer-sized variable (X). Assume an instruction exists to print out the character all the way to the right… putc X (prints D) Invent instructions, and write code to print ABCD, without changing X.

Karen’s solution rotl X, 8 bits putc X # A putc X # B putc X # C putc X # D