1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.

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

Intro to CS – Honors I Representing Numbers GEORGIOS PORTOKALIDIS
Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
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
Review Two’s complement
Assembly Language and Computer Architecture Using C++ and Java
Computer ArchitectureFall 2008 © August 25, CS 447 – Computer Architecture Lecture 3 Computer Arithmetic (1)
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
Arithmetic and Logical Operations
ECE 331 – Digital System Design
ECE 301 – Digital Electronics
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.
FIGURES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Arithmetic for Computers
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
ECE 4110– Sequential Logic Design
Binary Arithmetic Stephen Boyd March 14, Two's Complement Most significant bit represents sign. 0 = positive 1 = negative Positive numbers behave.
Chapter 7 Arithmetic Operations and Circuits Binary Arithmetic Addition –When the sum exceeds 1, carry a 1 over to the next-more-significant column.
BINARY ARITHMETIC Binary arithmetic is essential in all digital computers and in many other types of digital systems.
1 CS/COE0447 Computer Organization & Assembly Language Chapter 3.
Digital Arithmetic and Arithmetic Circuits
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION.
Number Systems. Why binary numbers? Digital systems process information in binary form. That is using 0s and 1s (LOW and HIGH, 0v and 5v). Digital designer.
CSE 241 Computer Organization Lecture # 9 Ch. 4 Computer Arithmetic Dr. Tamer Samy Gaafar Dept. of Computer & Systems Engineering.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Positional Number Systems
ECE 2110: Introduction to Digital Systems Signed Addition/Subtraction.
Operations on Bits Arithmetic Operations Logic Operations
Combinational Circuits
1 Positive numbers are well understood An n-bit number represents numbers from 0 to 2 n -1 n+m bits can be used to represent n-bit integer and m-bit fraction.
Number Systems & Operations
07/12/ Data Representation Two’s Complement & Binary Arithmetic.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
Introduction * Binary numbers are represented with a separate sign bit along with the magnitude. * For example, in an 8-bit binary number, the MSB is.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
Arithmetic Operations
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic Herbert G. Mayer, PSU Status 1/14/2016 Copied with Permission from prof. Mark PSU ECE.
ECE/CS 552: Arithmetic I Instructor:Mikko H Lipasti Fall 2010 University of Wisconsin-Madison Lecture notes partially based on set created by Mark Hill.
ECE DIGITAL LOGIC LECTURE 15: COMBINATIONAL CIRCUITS Assistant Prof. Fareena Saqib Florida Institute of Technology Fall 2015, 10/20/2015.
Integer Operations Computer Organization and Assembly Language: Module 5.
09/03/20161 Information Representation Two’s Complement & Binary Arithmetic.
Chapter 6. Digital Arithmetic: Operations and Circuits
Digital Logic & Design Adil Waheed Lecture 02.
Chapter 4 Operations on Bits.
Digital Logic & Design Dr. Waseem Ikram Lecture 02.
CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION
Digital Arithmetic Wen-Hung Liao, Ph.D..
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
University of Gujrat Department of Computer Science
Principles & Applications
Binary Addition & Subtraction
Wakerly Section 2.4 and further
Lecture 2 Topics Binary Arithmetic (Unsigned binary operands)
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
Digital Logic & Design Lecture 02.
EE207: Digital Systems I, Semester I 2003/2004
Unit 18: Computational Thinking
Binary to Decimal Conversion
ECE 171 Digital Circuits Chapter 2 Binary Arithmetic
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Two’s Complement & Binary Arithmetic
Presentation transcript:

1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3

2 x y+0001 sum 0100 Or in tabular form… Binary Addition Carry In ABSum Carry Out

3 Binary Addition ab sum coci And as a full adder… 4-bit Ripple-Carry adder: Carry values propagate from bit to bit Like pencil-and-paper addition Time proportional to number of bits “Lookahead-carry” can propagate carry proportional to log(n) with more space. ab sum coci ab sum coci ab sum coci ab sum coci

4 Addition: unsigned Just like the simple addition given earlier: Examples: (we are ignoring overflow for now) (33) (10) (29) (14) (62) (24)

5 Addition: 2’s complement Just like unsigned addition Assume 6-bit and observe: (3) (-4) (-1) (-24) (16) (-8) (-1) (8) (7) Ignore carry-outs (overflow) Sign bit is in the 2 n-1 bit position What does this mean for adding different signs?

6 Addition: 2’s complement More examples: Convert to 2SC and do the addition

7 Addition: sign magnitude Add magnitudes only, just like unsigned addition Do not carry into the sign bit If a carry out of the MSB of magnitude then overflowed Add only integers of like sign (“+ to +” OR “– to –” ) Sign of the result is same as sign of the addends

8 Examples: (5) (3) (8) (-10) (-3) (-13) (11) (-14) Cannot add!!! This is a subtraction Addition: sign magnitude

9 Subtraction General rules: 1 – 1 = 0 0 – 0 = 0 1 – 0 = 1 10 – 1 = 1 0 – 1 = need to borrow! Or replace (x – y) with x + (-y) Can replace subtraction with additive inverse and addition

10 Subtraction: 2’s complement Don’t. Just use addition: x – y  x + (-y) Example: (-10) (3) (-10) (-3) (-13)

11 Subtraction: 2’s complement Can also flip bits of bottom # and add an LSB carry in, so for we get: (throw away carry out) Addition and subtraction are simple in 2’s complement, just need an adder and inverters. “add 1”“flip bits of bottom number”

12 Subtraction: Unsigned For n-bits use the 2’s complement method and overflow if negative (+28) (+22) Becomes Only take 5 bits of result

13 Subtraction: Sign Magnitude If signs are different, then change the problem to additionIf signs are different, then change the problem to addition If the signs are the same then do subtractionIf the signs are the same then do subtraction –compare magnitudes –subtract smaller from larger –if the order was switched, then switch the sign of the result

14 Subtraction: sign magnitude (24) (7) (-17) becomes (7) (24) Switched sign since the order of the subtraction was reversed (-24) (-2) (-22) For example: Evaluation of the sign bit is not part of the arithmetic, it is determined by comparing magnitudes

15 Overflow in Addition Unsigned: When there is a carry out of the MSB 1000 (8) (9) (1)

16 Signed magnitude: When there is a carry out of the MSB of the magnitude (-8) (-9) Overflow in Addition carry out from MSB of magnitude (-1)

17 2’s complement: When the signs of the addends are the same, but the sign of the result is different 0011 (3) (6) Adding 2 numbers of opposite signs never overflows Why? Overflow in Addition 1001 (-7)

18 Overflow in Subtraction Unsigned: if result is negative Signed magnitude: never happens when actually doing subtraction 2’s complement: never do subtraction, so use the addition rule on the addition operation done.

19 Unsigned Binary Multiplication The multiplicand is multiplied by the multiplier to produce the product, the sum of partial products multiplicand X multiplier = product 0011 (+3) x 0110 (+6) (+18) Longhand, it looks just like decimal Result can require twice as many bits as the larger multiplicand (why?)

(3) x1011 (-5) 2’s Complement Multiplication If negative multiplicand, just sign-extend it. If negative multiplier, take 2SC of both multiplicand and multiplier (-7 x -3 = 7 x 3, and 7 x –3 = -7 x 3) 1101 (-3) x 0101 (+5) (-15) Only need 8 bits for result

21 Division Only required to know for unsigned binary Just like you do with decimal long hand 14/3 = …

22 Logical Operations Operate on raw bits with 1 = true and 0 = false In1In2&|~(&)~(|)^~(^) (AND OR NAND NOR XOR XNOR )

23 In LC-3, done bit-wise in parallel for corresponding bits X = 0011 Y = 1010 X AND Y = ? Logical Operations Example: So how do an OR? How about an XOR?

24 Masking Masking refers to using AND operations to isolate bits in a word Example: ab.FILL0x6162 mask.FILL0x00ff b.FILL0x0062 LDR2, b LDR5, ab LDR3, mask AND R1, R5, R3 JSRSub; R0 = R2 – R1 BRzfound_b; ‘b’ is 0x62 in ASCII Does this code find “b”?

25 How about adding this, does it work? ab.FILL0x6162 mask2.FILL0xff00 a.FILL0x0061 LDR2, a LDR5, ab LDR3, mask2 AND R1, R5, R3 JSRSub; R0 = R2 – R1 BRzfound_a; ‘a’ is 0x61 in ASCII Does this code find “a”? Masking

26 Shifts and Rotates Logical right Move bits to the right, same order Throw away the bit that pops off the LSB Introduce a 0 into the MSB  (shift right by 1 ) Logical left Move bits to the left, same order Throw away the bit that pops off the MSB Introduce a 0 into the LSB  (shift left by 2 ) Can do by adding number to it self Logical Operations

27 Logical Operations: Shifts and Rotates Arithmetic right Move bits to the right, same order Throw away the bit that pops off the LSB Reproduce the original MSB into the new MSB Alternatively, shift the bits, and then do sign extension  (right by 1) 1100  1111(right by 2) Arithmetic left Move bits to the left, same order Throw away the bit that pops off the MSB Introduce a 0 into the LSB  (left by 1)

28 Logical Operations: Shifts and Rotates Rotate left Move bits to the left, same order Put the bit(s) that pop off the MSB into the LSB No bits are thrown away or lost  (rotate by 1) 1100  1001 (rotate by 1) Rotate right Move bits to the right, same order Put the bit that pops off the LSB into the MSB No bits are thrown away or lost  (rotate by 1) 1101  0111 (rotate by 2)

29 Questions?

30