Multiplication by small constants (pp. 139 – 140)

Slides:



Advertisements
Similar presentations
Fractions. ADDING FRACTIONS  Build each fraction so that the denominators are the same  ADD the numerators  Place the sum of the two numerators on.
Advertisements

ARM versions ARM architecture has been extended over several versions.
Overheads for Computers as Components 2nd ed.
Multiplication – Microprocessor
© 2000 Morgan Kaufman Overheads for Computers as Components ARM instruction set zARM versions. zARM assembly language. zARM programming model. zARM memory.
Chapter 2 Instruction Sets 金仲達教授 清華大學資訊工程學系 (Slides are taken from the textbook slides)
1 ECE 5465 Advanced Microcomputers Group 11: Brian Knight Benjamin Moore Alex Williams.
Embedded System Design Center ARM7TDMI Microprocessor Data Processing Instructions Sai Kumar Devulapalli.
COMP3221 lec10-logical-II&mul.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 10: C/Assembler Logical and Shift – II & Multiplication.
COMP3221 lec9-logical-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 9: C/Assembler Logical and Shift - I
Binary Logic (review) Basic logical operators: (Chapter 7 expanded)
CMPT 334 Computer Organization Chapter 3 Arithmetic for Computers [Adapted from Computer Organization and Design 5 th Edition, Patterson & Hennessy, ©
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Computer Organization & Assembly Language
Modified from the notes by
Thumb Data Processing Instructions and Breakpoint Instructions 02/18/2015 Mingliang Ge Yi (Leo) Wu Xinuo (Johnny) Zhao.
COMP3221 lec08-arith.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 8: C/Assembler Data Processing
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
1 Lecture 4: Arithmetic for Computers (Part 4) CS 447 Jason Bakos.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
 SWBAT solve two-step algebraic equations.  Two-Step Equations are equations that require two- steps to solve.  You will ADD or SUBTRACT and then.
Arithmetic for Computers
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Multiplication of signed-operands
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
Lecture 4: Load/Store Architectures CS 2011 Fall 2014, Dr. Rozier.
Arithmetic and Logic Chapter 5
Integer Multiplication, Division Arithmetic shift Twice the number of places MIPS multiply unit. mult, multu Significant bits Mfhi, mflo, div, divu Arithmetic.
COMP3221: Microprocessors and Embedded Systems--Lecture 10 1 COMP3221: Microprocessors and Embedded Systems Lecture 10: Shift and Bit-set Instructions.
Addition Multiplication Subtraction Division. 1.If the signs are the same, add the numbers and keep the same sign = = If the.
Ch 3.1 Add and Subtract Signed Numbers Vocabulary Op posites :2 numbers the same distance from 0 but in opposite directions
Add & Subtract. Addition Add bit by bit from right to left Ex 5+6 or (5)0111 (7) (6)OR (3) 1011 (11)1010 (10)
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
ARM Shifts, Multiplies & Divide??. MVN Pseudo Instructions Pseudo Intruction: Supported by assembler, not be hardware.
Binary Logic (review) Basic logical operators:(Chapter 7 expanded) NOT AND – outputs 1 only if both inputs are 1 OR – outputs 1 if at lest one input is.
Basic derivation rules We will generally have to confront not only the functions presented above, but also combinations of these : multiples, sums, products,
ARM Intro.
Multiplication
Chapter 15: Higher Level Constructs
Chapter 5 Integer Arithmetic.
The University of Adelaide, School of Computer Science
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
Assembly Language Assembly Language
EE 319K Introduction to Embedded Systems
Processor Instructions set. Learning Objectives
March 2006 Saeid Nooshabadi
Knowing your math operation terms
Multiplication
Arithmetic and Logic Chapter 5
68000 Arithmetic Instructions
Lecture 8: Addition, Multiplication & Division
Lecture 8: Addition, Multiplication & Division
MISP Assembly.
Writing expression basic
EXPRESSIONS We have studied the following in the previous term. 11 = (1 x 10) + 1, 12 = (1 x 10) = (2 x 10) In the above numerical expressions.
Topic 6: Bitwise Instructions
Shift & Rotate Instructions)
Arithmetic and Logic Chapter 5
Table 3‑1: Unsigned Data Range Summary in ARM
The ARM Instruction Set
Branching instructions
Overheads for Computers as Components 2nd ed.
Number Lines.
CS501 Advanced Computer Architecture
Immediate data Immediate operands : ADD r3, r3, #1 valid ADD r3, #1,#2 invalid ADD #3, r1,r2 invalid ADD r3, r2, #&FF ( to represent hexadecimal immediate.
微處理機 Microprocessor (100上) ARM 內核嵌入式SOC原理
Subtracting integers without number line 3 digit.
Arithmetic and Logic Chapter 3
Presentation transcript:

Multiplication by small constants (pp. 139 – 140) Multiplying by a small constant is often faster using shifts and additions To use shifts and addition (or subtraction) convert the constant into a sum of powers of two convert the multiplications by powers of two into left shifts  

Multiplication by small constants (pp. 139 – 140) Example 1: x * 10 convert the constant into a sum of powers of two x * 10 = x * (8 + 2) = (x * 23) + (x * 21) convert the multiplications by powers of two into left shifts = (x << 3) + (x << 1)

Multiplication by small constants (pp. 139 – 140) Example 1 cont'd: x * 10 = x * (8 + 2) = (x * 23) + (x * 21) = (x << 3) + (x << 1) ARM code: Put x in r0 (NOTE: do not destroy r0) mov r1, r0, lsl #3 // r1 = r0 * 8 add r1, r1, r0, lsl #1 // r1 = r1 + r0 * 2 Why have an add instruction in the above example? Because only the second source operand can be shifted.

Multiplication by small constants (pp. 139 – 140) Example 2: x * 13 convert the constant into a sum of powers of two x * 13 = x * (8 + 4 + 1 ) = (x * 8) + (x * 4) + (x * 1) = (x * 23) + (x * 22) + (x * 20) convert the multiplications by powers of two into left shifts x * 13 = (x * 23) + (x * 22) + x = (x << 3) + (x << 2) + x

Multiplication by small constants (pp. 139 – 140) Example 2 cont'd: x * 13 = (x * 23) + (x * 22) + (x * 20) = (x << 3) + (x << 2) + x ARM code: Put x in r0 (NOTE: do not destroy r0) add r1, r1, r0, lsl #3 add r1, r1, r0, lsl #2 add r1, r1, r0

Multiplication by small constants (pp. 139 – 140) Example 3: x * 30 convert the constant into a sum of powers of two x * 30 = x * (16 + 8+ 4 + 2 ) = (x * 16) + (x * 8) + (x * 4) + (x * 2) = (x * 24) + (x * 23) + (x * 22) + (x * 21) convert the multiplications by powers of two into left shifts x * 30 = (x * 24) + (x * 23) + (x * 22) + (x * 21) = (x << 4) + (x << 3) + (x << 2) + (x << 1)

Multiplication by small constants (pp. 139 – 140) Example 3 cont'd: x * 30 = (x * 24) + (x * 23) + (x * 22) + (x * 21) = (x << 4) + (x << 3) + (x << 2) + (x << 1) ARM code: Put x in r0 (NOTE: do not destroy r0) mov r1, r0, lsl #4 add r1, r1, r0, lsl #3 add r1, r1, r0, lsl #2 add r1, r1, r0, lsl #1

Multiplication by small constants (pp. 139 – 140) Example 4: x * 7 x * 7 = x * (8 - 1) = (x * 8) - (x * 1) = (x * 23) - (x * 20) x * 15 = (x * 23) - (x * 20) = (x << 3) - x

Multiplication by small constants (pp. 139 – 140) Example 4 cont'd: x * 7 = (x * 23) - (x * 20) = (x << 3) - x ARM code: Put x in r0 rsb r1, r0, r0, lsl #3 // r1 = 8*r0 – r0 = 7*r0 rsb rd, rn, op2 (reverse subtract): subtracts rn from op2; therefore, rsb r1, r0, r1 is the same as sub r1, r1, r0 // r1 = r1 – r0

Division by small constants (p. 108) MOV r1, r3, ASR #7 // r1 = r3/128 vs. MOV r1, r3, LSR #7 // r1 = r3/128 The first treats the registers like signed values (shifts in MSB). The latter treats data like unsigned values (shifts in 0). int vs unsigned int >>