Lecture 8: Binary Multiplication & Division



Similar documents
Divide: Paper & Pencil. Computer Architecture ALU Design : Division and Floating Point. Divide algorithm. DIVIDE HARDWARE Version 1

Binary Division. Decimal Division. Hardware for Binary Division. Simple 16-bit Divider Circuit

CS201: Architecture and Assembly Language

Computer Science 281 Binary and Hexadecimal Review

Today. Binary addition Representing negative numbers. Andrew H. Fagg: Embedded Real- Time Systems: Binary Arithmetic

CSI 333 Lecture 1 Number Systems

Oct: 50 8 = 6 (r = 2) 6 8 = 0 (r = 6) Writing the remainders in reverse order we get: (50) 10 = (62) 8

Recall the process used for adding decimal numbers. 1. Place the numbers to be added in vertical format, aligning the decimal points.

To convert an arbitrary power of 2 into its English equivalent, remember the rules of exponential arithmetic:

Useful Number Systems

Lecture 2. Binary and Hexadecimal Numbers

Paramedic Program Pre-Admission Mathematics Test Study Guide

The string of digits in the binary number system represents the quantity

EE 261 Introduction to Logic Circuits. Module #2 Number Systems

Arithmetic in MIPS. Objectives. Instruction. Integer arithmetic. After completing this lab you will:

COMPSCI 210. Binary Fractions. Agenda & Reading

NUMBER SYSTEMS. William Stallings

Typy danych. Data types: Literals:

This Unit: Floating Point Arithmetic. CIS 371 Computer Organization and Design. Readings. Floating Point (FP) Numbers

Lecture 11: Number Systems

Pre-Calculus II Factoring and Operations on Polynomials

Binary Number System. 16. Binary Numbers. Base 10 digits: Base 2 digits: 0 1

Levent EREN A-306 Office Phone: INTRODUCTION TO DIGITAL LOGIC

Positional Numbering System

AN617. Fixed Point Routines FIXED POINT ARITHMETIC INTRODUCTION. Thi d t t d ith F M k Design Consultant

Reduced Instruction Set Computer (RISC)

2010/9/19. Binary number system. Binary numbers. Outline. Binary to decimal

Goals. Unary Numbers. Decimal Numbers. 3,148 is s 100 s 10 s 1 s. Number Bases 1/12/2009. COMP370 Intro to Computer Architecture 1

=

YOU MUST BE ABLE TO DO THE FOLLOWING PROBLEMS WITHOUT A CALCULATOR!

NUMBER SYSTEMS. 1.1 Introduction

Chapter 4 -- Decimals

Binary Representation. Number Systems. Base 10, Base 2, Base 16. Positional Notation. Conversion of Any Base to Decimal.

LSN 2 Number Systems. ECT 224 Digital Computer Fundamentals. Department of Engineering Technology

Numeral Systems. The number twenty-five can be represented in many ways: Decimal system (base 10): 25 Roman numerals:

Systems I: Computer Organization and Architecture

Session 29 Scientific Notation and Laws of Exponents. If you have ever taken a Chemistry class, you may have encountered the following numbers:

Binary Adders: Half Adders and Full Adders

Solution for Homework 2

Decimals Adding and Subtracting

MATH-0910 Review Concepts (Haugen)

MEP Y9 Practice Book A

COMP 250 Fall 2012 lecture 2 binary representations Sept. 11, 2012

CDA 3200 Digital Systems. Instructor: Dr. Janusz Zalewski Developed by: Dr. Dahai Guo Spring 2012

26 Integers: Multiplication, Division, and Order

Binary Representation

PREPARATION FOR MATH TESTING at CityLab Academy

Chapter 1: Digital Systems and Binary Numbers

JUST THE MATHS UNIT NUMBER 1.8. ALGEBRA 8 (Polynomials) A.J.Hobson

CPEN Digital Logic Design Binary Systems

An Efficient RNS to Binary Converter Using the Moduli Set {2n + 1, 2n, 2n 1}

A single register, called the accumulator, stores the. operand before the operation, and stores the result. Add y # add y from memory to the acc

Solve addition and subtraction word problems, and add and subtract within 10, e.g., by using objects or drawings to represent the problem.

1. Convert the following base 10 numbers into 8-bit 2 s complement notation 0, -1, -12

Number and codes in digital systems

Section 1.4 Place Value Systems of Numeration in Other Bases

Binary Numbers. Binary Octal Hexadecimal

The Euclidean Algorithm

Sheet 7 (Chapter 10)

Sistemas Digitais I LESI - 2º ano

Chapter 1: Order of Operations, Fractions & Percents

3. Convert a number from one number system to another

How do you compare numbers? On a number line, larger numbers are to the right and smaller numbers are to the left.

Chapter 5 Instructor's Manual

3.2 The Factor Theorem and The Remainder Theorem

Math Review. for the Quantitative Reasoning Measure of the GRE revised General Test

Informatica e Sistemi in Tempo Reale

Chapter 2. Binary Values and Number Systems

Section 4.2: The Division Algorithm and Greatest Common Divisors

CS101 Lecture 11: Number Systems and Binary Numbers. Aaron Stevens 14 February 2011

Number Systems and Radix Conversion

Playing with Numbers

Measures of Error: for exact x and approximation x Absolute error e = x x. Relative error r = (x x )/x.

ECE 0142 Computer Organization. Lecture 3 Floating Point Representations

ADDITION. Children should extend the carrying method to numbers with at least four digits.

Accuplacer Arithmetic Study Guide

CS 103X: Discrete Structures Homework Assignment 3 Solutions

ASCII and BCD Arithmetic. Chapter 11 S. Dandamudi

Introduction to MIPS Assembly Programming

Math 0306 Final Exam Review

Copy in your notebook: Add an example of each term with the symbols used in algebra 2 if there are any.

Zuse's Z3 Square Root Algorithm Talk given at Fall meeting of the Ohio Section of the MAA October College of Wooster

Integer Operations. Overview. Grade 7 Mathematics, Quarter 1, Unit 1.1. Number of Instructional Days: 15 (1 day = 45 minutes) Essential Questions

SOLUTIONS FOR PROBLEM SET 2

Dr Brian Beaudrie pg. 1

Some facts about polynomials modulo m (Full proof of the Fingerprinting Theorem)

CS321. Introduction to Numerical Methods

Activity 1: Using base ten blocks to model operations on decimals

Introduction to Programming (in C++) Loops. Jordi Cortadella, Ricard Gavaldà, Fernando Orejas Dept. of Computer Science, UPC

Example. Introduction to Programming (in C++) Loops. The while statement. Write the numbers 1 N. Assume the following specification:

Course Syllabus. MATH 1350-Mathematics for Teachers I. Revision Date: 8/15/2016

3 cups ¾ ½ ¼ 2 cups ¾ ½ ¼. 1 cup ¾ ½ ¼. 1 cup. 1 cup ¾ ½ ¼ ¾ ½ ¼. 1 cup. 1 cup ¾ ½ ¼ ¾ ½ ¼

MACM 101 Discrete Mathematics I

Quick Reference ebook

Addition Methods. Methods Jottings Expanded Compact Examples = 15

Previously, you learned the names of the parts of a multiplication problem. 1. a. 6 2 = 12 6 and 2 are the. b. 12 is the

Continued Fractions and the Euclidean Algorithm

PURSUITS IN MATHEMATICS often produce elementary functions as solutions that need to be

Transcription:

Lecture 8: Binary Multiplication & Division Today s topics: Addition/Subtraction Multiplication Division Reminder: get started early on assignment 3 1

2 s Complement Signed Numbers two = 0 ten 0001 two = 1 ten 0111 1111 1111 1111 1111 1111 1111 1111 two = 2 31-1 1000 two = -2 31 1000 0001 two = -(2 31 1) 1000 0010 two = -(2 31 2) 1111 1111 1111 1111 1111 1111 1111 1110 two = -2 1111 1111 1111 1111 1111 1111 1111 1111 two = -1 Why is this representation favorable? Consider the sum of 1 and -2. we get -1 Consider the sum of 2 and -1. we get +1 This format can directly undergo addition without any conversions! Each number represents the quantity x 31-2 31 + x 30 2 30 + x 29 2 29 + + x 1 2 1 + x 0 2 0 2

Alternative Representations The following two (intuitive) representations were discarded because they required additional conversion steps before arithmetic could be performed on the numbers sign-and-magnitude: the most significant bit represents +/- and the remaining bits express the magnitude one s complement: -x is represented by inverting all the bits of x Both representations above suffer from two zeroes 3

Addition and Subtraction Addition is similar to decimal arithmetic For subtraction, simply add the negative number hence, subtract A-B involves negating B s bits, adding 1 and A 4

Overflows For an unsigned number, overflow happens when the last carry (1) cannot be accommodated For a signed number, overflow happens when the most significant bit is not the same as every bit to its left when the sum of two positive numbers is a negative result when the sum of two negative numbers is a positive result The sum of a positive and negative number will never overflow MIPS allows addu and subu instructions that work with unsigned integers and never flag an overflow to detect the overflow, other instructions will have to be executed 5

Multiplication Example Multiplicand Multiplier Product 1000 ten x 1001 ten --------------- 1000 1000 ---------------- 1001000 ten In every step multiplicand is shifted next bit of multiplier is examined (also a shifting step) if this bit is 1, shifted multiplicand is added to the product 6

HW Algorithm 1 In every step multiplicand is shifted next bit of multiplier is examined (also a shifting step) if this bit is 1, shifted multiplicand is added to the product 7

HW Algorithm 2 32-bit ALU and multiplicand is untouched the sum keeps shifting right at every step, number of bits in product + multiplier = 64, hence, they share a single 64-bit register 8

Notes The previous algorithm also works for signed numbers (negative numbers in 2 s complement form) We can also convert negative numbers to positive, multiply the magnitudes, and convert to negative if signs disagree The product of two 32-bit numbers can be a 64-bit number -- hence, in MIPS, the product is saved in two 32-bit registers 9

MIPS Instructions mult $s2, $s3 computes the product and stores it in two internal registers that can be referred to as hi and lo mfhi $s0 moves the value in hi into $s0 mflo $s1 moves the value in lo into $s1 Similarly for multu 10

Fast Algorithm The previous algorithm requires a clock to ensure that the earlier addition has completed before shifting This algorithm can quickly set up most inputs it then has to wait for the result of each add to propagate down faster because no clock is involved -- Note: high transistor cost 11

Division 1001 ten Quotient Divisor 1000 ten 1001010 ten Dividend -1000 10 101 1010-1000 10 ten Remainder At every step, shift divisor right and compare it with current dividend if divisor is larger, shift 0 as the next bit of the quotient if divisor is smaller, subtract to get new dividend and shift 1 as the next bit of the quotient 12

Division 1001 ten Quotient Divisor 1000 ten 1001010 ten Dividend 0001001010 0001001010 001010 001010 1000 000100 10 001000 Quo: 0 01 010 01001 At every step, shift divisor right and compare it with current dividend if divisor is larger, shift 0 as the next bit of the quotient if divisor is smaller, subtract to get new dividend and shift 1 as the next bit of the quotient 13

Divide Example Divide 7 ten ( 0111 two ) by 2 ten (0010 two ) Iter Step Quot Divisor Remainder 0 Initial values 1 2 3 4 5 14

Divide Example Divide 7 ten ( 0111 two ) by 2 ten (0010 two ) Iter Step Quot Divisor Remainder 0 Initial values 0010 0111 1 Rem = Rem Div 0010 1110 0111 Rem < 0 +Div, shift 0 into Q 0010 0111 Shift Div right 0001 0111 2 Same steps as 1 0001 1111 0111 0001 0111 1000 0111 3 Same steps as 1 0100 0111 4 Rem = Rem Div 0100 0011 Rem >= 0 shift 1 into Q 0001 0100 0011 Shift Div right 0001 0010 0011 5 Same steps as 4 0011 0001 0001 15

Hardware for Division A comparison requires a subtract; the sign of the result is examined; if the result is negative, the divisor must be added back 16

Efficient Division 17

Divisions involving Negatives Simplest solution: convert to positive and adjust sign later Note that multiple solutions exist for the equation: Dividend = Quotient x Divisor + Remainder +7 div +2 Quo = Rem = -7 div +2 Quo = Rem = +7 div -2 Quo = Rem = -7 div -2 Quo = Rem = 18

Divisions involving Negatives Simplest solution: convert to positive and adjust sign later Note that multiple solutions exist for the equation: Dividend = Quotient x Divisor + Remainder +7 div +2 Quo = +3 Rem = +1-7 div +2 Quo = -3 Rem = -1 +7 div -2 Quo = -3 Rem = +1-7 div -2 Quo = +3 Rem = -1 Convention: Dividend and remainder have the same sign Quotient is negative if signs disagree These rules fulfil the equation above 19

Title Bullet 20