carry in carry 1101 carry carry

Similar documents
COMPUTER ARITHMETIC (Part 1)

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

COMP 303 Computer Architecture Lecture 6

Chapter 3: part 3 Binary Subtraction

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Module 2: Computer Arithmetic

Chapter 4 Arithmetic Functions

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Chapter 5: Computer Arithmetic

9 Multiplication and Division

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Lecture 8: Addition, Multiplication & Division

CO212 Lecture 10: Arithmetic & Logical Unit

Number Systems and Computer Arithmetic

Chapter 10 - Computer Arithmetic

EECS150 - Digital Design Lecture 13 - Combinational Logic & Arithmetic Circuits Part 3

The ALU consists of combinational logic. Processes all data in the CPU. ALL von Neuman machines have an ALU loop.

Chapter 5 : Computer Arithmetic

COMPUTER ORGANIZATION AND ARCHITECTURE

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

COMPUTER ARCHITECTURE AND ORGANIZATION. Operation Add Magnitudes Subtract Magnitudes (+A) + ( B) + (A B) (B A) + (A B)

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

(+A) + ( B) + (A B) (B A) + (A B) ( A) + (+ B) (A B) + (B A) + (A B) (+ A) (+ B) + (A - B) (B A) + (A B) ( A) ( B) (A B) + (B A) + (A B)

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

ECE260: Fundamentals of Computer Engineering

Homework 3. Assigned on 02/15 Due time: midnight on 02/21 (1 WEEK only!) B.2 B.11 B.14 (hint: use multiplexors) CSCI 402: Computer Architectures

Chapter 4 Section 2 Operations on Decimals

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

Divide: Paper & Pencil

CPS 104 Computer Organization and Programming

More complicated than addition. Let's look at 3 versions based on grade school algorithm (multiplicand) More time and more area

CS/COE 0447 Example Problems for Exam 2 Spring 2011

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

Numbering systems. Dr Abu Arqoub

Organisasi Sistem Komputer

Week 7: Assignment Solutions

Math in MIPS. Subtracting a binary number from another binary number also bears an uncanny resemblance to the way it s done in decimal.

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Number System. Introduction. Decimal Numbers

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

World Inside a Computer is Binary

CHW 261: Logic Design

EEC 483 Computer Organization

Integer Multiplication and Division

Timing for Ripple Carry Adder

EE 109 Unit 6 Binary Arithmetic

UNIT-III COMPUTER ARTHIMETIC

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

Chapter 3: Arithmetic for Computers

Korea University of Technology and Education

Number Systems. Both numbers are positive

Iterative Division Techniques COMPUTER ARITHMETIC: Lecture Notes # 6. University of Illinois at Chicago

COMPUTER ORGANIZATION AND. Edition. The Hardware/Software Interface. Chapter 3. Arithmetic for Computers

DIGITAL SYSTEM FUNDAMENTALS (ECE 421) DIGITAL ELECTRONICS FUNDAMENTAL (ECE 422) COURSE / CODE NUMBER SYSTEM

By, Ajinkya Karande Adarsh Yoga

Arithmetic Processing

University of Illinois at Chicago. Lecture Notes # 13

Arithmetic Logic Unit

Tailoring the 32-Bit ALU to MIPS

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

Number System. Introduction. Natural Numbers (N) Whole Numbers (W) Integers (Z) Prime Numbers (P) Face Value. Place Value

EE260: Logic Design, Spring n Integer multiplication. n Booth s algorithm. n Integer division. n Restoring, non-restoring

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

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

Floating-Point Data Representation and Manipulation 198:231 Introduction to Computer Organization Lecture 3

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

361 div.1. Computer Architecture EECS 361 Lecture 7: ALU Design : Division

CS 64 Week 1 Lecture 1. Kyle Dewey

UNIT - I: COMPUTER ARITHMETIC, REGISTER TRANSFER LANGUAGE & MICROOPERATIONS

Arithmetic for Computers

NUMBER SCALING FOR THE LGP-27

Place Value. Verbal Form: 30,542 = Thirty thousand, five hundred forty-two. (Notice we don t use the word and.)

Data Representation in Digital Computers

Chapter 10 Binary Arithmetics

CO Computer Architecture and Programming Languages CAPL. Lecture 9

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

Binary Adders. Ripple-Carry Adder

Chapter 3 Arithmetic for Computers. ELEC 5200/ From P-H slides

Positional Number System

Outline. EEL-4713 Computer Architecture Multipliers and shifters. Deriving requirements of ALU. MIPS arithmetic instructions

Internal Data Representation

Computer Arithmetic Ch 8

COMP 122/L Lecture 2. Kyle Dewey

Computer Arithmetic Ch 8

Introduction to Digital Logic Missouri S&T University CPE 2210 Multipliers/Dividers

Adding Binary Integers. Part 5. Adding Base 10 Numbers. Adding 2's Complement. Adding Binary Example = 10. Arithmetic Logic Unit

Adding Binary Integers. Part 4. Negative Binary. Integers. Adding Base 10 Numbers. Adding Binary Example = 10. Arithmetic Logic Unit

5.OA Why Do We Need an Order of Operations?

MIPS Integer ALU Requirements

Arithmetic Operations on Binary Numbers

Arithmetic Operations

Chapter 4. Combinational Logic

Number Systems CHAPTER Positional Number Systems

Integer Arithmetic. Jinkyu Jeong Computer Systems Laboratory Sungkyunkwan University

Arithmetic and Logical Operations

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Transcription:

Chapter Binary arithmetic Arithmetic is the process of applying a mathematical operator (such as negation or addition) to one or more operands (the values being operated upon). Binary arithmetic works exactly like arithmetic, except that 2 (not ) governs how individual digits are interpreted and manipulated.. Addition To add a augend a and addend b, the sum s is constructed by adding digits one at a time from least to most significant digit. If in any position the result is 2,ais carried into the next more-significant position [Alg..]. 5 8 sum out in A non-zero out of the most significant digit indicates unsigned overflow; the result is larger than the largest value that can be represented (2 N, for N bits). 5 62 out in sum Two s complement signed addition is the same as unsigned addition (because 2 N the additive inverse of x, modulo 2 N [Sec. 2..4]). x is -5-2 sum in out to msb of msb in - -5-8 sum in out to msb of msb in If the signed result cannot be represented in the number of bits available then signed overflow will occur. Signed overflow is indicated by the in to the msb being different to the out of the msb. 9

Algorithm. Binary addition input: N-bit augend a and addend b, and a -bit in c output: N-bit sum s, and a -bit out c function ADD(a, b, c) for i to N do n a i b i c. two-bit sum s i n c n return c, s. out and sum 6 8 sum in out to msb of msb in signed overflow - -8-65 sum in out to msb of msb in signed overflow Signed overflow can occur only if the augend and addend have the same sign..2 Subtraction To subtract a subtrahend b from a minuend a, the difference d is constructed by subtracting digits one at a time from the least to the most significant digit. If in any position the resulting digit would be negative, a is ed from the next more-significant position. - - out - - - - difference A non-zero out of the most significant digit indicates unsigned overflow; the (negative) result is less than the smallest value that can be represented (zero). - - -66 (-) - difference out - - - A simpler, more convenient, and more efficient way to subtract b from a is to observe that, modulo 2 N, a b 2 N a b a (2 N b) a b

where b is the two s complement of b [Sec. 2..4]. Subtraction now behaves exacly like addition of signed numbers [Sec..], including the detection of signed overflow by comparing the carries in to and out of the msb. Propagating a is expensive [Sec. 5.4.]. Adding the two s complement of b to a involves propagating two separate carries (first when calculating the two s complement, and again when performing the addition with a). The first of these can be eliminated by observing that the in to the addition is always. Setting the in to instead, and then using the one s complement of b (which can be calculated very efficiently), produces exactly the same result. a b = a b (add the two s complement of b) = a b (add the one s complement of b plus ) Using this method of subtraction, the in to the lsb of the addition becomes a not in. (When c =, the subtraction yields the correct result; when c =, the subtraction yields one less than the correct result.) Similarly, the out from the msb of the addition represents the not out from the subtraction. For unsigned subtraction, an unsigned overflow has therefore occured if (and only if) the out is. (Most ALUs implement subtraction using this method. How programmers view and depends on the design of the CPU instruction set. Some CPUs, such as the ARM found in most mobile devices, use the directly and programmers must treat is as not. Others, such as Intel processors, invert the in and out when subtracting, and programmers treat as.). Multiplication To multiply a multiplicand a and multiplier b, the product p (initially ) is constructed by considering each bit position i in the multiplier. If b i =, the multiplicand is shifted left i bits (forming a partial product) and added to p [Alg..2]. NX p = b i a 2 i i= 6 5 product Signed multiplication is the same as unsigned multiplication, provided signed overflow is avoided during the addition of the partial products. The product p of two N-bit numbers p = a b can require up to 2N bits, so the mulitplication is converted to a 2N-bit multplication by sign-extending both multiplicand and multiplier to 2N bits. A 2N-bit unsigned multiplication of two signed numbers then gives the correct 2N-bit signed result.

Algorithm.2 Binary multiplication input: N-bit multiplicand a and multiplier b output: 2N-bit product p function MULTIPLY(a, b) p. register p is 2N bits wide for N times do if b =then p p a. accumulate partial products a a lshift b b rshift return p. product () (-5) (??) incorrect () (-5) sign extended (-5) (-) (-) sign extended (9) To obtain a N-bit result, take the least significant N bits of the 2N-bit result. If any of the most significant N bits are non-zero, then an unsigned overflow has occurred. If any of the most significant N bits differ from the sign bit p N of the result, then a signed overflow has occured..4 Division To divide a N-bit unsigned dividend a by an unsigned divisor b, set r to a and then the quotient q is the number of times b can be subtracted from r without the result becoming negative. When no more subtractions are possible, r contains the remainder and a = b q r, r<b. Because of the second condition (which implies b 6= ) there is only one solution to this equation. The manual process of long division is more efficient. quotient 7 2 2-2 - (cannot subtract) (-7=4) - (8-7=) 2 remainder

Algorithm. Unsigned division input: N-bit dividend a and divisor b output: N-bit quotient q and remainder r note: All registers are N bits wide, except for r : a which is the 2N-bit concatenation of r (most significant half) and a (least significant half). function UNSIGNEDDIVIDE(a, b) q r.r:ais the 2N-bit, zero-extended dividend for N times do q q lshift r:a r:a lshift. moves msb of dividend a to lsb of r if r b then r r b. subtract the divisor from the partial remainder q q. put the corresponding into the lsb of the quotient return q, r. unsigned quotient and remainder Manual long division can be simulated by initially shifting r (a copy of a) to the right N bits, and then building q one bit at a time, from msb to lsb. For each bit position, r is shifted left one bit and b subtracted from it. If the result is non-negative, a is appended to the least-significant end of q; otherwise a is appended to q, and r restored to its previous value. When all N bit positions have been considered, q contains a b and r contains the remainder. Signed, two s complement division can be performed by making dividend and divisor positive, performing an unsigned division, and then adjusting the signs of the quotient and remainder. As above, quotient and remainder are still defined by a = b q r, and r < b, but this is insufficient to avoid multiple solutions, because we do not know the correct signs of q and r. To make the solution unique, the usual convention is to require sign r =signa, and, if sign a =signb, sign q =, otherwise. Algorithms can be constructed to perform division directly on signed, two s complement dividend and divisor [Alg..4]. Regardless of the algorithm used, signed overflow can occur during division. For example, the two s complement signed result of the 8-bit division 28 cannot be represented in 8 bits.

Algorithm.4 Signed, two s complement, restoring division input: N-bit signed dividend n and divisor d output: N-bit quotient q and remainder r such that n = d q r, where r always has the same sign as n, q is negative if the signs of n and d differ, and apple r < d note: All registers are N bits wide, except for r : q which is the 2N-bit concatenation of r (most significant half) and q (least significant half). note: r : q initially holds a sign-extended dividend. Instead of shifting the divisor right at each division step, we shift the dividend r : q left (setting the lsb of q to ). The partial remainder is therefore always in r, and if we succeed in subtracting the divisor from it we can put a into the lsb of q. After N iterations, q contains the quotient and r contains the remainder. function SIGNEDDIVIDE(n, d) r:q sign-extend n. sign-extend dividend to 2N bits for N times do. form N quotient bits, one at a time, from msb to lsb r: q r: q lshift.r: q is the 2N-bit concatenation of N-bit registers r and q p r if sign r =signdthen.rand d are both positive or both negative r r d. move r towards else r r d. ditto if sign p =signq _ (r =^q =)then. subtraction did not cross q. shift a into the lsb of the quotient else. subtraction overflowed r p. restore r to previous value if r = d then. for negative n, the loop can produce r = d r. so adjust remainder and quotient if necessary q q. to guarantee r < d if sign n 6= signd then. the above computes a positive quotient q q. so make it negative if necessary return q, r. signed quotient and remainder 4