ARM Memory
Owen Kaser, CS2253
Mostly corresponds to book Chapter 5.
ARM Memory Owen Kaser, CS2253 Mostly corresponds to book Chapter 5. - - PowerPoint PPT Presentation
ARM Memory Owen Kaser, CS2253 Mostly corresponds to book Chapter 5. Overview Loads and Stores Memory Maps Register-Indirect Addressing Post- and Pre-indexed Addressing 16 Registers is Not Enough So far, the only places
Owen Kaser, CS2253
Mostly corresponds to book Chapter 5.
ARM's CPU registers
data storage.
(eg, of trig functions) that are never altered
can be set at the factory. Fancy toaster: you can “flash” your toaster with improved software.
directly do calculations on values in memory. Have to load them into a CPU register to use them as inputs.
can use a store instruction to put them into memory.
should go. This will be a numeric “memory address”.
the CPU can do, to compute the memory address.
address.
values as memory addresses. Each address would correspond to a byte (oops, octet).
0xFFFFFFFF.
(boundaries are often small multiples of powers of 2)
subdivisions.
realize that some memory addresses accept stores, and some ignore them.
(extracts from book Table 5.1)
Start End Description 0x00000000 0x0003FFFF On-chip flash 0x00040000 0x00FFFFFF reserved 0x01000000 0x1FFFFFFF ROM 0x20000000 0x20007FFF (Static) RAM ….. 0x4000C000 0x4000CFFF UART 0 (a “serial port”) device ….. 0xE0001000 0xE0001FFF “data watchpoint and trace” (DWT) facility …. 0xE0004000 0xFFFFFFFF reserved
corresponds to RAM memory.
0x00005000 into register R3.
value to be zero-extended, use LDRB instruction.
data you care about. Let's go for R1.
LDRB R3, [R1] ; memory value to R3
contents of all memory locations from 0x00005000 to 0x00005FFF.
MOV R1, #0x00005000 ; starting location
MOV R2, #0x00006000; when to stop MOV R3, #0 LP STRB R3, [R1] ; wipe clear current location's value ADD R1, R1, #1 ; advance to next location TEQ R1, R2 ; has R1 hit the stopping location? BNE LP ….
(starts on a multiple of 4) and is the right size (a multiple of 4) we can clear out 4 consecutive addresses with one STR (store word) instruction.
addresses: A, A+1, A+2, A+3.
MOV R1, #0x00005000 ; starting location MOV R2, #0x00006000; when to stop MOV R3, #0 ; 4 bytes of zeros LP STR R3, [R1] ; wipe clear current location's value AND the next 3 locations' values ADD R1, R1, #4 ; advance to location of next group of 4 bytes TEQ R1, R2 ; has R1 hit the stopping location? BNE LP
address, then update the register in preparation for the next loop” is extremely common.
does BOTH of these operations in a single
STR R3, [R1] ADD R1, R1, #4
MOV R1, #0x00005000 ; starting location
MOV R2, #0x00006000; when to stop MOV R3, #0 ; 4 bytes of zeros LP STR R3, [R1], #4 ; wipe 4, then advance “pointer” R1 ADD R1, R1, #4 ; advance to location of next group TEQ R1, R2 ; has R1 hit the stopping location? BNE LP
– it uses the current version of p to index M – then it increments p. post-increment.
– it first increments p pre-increment – then then new value of p is used to index into M
(Should not be R15.)
computation
– adding/subtracting a constant (earlier example) – adding/subtracting a register
j = 0;
while (….) { sum += M[j]; j += x;}
Both do a little computation and use the computed effective address to go to memory. In one, the base register is updated. Other flavour does not update.
the base register. Don't use R15 as the base register with !
beyond the start of the current machine code. [Details
the object.
(if the object size is a power of two)
for HLLs would find useful, I think...rather than focussing on assembly language programmers)
STR r0, [r1, #12]! ; r0 ← x20c
an 8 bit value.
Then use PC-relative addressing to load it.
… 1000 bytes later... myConst DCD 0x12345678
LDR R1, [PC, #996] ; PC was already 8 ahead
memory addresses (possibly with padding)
are two 32-bit fields, then a 16-bit halfword field that we want to load into R2.
(Desired field starts 8 bytes later: gotta skip over first two words.)
array.
R1 + 4*w
put an address into a register (that you will then use as a base register). For instance, summing values in array… MOV R0, #0 ; accumulate answer ADR R1, MyArr ; Keil pseudo-op ADR R2, AfterMyArr ; past last valid address LP LDR R3, [R1], #4 ADD R0, R0, R3 TEQ R1, R2 BNE LP ….. MyArr DCD 34, 23, 56, 78, 12345566, ……... AfterMyArr DCB 0
n s t e a d
A D R , y
s h
l d b e a b l e t
h e f
l
i n g : M O V R , # ; a c c u m u l a t e a n s w e r L D R R 1 , = M y A r r L D R R 2 , = A f t e r M y A r r ; p a s t l a s t v a l i d a d d r e s s L P L D R R 3 , [ R 1 ] , # 4 A D D R , R , R 3 T E Q R 1 , R 2 B N E L P … . . M y A r r D C D 3 4 , 2 3 , 5 6 , 7 8 , 1 2 3 4 5 5 6 6 , … … . . . A f t e r M y A r r D C D ; w a s t e d w
d , c
l d a v
d . . .
constant).
the current AREA.
into Rx from this preinitialized location.
LDR R3, [R1], #4 and also STRB R3, [R1, R2, LSR #5]!
indicates which register to load. They are loaded from consecutive addresses.
the runtime stack, and will be looked at when we cover that topic.