Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.

Slides:



Advertisements
Similar presentations
B261 Systems Architecture
Advertisements

Integer Arithmetic: Multiply, Divide, and Bitwise Operations
Chapter 3 Arithmetic for Computers. Exam 1 CSCE
Lecture 15: Computer Arithmetic Today’s topic –Division 1.
CMPT 334 Computer Organization Chapter 3 Arithmetic for Computers [Adapted from Computer Organization and Design 5 th Edition, Patterson & Hennessy, ©
Lecture Objectives: 1)Perform binary division of two numbers. 2)Define dividend, divisor, quotient, and remainder. 3)Explain how division is accomplished.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Chapter 3 Arithmetic for Computers. Multiplication More complicated than addition accomplished via shifting and addition More time and more area Let's.
Lecture 9 Sept 28 Chapter 3 Arithmetic for Computers.
1 Representing Numbers Using Bases Numbers in base 10 are called decimal numbers, they are composed of 10 numerals ( ספרות ) = 9* * *10.
Computer Organization Multiplication and Division Feb 2005 Reading: Portions of these slides are derived from: Textbook figures © 1998 Morgan Kaufmann.
Integer Multiplication and Division
1 Lecture 8: Binary Multiplication & Division Today’s topics:  Addition/Subtraction  Multiplication  Division Reminder: get started early on assignment.
ECE 15B Computer Organization Spring 2010 Dmitri Strukov Lecture 6: Logic/Shift Instructions Partially adapted from Computer Organization and Design, 4.
COE 308: Computer Architecture (T041) Dr. Marwan Abu-Amara Integer & Floating-Point Arithmetic (Appendix A, Computer Architecture: A Quantitative Approach,
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
Lecture Objectives: 1)Explain the relationship between addition and subtraction with twos complement numbering systems 2)Explain the concept of numeric.
Operations on data CHAPTER 4.
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.
Lec 13Systems Architecture1 Systems Architecture Lecture 13: Integer Multiplication and Division Jeremy R. Johnson Anatole D. Ruslanov William M. Mongan.
July 2005Computer Architecture, The Arithmetic/Logic UnitSlide 1 Part III The Arithmetic/Logic Unit.
CSE378 Instr. encoding.1 Instruction encoding The ISA defines –The format of an instruction (syntax) –The meaning of the instruction (semantics) Format.
Operations on Bits Arithmetic Operations Logic Operations
Chapter 3 Arithmetic for Computers (Integers). Florida A & M University - Department of Computer and Information Sciences Arithmetic for Computers Operations.
Chapter 10 The Assembly Process. What Assemblers Do Translates assembly language into machine code. Assigns addresses to all symbolic labels (variables.
Conversion to Larger Number of Bits Ex: Immediate Field (signed 16 bit) to 32 bit Positive numbers have implied 0’s to the left. So, put 16 bit number.
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Integer Multiplication and Division
Informationsteknologi Friday, September 28, 2007Computer Architecture I - Class 21 Today’s class More assembly language programming.
True Assembly Language Part I. The Assembly Process The process of translating a MAL code (an assembly language program) into machine code (a sequence.
Integer Multiplication and Division ICS 233 Computer Architecture and Assembly Language Dr. Aiman El-Maleh College of Computer Sciences and Engineering.
Csci 136 Computer Architecture II – Multiplication and Division
EI 209 Chapter 3.1CSE, 2015 EI 209 Computer Organization Fall 2015 Chapter 3: Arithmetic for Computers Haojin Zhu ( )
Division Check for 0 divisor Long division approach – If divisor ≤ dividend bits 1 bit in quotient, subtract – Otherwise 0 bit in quotient, bring down.
Integers’ Representation. Binary Addition. Two's Complement. Unsigned number representation Binary Addition, Subtraction. Overflow of unsigned numbers.
CDA 3101 Spring 2016 Introduction to Computer Organization
CMPUT Computer Organization and Architecture I1 CMPUT229 - Fall 2003 Topic6: Logic, Multiply and Divide Operations José Nelson Amaral.
Integer Multiplication and Division COE 301 Computer Organization Dr. Muhamed Mudawar College of Computer Sciences and Engineering King Fahd University.
Integer Operations Computer Organization and Assembly Language: Module 5.
By Wannarat Computer System Design Lecture 3 Wannarat Suntiamorntut.
COMPUTER ORGANIZATION ARITHMETIC YASSER MOHAMMAD.
Computer System Design Lecture 3
Computer Architecture & Operations I
Integer Multiplication, Division Arithmetic shift
Integers’ Representation. Binary Addition. Two's Complement.
Computer Architecture & Operations I
Integer Multiplication and Division
Single Bit ALU 3 R e s u l t O p r a i o n 1 C y I B v b 2 L S f w d O
Computer Organization and Design Instruction Sets - 2
Computer Organization and Design Instruction Sets - 2
Morgan Kaufmann Publishers
Morgan Kaufmann Publishers
Lecture 8: Binary Multiplication & Division
CDA 3101 Summer 2007 Introduction to Computer Organization
CDA 3101 Spring 2016 Introduction to Computer Organization
Computer Organization and Design Instruction Sets
CS352H: Computer Systems Architecture
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
Systems Architecture I
CDA 3101 Summer 2007 Introduction to Computer Organization
Part III The Arithmetic/Logic Unit
ECE232: Hardware Organization and Design
Morgan Kaufmann Publishers Arithmetic for Computers
MIPS Arithmetic and Logic Instructions
Pointless Poll Clap if you like pizza!.
Number Representation
MIPS Arithmetic and Logic Instructions
Presentation transcript:

Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic shift. sra Textbook: Appendix A Central Connecticut State University, MIPS Tutorial. Chapter 14.

Review: MIPS programming model In this model from the textbook we can see several additional groups of MIPS instructions : Integer Multiplication Division instructions. Floating point arithmetic instructions. System Control instructions MIPS contains: Integer arithmetic processor Floating point arithmetic processor Whole system’s Control Processor

 The product of two N-place decimal integers may need 2N places.  This is also true for numbers expressed in any base.  In particular, the product of two integers expressed with N-bit binary may need 2N bits.  The product of two N-place decimal integers may need 2N places.  This is also true for numbers expressed in any base.  In particular, the product of two integers expressed with N-bit binary may need 2N bits. Twice the Number of Places

 We will mostly write programs that keep the result under 32 bits in length.  When this is true, the result of a multiplication will be in lo  How to keep the result of multiplication in 32 bits ?  How large will be the operands in that case ?  We will mostly write programs that keep the result under 32 bits in length.  When this is true, the result of a multiplication will be in lo  How to keep the result of multiplication in 32 bits ?  How large will be the operands in that case ? Significant bits  The significant bits in a positive or unsigned number represented in binary are the most significant 1 bit (the leftmost 1 bit) and all bits to the right of it. For example, the following has 23 significant bits:  The significant bits in a negative number represented in two's complement are the most significant 0 bit (the leftmost 0 bit) and all bits to the right of it. For example, the following has 23 significant bits:  To ensure that a product has no more than 32 significant bits, ensure that the sum of the number of significant bits in each operand is 32 or less.  The significant bits in a positive or unsigned number represented in binary are the most significant 1 bit (the leftmost 1 bit) and all bits to the right of it. For example, the following has 23 significant bits:  The significant bits in a negative number represented in two's complement are the most significant 0 bit (the leftmost 0 bit) and all bits to the right of it. For example, the following has 23 significant bits:  To ensure that a product has no more than 32 significant bits, ensure that the sum of the number of significant bits in each operand is 32 or less.

 The multiply unit of MIPS contains two 32-bit registers called hi and lo.  These are not general purpose registers.  When two 32-bit operands are multiplied, hi and lo hold the 64 bits of the result.  Bits 32 through 63 are in hi and bits 0 through 31 are in lo.  The multiply unit of MIPS contains two 32-bit registers called hi and lo.  These are not general purpose registers.  When two 32-bit operands are multiplied, hi and lo hold the 64 bits of the result.  Bits 32 through 63 are in hi and bits 0 through 31 are in lo. MIPS Multiply Unit

 There is a multiply instruction for unsigned operands - multu  and a multiply instruction for signed operands (two's complement operands) - mult.  Integer multiplication never causes a trap.  There is a multiply instruction for unsigned operands - multu  and a multiply instruction for signed operands (two's complement operands) - mult.  Integer multiplication never causes a trap. mult, multu  Note: with add and addu, the operation carried out is the same with both instructions. The "u" means "don't trap overflow".  With mult and multu, different operations are carried out. Neither instruction ever causes a trap.  Note: with add and addu, the operation carried out is the same with both instructions. The "u" means "don't trap overflow".  With mult and multu, different operations are carried out. Neither instruction ever causes a trap.

 If we treat the binary patterns as two’s complement then 2x-3 should be equal to -6 – So we should use mult to get the correct two’s complement result.  If we treat the binary patterns as unsigned numbers then 2x5 should be equal to unsigned 10. So we should use the unsigned multiplication. In this case multu will do the task.  If we treat the binary patterns as two’s complement then 2x-3 should be equal to -6 – So we should use mult to get the correct two’s complement result.  If we treat the binary patterns as unsigned numbers then 2x5 should be equal to unsigned 10. So we should use the unsigned multiplication. In this case multu will do the task. mult, multu

There are two instructions that move the result of a multiplication into a general purpose register: The mfhi and mflo Instructions mfhi d # d <-- hi. Move From Hi mflo d # d <-- lo. Move From Lo ## Program to calculate 5 × x – 74 #### Register Use: ## $8 x ## $9 result.text.globl main main: ori $8,$0,12 # put x into $8 ori $9,$0,5 # put 5 into $9 mult $9,$8 # lo <-- 5x mflo $9 # $9 = 5x addiu $9,$9,-74 # $9 = 5x - 74 ## Program to calculate 5 × x – 74 #### Register Use: ## $8 x ## $9 result.text.globl main main: ori $8,$0,12 # put x into $8 ori $9,$0,5 # put 5 into $9 mult $9,$8 # lo <-- 5x mflo $9 # $9 = 5x addiu $9,$9,-74 # $9 = 5x - 74

div “/” and mod “%” in C Example from K&R: printf ("\n9 div 4 = 2 remainder 1 :\n"); printf ("int 9 / 4 = %d\n", 9 / 4);//Quotient -> (hi) printf ("int 9 % 4 = %d\n", 9 % 4);//Remainder -> (lo) Example from K&R: printf ("\n9 div 4 = 2 remainder 1 :\n"); printf ("int 9 / 4 = %d\n", 9 / 4);//Quotient -> (hi) printf ("int 9 % 4 = %d\n", 9 % 4);//Remainder -> (lo) 9 div 4 = 2 remainder 1: int 9 / 4 = 2 int 9 % 4 = 1

 With N-place integer division there are two results  an N-place quotient  and an N-place remainder.  With 32-bit operands there will be (in general) two 32-bit results.  MIPS uses the hi and lo registers for the results:  With N-place integer division there are two results  an N-place quotient  and an N-place remainder.  With 32-bit operands there will be (in general) two 32-bit results.  MIPS uses the hi and lo registers for the results: The div and the divu Instructions

## Program to calculate (y + x) / (y - x) #### Register Use: ## $8 x, $9 y ## $10 x/y quotient, $11 x%y remainder.text.globl main main: ori $8,$0,8 # put x into $8 ori $9,$0,36 # put y into $9 addu $10,$9,$8 # $10 <-- (y+x) subu $11,$9,$8 # $11 <-- (y-x) div $10,$11 # hilo<--(y+x)/(y-x) mflo $10 # $10 <-- quotient mfhi $11 # $11 <-- remainder Example

 The problem is that a shift right logical moves zeros into the high order bit. This is correct in some situations, but not for dividing two's complement negative integers.  An arithmetic right shift replicates the sign bit as needed to fill bit positions. Shift Right Arithmetic

Multiply registers rs and rt and add the resulting 64-bit product to the 64-bit value in the concatenated registers lo and hi. madd $8, $9 # Multiply add maddu $8, $9# Unsigned multiply add Multiply registers rs and rt and subtract the resulting 64-bit product from the 64-bit value in the concatenated registers lo and hi. msub $8, $9# Multiply subtract msubu $8, $9# Unsigned multiply subtract The madd, maddu, msub, msubu Instructions