Declaring Pointers for Different Addressing Types
Learn how pointers are used to address memory cells and registers, and learn about addressing different memory granularity in assembly language.
We'll cover the following
Pointers revisited
The pointer is a memory cell or a register that contains the address of another memory cell. Memory pointers have their own addresses because they are memory cells too. On a 32-bit Linux, pointers are 32-bit, and on a 64-bit Linux, pointers are 64-bit.
Addressing types
Memory cells can be of one byte, half word, word, or double word sizes. Therefore, we can have a pointer to a byte, a pointer to a half word, a pointer to a word, and a pointer to a double word. If we want to load or store, we would use the following:
-
Byte: We use
LDRB
/STRB
instructions andw
-registers for storing the data. -
Half word: We use
LDRH
/STRH
instructions andw
-registers for storing the data. -
Word: We use
LDR
/STR
instructions andw
-registers for storing the data. -
Double word: We use
LDR
/STR
instructions andx
-registers for storing the data.
We always use x
-registers for memory addresses.
Here are some illustrated examples:
Get hands-on with 1400+ tech skills courses.