131 Week 14 - Memory Flashcards
Cortex-M3 memory map
Cortex-M3 processor is a memory-mapped system.
It has a fixed linear memory map of 4 gigabytes of addressable memory space.
It has dedicated address ranges for code (code space), SRAM (memory space), external memories/devices and internal/external peripheral.
Cortex-M3 memory layout
The stack (SRAM region) stores all local variables and function arguments. The stack pointer register points at the bottom.
The heap (SRAM region) stores data allocated during runtime (e.g. malloc).
The global data (SRAM region) area stores global variables. ARM uses R9 as the static base pointer (SB).
Global contains the bss area (uninitialized global data).
The text segment (CODE region) stores the machine language program.
ARM ISA memory
ARM uses a byte-addressable memory (Each byte has a unique address)
1 word = 32 bits = 4 bytes
Loading from memory
Can load from memory using ldr the syntax:
ldr destinationRegister [baseAddress, offset]
E.g., ldr r0, [r2, #100]
Storing to memory
Can load from memory using ldr the syntax:
str sourceRegister [baseAddress, offset]
E.g., str r0, [r2, #100]
Storing keywords
Base Address: the starting address before the offset is added
Offset: the value to add to the base address to get a new address.
Addressing modes
reg+const mode: use a register and a constant to compute the read/write address. E.g., ldr r0, [r1, #20]
reg+reg mode: use the sum of 2 registers to compute the read/write address. E.g., ldr r0, [r1, r2]
reg+reg«scale: shift the second register parameter and add to the
first register, to compute the read/write address. E.g., ldr r0, [r1, r2, LSL #2]
Memory layout and directives
.bss: Contains statically allocated variables that are declared but have not been assigned a value yet.
.data: Contains initialized static variables, i.e., global variables and static local variables set to a value.
.rodata: Contains initialized static variables that constant.
.text: Contains the executable instructions
Data types directives
.word: 4-byte integer.
.byte: 1 byte integer.
.ascii: quote enclosed string.
.asciz: null-terminated string.
.fill repeat, size, value: fills memory with a repeated value of size bytes.
.zero size: fill memory with zeroes.
Defining data in memory
.region
label: .type optionalValue
where:
.region specifies the region where data is stored
label is a name to reference the data
.type is an optional data type to help the assembler to
allocate appropriate space
value is an optional value to initialize memory
E.g.,
.section .data
test1: .word 0x11223344
Loading a label from memory
Use
ldr destinationRegister, labelName
to load a label from memory into a register
E.g.,
ldr r0, =test1
Addressing specific memory
ldrb (load byte): access individual byte in memory, zero extend.
ldrsb (load signed byte): access individual byte in memory, sign extend.
strb (store byte): stores the least significant byte of the 32-bit register into the specified byte address in memory.
ldrh (load halfword): access 16-bits from memory, zero extend.
ldrsh (load signed halfword): access 16-bits in memory, sign extend.
strh (store halfword): stores the least significant 16-bits of the 32-bit register into the specified byte address in memory.
Extend modes for memory addressing
Zero extend: remaining bits are filled with zeros after loading the byte.
Sign extend remaining bits are filled with the sign bit (most significant byte).