Multiplication – Microprocessor

Slides:



Advertisements
Similar presentations
ECE 353 Introduction to Microprocessor Systems Michael G. Morrow, P.E. Week 4.
Advertisements

Register Transfer and Microoperations Part2
Intel 8086.
B261 Systems Architecture
Chapter 4 Addressing modes CEG2400 Microcomputer Systems CEG2400 ch4 addressing modes v3a 1.
Computer Science Education
SE 292 (3:0) High Performance Computing L2: Basic Computer Organization R. Govindarajan
Morgan Kaufmann Publishers Arithmetic for Computers
CS 1 Introduction CS 1 Part 11. Hardware 1.Central Processing Unit (CPU) 2.Main Memory 3.Secondary Memory / Storage 4.Input Devices 5.Output Devices CS.
Princess Sumaya University
Slides created by: Professor Ian G. Harris Efficient C Code  Your C program is not exactly what is executed  Machine code is specific to each ucontroller.
ARM versions ARM architecture has been extended over several versions.
Embedded Systems Programming
Appendix D The ARM Processor
Overheads for Computers as Components 2nd ed.
The University of Adelaide, School of Computer Science
Chapter 3 โพรเซสเซอร์และการทำงาน The Processing Unit
Wat gaan we doen? harhaling data types
Embedded Systems Architecture
MIPS Assembly Tutorial
THUMB Instructions: Branching and Data Processing
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.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Load and store instruction.
CONDITION CODE AND ARITHMETIC OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
COMP3221 lec10-logical-II&mul.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 10: C/Assembler Logical and Shift – II & Multiplication.
INTRODUCTION TO THE ARM PROCESSOR – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
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)
Modified from the notes by
Chap.2: Instructions: Language of the computer Jen-Chang Liu, Spring 2006 Adapted from
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 4: Memory Access March,
Elec2041 lec-11-mem-I.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 11: Memory Access - I
Topics covered: ARM Instruction Set Architecture CSE 243: Introduction to Computer Architecture and Hardware/Software Interface.
Data Transfer & Decisions I (1) Fall 2005 Lecture 3: MIPS Assembly language Decisions I.
Lecture Objectives: 1)Explain the relationship between addition and subtraction with twos complement numbering systems 2)Explain the concept of numeric.
ARM Instructions I Prof. Taeweon Suh Computer Science Education Korea University.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Thumb Instruction Set.
Topic 8: Data Transfer Instructions CSE 30: Computer Organization and Systems Programming Winter 2010 Prof. Ryan Kastner Dept. of Computer Science and.
Topic 10: Instruction Representation CSE 30: Computer Organization and Systems Programming Winter 2011 Prof. Ryan Kastner Dept. of Computer Science and.
Making Decision – Microprocessor
BITWISE OPERATIONS – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat.
1 Chapter 4 ARM Assembly Language Smruti Ranjan Sarangi Computer Organisation and Architecture PowerPoint Slides PROPRIETARY MATERIAL. © 2014 The McGraw-Hill.
Lecture 2: Advanced Instructions, Control, and Branching EEN 312: Processors: Hardware, Software, and Interfacing Department of Electrical and Computer.
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.
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
Chapter 15: Higher Level Constructs
ECE 3430 – Intro to Microcomputer Systems
Assembly Language Assembly Language
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
Processor Instructions set. Learning Objectives
March 2006 Saeid Nooshabadi
The University of Adelaide, School of Computer Science
Topic 6: Bitwise Instructions
Multiplication by small constants (pp. 139 – 140)
3.
Arithmetic and Logic Chapter 5
COMS 361 Computer Organization
The ARM Instruction Set
Branching instructions
March 2006 Saeid Nooshabadi
Overheads for Computers as Components 2nd ed.
Computer Architecture
Multiply Instructions
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.
MICROCONTROLLERS AND EMBEDDED SYSTEMS Unit – 4 : ARM / Thumb Instruction set GEC
ARM Load/Store Instructions
Arithmetic and Logic Chapter 3
Presentation transcript:

Multiplication 353156 – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka and Asst. Prof. Dr. Suphot Chunwiphat

Review : ARM Instruction so far ADD : Addition SUB : Subtraction MOV : Move AND : And BIC : And not ORR : Or EOR : Xor LSL : Shift left LSR : Shift right ASR : Arithmetic Shift Right ROR : Rotate right

Decimal Multiplication In decimal Multiplying by 10 is same as shifting left by 1 54 * 10 = 540 120 * 10 = 1200 Multiplying by 100 is same as shifting left by 2 54 * 100 = 5400 120 * 100 = 12000 Multiplying by 10n is same as shifting left by n

Binary Multiplication In Binary Multiplying by 2 (102) is same as shifting left by 1 112 * 102 = 1102 1012 * 102 = 10102 Multiplying by 4 (1002) is same as shifting left by 2 112 * 1002 = 11002 1012 * 1002 = 101002 Multiplying by 2n is same as shifting left by n

Multiply by Power of 2 via Shift Left Since shifting is so much faster than the multiplication A good compiler usually notice for example C code multiplies by power of 2 and compiles it to a shift instruction Example In C: A = A * 8 In Assembly : MOV R0, R0, LSL #3

Shift, Add and Subtract for Multiplication In Depth techniques : Example 1 : In C : R0 = 5 * R1 In ARM Assembly: R0 = (4 + 1) * R1 = (4 * R1) + R1 = R1 + (4 * R1) ADD R0, R1, R1, LSL #2 Example 2 : In C : R0 = 105 * R1 In ARM Assembly : R0 = (15 * 7) * R1 = (16 – 1) * (8 - 1) * R1 RSB R0, R1, R1, LSL #4 ; (16 – 1) * R1 RSB R0, R0, R0, LSL #3 ; (8 – 1) * R0

Multiply (unsigned) : Example Multiplicand (810) 1 0 0 0 Multiplier (910) 1 0 0 1 X 1 1 1 1 =7210 m bits x n bits = m + n bit product Thus, 32 bits X 32 bits = 64 bits value

Multiply (signed) : Example Multiplicand (-810) 1 0 0 0 Multiplier (-710) 1 0 0 1 X 1 1 1 1 = 7210

2’s Complement Multiplication A sequence of 2’s complement addition except for last step, we do the subtraction. Multiplicand (-810) 1 0 0 0 Multiplier (-710) 1 0 0 1 X 1 1 1 1 1 1 1 1 2’s complement.. =5610 1 1 1 1

2’s Complement Multiplication (more example) Multiplicand (-810) 1 0 0 0 Multiplier ( 310) 0 0 1 1 X 1 1 1 1 1 1 1 1 1 2’s complement.. 1 1 1 1 1 2’s complement.. 1 1 =2410

Multiplication Instructions BASIC ARM Multiplication MUL Rd, Rm, Rs ; Rd = Rm * Rs ;signed [31:0] Warning : Rd can’t be the same as Rm Multiply-Long UMULL RdHi, RdLo, Rm, Rs ;unsigned SMULL RdHi, RdLo, Rm, Rs ;signed RdHi = Rm * Rs [63:32] RdLo = Rm * Rs [31:0] ** No Division Instruction in ARM ** Division has to be done in software through a sequence of shift/subtract/add instruction (too much for this class)

Exercise 1 Given After execute the instruction R2 stores value -10 R3 stores value 2 After execute the instruction SMULL R0, R1, R2, R3 What is the value stores in R0 and R1 ?

353156 – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka Memory Access 353156 – Microprocessor Asst. Prof. Dr. Choopan Rattanapoka

ARM and Memory Up until now, we learnt the ARM instructions ADD, SUB, LSL, LSR, ORR, XOR, MOV, ..etc. Remember ?, ARM arithmetic instructions only operate on registers, never directly on memory. Data Transfer Instructions transfer data between registers and memory: Memory to Register Register to Memory

Review : MOV with Immediate MOV R0, #12 Immediate value must be fit in 8 bit Immediate value can get by rotate even number of bit MOV R0, #0xFF000000 ; 0xFF rotate right by 24 bit MOV R0, #0x123456 doesn’t work !! LDR R0, =0x123456 Assembler will allocate memory and store value 0x123456 for you, then LDR instruction will load value from that address to the register Why not always use LDR instruction for immediate value ? Loading value from memory is much SLOWER than generating it by ALU.

Data Transfer : Memory to Register (1) To transfer a word of data, we need to specify two things : Register Memory Address Think of memory as a single one- dimension array, so we can address it simply by supplying a pointer to a memory address Other times, we want to be able to offset from this pointer pointer 0x40000000 0x40000004 0x40000008 0x4000000C 0x40000010 offset

Data Transfer : Memory to Register (2) To specify a memory address to copy from, specify two things : A register which contains a pointer to memory A numerical offset (in bytes), or a register which contain an offset The desired memory address is the sum of these two values Example 1: [ v1 , #8 ] Specifies the memory address pointed by the value in v1 + 8 bytes Example 2: [ v1, v2 ] Specifies the memory address pointed by the value in v1 + v2

Data Transfer : Memory to Register (3) Load Instruction Syntax : LDR 1, [ 2, 3 ] 1 : register that will receive value 2 : register containing pointer to memory 3 : numerical offset in bytes or another shifted index register Example LDR R0, [ R1, #8] LDR R0, [ R1, R2] Offset Base register Index register

Example 1 Given a table of memory address and its stored data, What the value in R0, R1, and R2 after executing the programs AREA ex1, CODE, READONLY ENTRY start LDR R2, =0x40000000 MOV R3, #4 LDR R0, [R2, R3] LDR R1, [R2, #16] END Value Address 0x10 0x4000 0000 0x20 0x4000 0004 0x30 0x4000 0008 0x50 0x4000 000C 0x4000 0010 0x45 0x4000 0014 0xFF 0x4000 0018

Pre Indexed Load Instruction Pre Indexed Load Instruction Syntax : LDR 1, [ 2, 3]! 1 : register that will receive value 2 : register containing pointer to memory 3 : numerical offset in bytes or another shifted index register This instruction will take 2 step 1) Register “1” loads the value from the memory pointed by the pointer in “2”, add “3” bytes 2) “2” is updated by computed sum of “2” and “3” Example : Let R1 = 0x4000 0000 LDR R0, [R1, #0x12] ! Load R0  mem[ R1 + 0x12 ] ; R0  mem [0x4000 0012] Update base register : R1  R1 + 0x12 ; now R1 = 0x4000 0012

Example 2 Given a table of memory address and its stored data, What the value in R0, R1, R2 after execution the programs AREA ex2, CODE, READONLY ENTRY start LDR R2, =0x40000000 MOV R3, #4 LDR R0, [R2, R3] ! LDR R1, [R2, #16] ! END Value Address 0x10 0x4000 0000 0x20 0x4000 0004 0x30 0x4000 0008 0x50 0x4000 000C 0x4000 0010 0x45 0x4000 0014 0xFF 0x4000 0018

Post Indexed Load Instruction Post Indexed Load Instruction Syntax : LDR 1, [ 2 ] , 3 1 : register that will receive value 2 : register containing pointer to memory 3 : numerical offset in bytes or another shifted index register This instruction will take 2 step 1) Register “1” loads the value from the memory pointed by the pointer in “2” 2) “2” is updated by computed sum of “2” and “3” Example : Let R1 = 0x4000 0000 LDR R0, [ R1 ], #0x12 Load R0  mem[ R1] ; R0  mem [0x4000 0000] Update base register : R1  R1 + 0x12 ; now R1 = 0x4000 0012

Example 3 Given a table of memory address and its stored data, What the value in R0, R1 and R2 after execution the programs AREA ex3, CODE, READONLY ENTRY start LDR R2, =0x40000000 MOV R3, #4 LDR R0, [R2], R3 LDR R1, [R2], #16 END Value Address 0x10 0x4000 0000 0x20 0x4000 0004 0x30 0x4000 0008 0x50 0x4000 000C 0x4000 0010 0x45 0x4000 0014 0xFF 0x4000 0018

Data Transfer : Register to Memory For storing data in register to memory, we will use STR instruction STR instruction syntax is identical to LDR instruction syntax STR : store from register, so 32 bits or one word are stored from register to memory at a time Example : Let R1 = 0x4000 0000, R2 = 0x8 STR R0, [R1, #0x12] Store R0  mem[ R1 + 0x12 ] ; R0  mem [0x4000 0012] STR R0, [R1, R2] Store R0  mem[ R1 + R2] ; R0  mem [0x4000 0008]

Pre Indexed Store Instruction Pre Indexed Store Instruction Syntax : STR 1, [ 2, 3]! 1 : register that will send value 2 : register containing pointer to memory 3 : numerical offset in bytes or another shifted index register This instruction will take 2 step 1) Register “1” stores the value to the memory pointed by the pointer in “2”, add “3” bytes 2) “2” is updated by computed sum of “2” and “3” Example : Let R1 = 0x4000 0000 STR R0, [R1, #0x12] ! Store R0  mem[ R1 + 0x12 ] ; R0  mem [0x4000 0012] Update base register : R1  R1 + 0x12 ; now R1 = 0x4000 0012

Post Indexed Store Instruction Post Indexed Store Instruction Syntax : STR 1, [ 2 ] , 3 1 : register that will send value 2 : register containing pointer to memory 3 : numerical offset in bytes or another shifted index register This instruction will take 2 step 1) Register “1” stores the value to the memory pointed by the pointer in “2” 2) “2” is updated by computed sum of “2” and “3” Example : Let R1 = 0x4000 0000 STR R0, [ R1 ], #0x12 Store R0  mem[ R1] ; R0  mem [0x4000 0000] Update base register : R1  R1 + 0x12 ; now R1 = 0x4000 0012

Example 4 Complete the values in the given table of memory address and its stored data after execution the programs AREA ex4, CODE, READONLY ENTRY start MOV R0, #0xFF LDR R2, =0x40000000 MOV R3, #8 STR R0, [R2, R3] STR R0, [R2], R3 STR R0, [R2, R3] ! END Value Address 0x4000 0000 0x4000 0004 0x4000 0008 0x4000 000C 0x4000 0010 0x4000 0014

We can work with Local on-chip memory from address 0x4000 0000 ARM : Memory Map ON-CHIP RAM CODE (ROM) We can work with Local on-chip memory from address 0x4000 0000 to address 0x4000 FFFFF

Memory Alignment Don’t forget that sequential word addresses in ARM with byte addressing do not differ by 1 ARM requires that all words start at addresses that are multiples of 4 bytes 3 2 1 Aligned Not Aligned

Assignment 6 AREA hw6, CODE, READONLY ENTRY start MOV R1, #1 LDR R2, =0x40000000 MOV R3, #4 STR R1, [R2, R3]! LSL R1, #2 LSL R1, #2 STR R1, [R2, R3]! LDR R2, =0x40000000 LDR R0, [R2, #8 ]! LDR R1, [R2] , #4 ADD R0, R0, R1, LSL #4 STR R0, [R2, #4] END Solve the following expression in 4- bits register step-by-step -5 x -2 5 x -2 Complete the value in memory table after program is executed Value Address ? 0x4000 0000 0x4000 0004 0x4000 0008 0x4000 000C 0x4000 0010