ARM Load/Store Instructions

Slides:



Advertisements
Similar presentations
Appendix D The ARM Processor
Advertisements

Wat gaan we doen? harhaling data types
Run-time Environment for a Program different logical parts of a program during execution stack – automatically allocated variables (local variables, subdivided.
Embedded System Design Center Sai Kumar Devulapalli ARM7TDMI Microprocessor Load and store instruction.
Introduction to Embedded Systems Intel Xscale® Assembly Language and C Lecture #3.
COMP3221 lec-12-mem-II.1 Saeid Nooshabadi COMP 3221 Microprocessors and Embedded Systems Lecture 12: Memory Access - II
Multiple data transfer instructions ARM also supports multiple loads and stores: ldm/ldmia/ldmfd: load multiple registers starting from [base register],
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.
Agenda Introduction Architecture Programmers Model Instruction Set
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.
Advanced RISC Machines
Subroutines and Stacks 1. Subroutines Separate, independent module of program, performs a specific task shortens code, provide reusable “tools” High-level.
ARM Assembly Programming Computer Organization and Assembly Languages Yung-Yu Chuang 2007/11/19 with slides by Peng-Sheng Chen.
Lecture 4. ARM Instructions #1 Prof. Taeweon Suh Computer Science Education Korea University ECM586 Special Topics in Embedded Systems.
Chapter 3-1 ARM ISA ARM Instruction Set Architecture ARM Instruction Set Architecture Next Lecture Next Lecture  ARM program examples.
Lecture 4. ARM Instructions Prof. Taeweon Suh Computer Science & Engineering Korea University COMP427 Embedded Systems.
Lecture 3. ARM Instructions Prof. Taeweon Suh Computer Science Education Korea University ECM583 Special Topics in Computer Systems.
Lecture 8: Control, Procedures, and the Stack CS 2011 Fall 2014, Dr. Rozier.
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
ECS642U Embedded Systems ARM CPU and Assembly Code William Marsh.
嵌入式處理器架構與程式設計 王建民 中央研究院 資訊所 2008 年 7 月. 2 Contents Introduction Computer Architecture ARM Architecture Development Tools  GNU Development Tools ARM Instruction.
Unit-2 Instruction Sets, CPUs
More on Assembly 1 CSE 2312 Computer Organization and Assembly Language Programming Vassilis Athitsos University of Texas at Arlington.
Lecture 8: Loading and Storing to Memory CS 2011 Fall 2014, Dr. Rozier.
Assembly Variables: Registers Unlike HLL like C or Java, assembly cannot use variables – Why not? Keep Hardware Simple Assembly Operands are registers.
Arrays In high-level languages, we have several technigues available for constucting data stuctures: −One-dimensional arrays −Multi-dimensional arrays.
Lecture 10: Load/Store cont. and Integer Arithmetic CS 2011 Fall 2014, Dr. Rozier.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
ARM Instruction Set Computer Organization and Assembly Languages Yung-Yu Chuang with slides by Peng-Sheng Chen.
Multiple data transfer instructions ARM also supports multiple loads and stores: When the data to be copied to the stack is known to be a multiple of 4.
Intel Xscale® Assembly Language and C. The Intel Xscale® Programmer’s Model (1) (We will not be using the Thumb instruction set.) Memory Formats –We will.
ARM Programming CMPE 450/490 ©2010 Elliott, Durdle, Minderman
Displacement (Indexed) Stack
Main features of the ARM Instruction Set
ARM Assembly Language Programming
Instruction sets : Addressing modes and Formats
Chapter 4 Copying Data.
Chapter 15: Higher Level Constructs
ECE 3430 – Intro to Microcomputer Systems
The Stack.
Introduction to the ARM Instruction Set
ARM Registers Register – internal CPU hardware device that stores binary data; can be accessed much more rapidly than a location in RAM ARM has.
ECE 3430 – Intro to Microcomputer Systems
The Cortex-M3/m4 Embedded Systems: Cortex-M3/M4 Instruction Sets
The Stack.
The ARM Instruction Set
Chapter 4 Addressing modes
Chapter 10 And, Finally... The Stack
William Stallings Computer Organization and Architecture 8th Edition
The Stack.
Arithmetic using a stack
ECM586 Special Topics in Embedded Systems Lecture 4. ARM Instructions
ARM Arrays.
Chapter 10 And, Finally... The Stack
Computer Organization and Assembly Languages Yung-Yu Chuang 2008/11/17
ARM Introduction.
Overheads for Computers as Components 2nd ed.
ARM ORGANISATION.
Computer Architecture
Multiply Instructions
Computer Organization and Assembly Language
Introduction to Assembly Chapter 2
ARM Load/Store Instructions
An Introduction to the ARM CORTEX M0+ Instructions
8/23/
(The Stack and Procedures)
Presentation transcript:

ARM Load/Store Instructions The ARM is a Load/Store Architecture: Only load and store instructions can access memory Does not support memory to memory data processing operations. Must move data values into registers before using them. All instructions other than these can only use values in registers

ARM Load/Store Instructions ARM has three sets of instructions which interact with main memory. These are: Single register data transfer (LDR/STR) Block data transfer (LDM/STM) Single Data Swap (SWP)

ARM Single Register Load/Store Instructions The basic load and store instructions are: LDR STR Word LDRB STRB Byte LDRH STRH Halfword LDRSB Signed byte load LDRSH Signed halfword load

ARM Single Register Load/Store Instructions Memory system must support all access sizes Syntax: LDR{<cond>}{<size>} Rd, <address> STR{<cond>}{<size>} Rd, <address> e.g. LDR R0, [R1] STR R0, [R1] LDREQB R0, [R1]

Data Transfer: Memory to Register (load) To transfer a word of data, we need to specify two things: Register: r0 - r15 Memory address: more difficult Think of memory as a single one-dimensional array, so we can address it simply by supplying a pointer to a memory address. There are times when we will want to offset from this pointer.

ARM Addressing Modes There are basically two types of addressing modes available in ARM Pre-indexed addressing: the address generated is used immediately Post-indexed addressing: the address generated later replaces the base register

Destination Register for ldr ARM Addressing Modes [Rn] Register Address accessed is value found in Rn. Example: ldr r0, [r1] @ r0 *r1 Memory 0x5 . 0x200 r1 r0 0x5 Destination Register for ldr .

ARM Addressing Modes (Pre-Indexing) [Rn, #±imm] Immediate offset Address accessed is imm more/less than the address found in Rn. Rn does not change. Example: ldr r2, [r1, #12] @ r2 ← *(r1 + 12) Memory 27 . 27 r2 200 r1 188 Destination Register for ldr

ARM Addressing Modes (Pre-Indexing) [Rn, ±Rm] Register offset Address accessed is the value in Rn ± the value in Rm. Rn and Rm do not change values. Example: ldr r2, [r0, r1] @ r2 ← *(r0 + r1)

ARM Addressing Modes (Pre-Indexing) [Rn, ±Rm, shift] Scaled register offset Address accessed is the value in Rn ± the value in Rm shifted as specified. Rn and Rm do not change values. Example: ldr r0, [r1, r2, lsl #2] @ r0 ← *(r1 + r2*4)

ARM Addressing Modes (Pre-Indexing w\ update [Rn, #±imm]! Immediate pre-indexed w\update Address accessed is as with immediate offset mode, but Rn's value updates to become the address accessed. Example: ldr r2, [r1, #12]! @ r1 ← r1 + 12 then r2 ← *r1

ARM Addressing Modes (Pre-Indexing w\ update [Rn, ±Rm]! Register pre-indexed w\update Address accessed is as with register offset mode, but Rn's value updates to become the address accessed. Example: ldr r2, [r0, r1]! @ r0 ← r0 + r1 then r2 ← *r0

ARM Addressing Modes (Pre-Indexing w\ upadate [Rn, ±Rm, shift]! Scaled register pre-indexed w\update Address accessed is as with scaled register offset mode, but Rn's value updates to become the address accessed. Example: ldr r2, [r0, r1, lsl #2]! @ r0 ← r0 + r1*4 then r2 ← *r0

ARM Addressing Modes (Post-Indexing) [Rn], #±imm Immediate post-indexed Address accessed is value found in Rn, and then Rn's value is increased/decreased by imm. Example: str r2, [r1], +4 @ *r1 ← r2 then r1 ← r1 + 4

ARM Addressing Modes (Post-Indexing) [Rn], ±Rm Register post-indexed Address accessed is value found in Rn, and then Rn's value is increased/decreased by Rm. Example: str r0, [r1], r2 @ *r1 ← r0 then r1 ← r1 + r2

ARM Addressing Modes (Post-Indexing) [Rn], ±Rm, shift Scaled register post-indexed Address accessed is value found in Rn, and then Rn's value is increased/decreased by Rm shifted according to shift. Example: ldr r0, [r1], r2, lsl #3 @ r0 ← *r1 then r1 ← r1 + r2*8

Examples of pre- and post- indexed addressing str r3, [r0, r4, lsl #3] ldr r5, [r0, r1, lsl #3]! ldr r0, [r1, #-8] ldr r0, [r1, -r2, lsl #2] ldrb r5, [r1] ldrsh r5, [r3] ldrsb r5, [r3, #0xc1] str r7, [r0], #4 ldr r2, [r0], r4, lsl #2 ldrh r3, [r5], #2 strh r2, [r5], #8 @ pre-indexed @ pre indexed with writeback @ pre-indexed with negative offset @ negative offset shifted @ load byte from ea <r1> @ load signed halfword from ea <r3> @ load signed byte from ea <r3+193> @ store r7 to ea<r0>, then add #24 to r0 @ load r2 from ea<r0>, then add r4*4 to r0 @ load halfword to r3 from ea<r5>, then @ add #2 to r5 @ store halfword from r2 to ea<r5>, then @ add 8 to r5

Block Data (Multiple data) transfer instructions ARM also supports multiple loads and stores: When the data to be copied to the stack is known to be a multiple of 4 bytes, copying is faster using load multiple and store multiple instructions. Each instruction can transfer 1 or more 32-bit words between registers and memory Each instruction updates another register that holds the memory address

Multiple data transfer instructions General syntax: op<address-mode>{cond} <rn>{!}, <register-list>{^} op : ldm, stm address-mode: ia – Increment address after each transfer ib – Increment address before each transfer. da – Decrement address after each transfer db – Decrement address before each transfer fd – full descending stack ed – empty descending stack fa – full ascending stack ea – empty ascending stack.

Multiple data transfer instructions cond is an optional condition code rn is the base register containing the initial memory address for the transfer. ! is an optional suffix. If ! is present, the final address is written back into rn. If the base register is in the register-list, then you must not use the writeback option.

Multiple data transfer instructions reg-list a list of registers to be loaded or stored. can be a comma-separated list or an rx-ry range. may contain any or all of r0 - r15 the registers are always loaded in order, regardless to how the registers are ordered in the list. for both the ldm and stm instructions, reg-list must not contain the sp for ldm, reg-list must not contain the PC if it contains the lr for stm, reg-list must not contain the lr if it contains the pc

Multiple data transfer instructions ^ is an optional suffix. Do NOT use it in User mode or System mode. - forces processor to transfer the saved program status register (SPSR) into the current program status register (CPSR) at the same time, saving us an instruction - if op is LDM and register-list contains the pc, the CPSR is restored from the SPSR - otherwise, data is transferred into or out of the User mode registers instead of the current mode registers.

Multiple data transfer instructions Operation [s] Notes ldmia rn[!],<reglist> rfirst<- mem[rn] rfirst+1<- mem[rn+4] rfirst+2<- mem[rn+8] etc. rfirst, rlast … refer to the order of the registers by register number, not by the order they apprear in the list '!' is an optional write-back suffix. If present, the final address that is written to or stored from is written back into rn ldmdb rlast[!],<reglist> rlast<- mem[rn] rlast-1<- mem[rn- 4] rlast-2<- mem[rn- 8] stmia rn[!],<reglist> mem[rn] <- rfirst mem[rn+4] <- rfirst+1 mem[rn+8] <- rfirst+2 stmdb rn[!],<reglist> mem[rn] <- rlasst mem[rn- 4] <- rlast-1 mem[rn- 8] <- rlast-2

Multiple data transfer instructions Example of ldmia – load, increment after ldmia r9, {r0-r3} // register 9 holds the // base address. “ia” says // increment the base addr // after each value has // been loaded from memory

Multiple data transfer instructions Example of ldmia – load, increment after ldmia r9, {r0-r3} // register 9 holds the // base address This has the same effect as four separate ldr instructions, or ldr r0, [r9] ldr r1, [r9, #4] ldr r2, [r9, #8] ldr r3, [r9, #12] Note: at the end of the ldmia instruction, register r9 has not been changed. If you wanted to change r9, you could simply use ldmia r9!, {r0-r3, r12}

Multiple register data transfer instuctions ldmia – Example 2 ldmia r9, {r0-r3, r12} Load words addressed by r9 into r0, r1, r2, r3, and r12 Increment r9 after each load. Example 3 ldmia r9, {r5, r3, r0-r2, r14} load words addressed by r9 into registers r0, r1, r2, r3, r5, and r14. ldmib, ldmda, ldmdb work similar to ldmia Stores work in an analogous manner to load instructions

PUSH and POP Note: push is a synonym for stmdb sp!, reg-list pop is a synonym for ldmia sp!, reg-list ldmfd is a synonym for ldmia stmfd is a synonym for stmdb

Multiple register data transfer instuctions Common usage of multiple data transfer instructions Stack Function calls Context switches Exception handlers

Multiple register data transfer instructions Stack When making nested subroutine calls, we need to store the current state of the processor. The multiple data transfer instructions provide a mechanism for storing state on the runtime stack (pointed to by the stack pointer, r13 or sp) stack addressing: – stacks can ascend or descend memory – stacks can be full or empty – ARM multiple register transfers support all forms of the stack

Multiple register data transfer instructions Stack Ascending stack: grows up Descending stack: grows down A stack pointer (sp) holds the address of the current top of the stack Full stack: sp is pointing to the last valid data item pushed onto the stack Empty stack: sp is pointing to the vacant slot where the next data item will be placed

Multiple register data transfer instructions Stack Processing ARM support for all four forms of stacks Full ascending (FA): grows up; stack pointer points to the highest address containing a valid data item Empty ascending (EA): grows up; stack pointer points to the first empty location Full descending (FD): grows down; stack pointer points to the lowest address containing a valid data item Empty descending (ED): grows down; stack pointer points to the first empty location below the stack

Load and Store Multiples IA r1 Increasing Address r4 r0 r10 IB DA DB LDMxx r10, {r0,r1,r4} STMxx r10, {r0,r1,r4} Base Register (Rb) Several aliases for stack usage are allowed for instance: LDMFD -> LDMIA STDFD -> STMDB

Stack push operation: stmfd STMFD r13!, {r4-r7} – Push R4,R5,R6 and R7 onto the stack.

Stack pop operation: ldmed LDMFD r13!, {r4-r7} – Pop R4,R5,R6 and R7 from the stack.