Topic: Course Name: Embedded System Design With ARM
Topic: Course Name: Embedded System Design With ARM
Topic
Lecture 8: ARM Instruction Set (Part 2)
Data transfer instructions
3
• All ARM data transfer instructions use register indirect addressing.
• Before any data transfer, some register must be initialized with a memory address.
ADRL r1,Table ; r1 = memory address of Table
• Example:
LDR r0,[r1] ; r0 = mem[r1]
STR r0,[r1] ; mem[r1] = r0
4
• Single register loads and stores
• The simplest form uses register indirect without any offset:
LDR r0,[r1] ; r0 = mem[r1]
STR r0,[r1] ; mem[r1] = r0
• An alternate form uses register indirect with offset (limited to 4 Kbytes):
LDR r0,[r1,#4] ; r0 = mem[r1+4]
STR r0,[r1,#12] ; mem[r1+12] = r0
• We can also use auto-indexing in addition:
LDR r0,[r1,#4]! ; r0 = mem[r1+4], r1 = r1 + 4
STR r0,[r1,#12]! ; mem[r1+12] = r0, r1 = r1 + 4
5
• We can use post indexing:
LDR r0,[r1],#4 ; r0 = mem[r1], r1 = r1 + 4
STR r0,[r1],#12 ; mem[r1] = r0, r1 = r1 + 12
• We can specify a byte or half-word to be transferred:
LDRB r0,[r1] ; r0 = mem8[r1]
STRB r0,[r1] ; mem8[r1] = r0
LDRSH r0,[r1] ; r0 = mem16[r1]
STRSH r0,[r1] ; mem16[r1] = r0
6
• Multiple register loads and stores
• ARM supports instructions that transfer between several registers and memory.
• Example:
LDMIA r1,{r3,r5,r6} ; r3 = mem[r1]
; r5 = mem[r1+4]
; r6 = mem[r1+8]
• For LDMIB, the addresses will be r1+4, r1+8, and r1+12.
• The list of destination registers may contain any or all of r0 to r15.
• Block copy addressing
• Supported with addresses that can increment (I) or decrement (D), before (B)
or after (A) each transfer.
7
• Examples of addressing modes in multiple-register transfer:
LDMIA, STMIA
• Increment after
LDMIB and STMIB
• Increment before
LDMDA, STMDA
• Decrement after
LDMDB, STMDB
• Decrement before
8
• Point to note:
• ARM does not support any hardware stack.
• Software stack can be implemented using the LDM and STM family of instructions.
9
An Example
10
Memory Mapped I/O in ARM
Data
Memory
Data
Data Address I/O Port
Memory
Address
Decoder
.. I/O Port
. ..
.
Select I/O Port
Lines
11
• No separate instructions for input/output.
• The I/O ports are treated as data memory locations.
• Each with a unique (memory) address.
• Data input is done using the LDR instruction.
• Data output is done with the STR instruction.
12
13