This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:multiasm:piot:chapter_4_5 [2026/03/01 19:00] – [Program Memory Addressing with Post-increment] ktokarz | en:multiasm:piot:chapter_4_5 [2026/03/01 19:43] (current) – [Addressing Modes] ktokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Addressing Modes ====== | ====== Addressing Modes ====== | ||
| - | Addressing modes define how the processor accesses data. There are 15 different addressing modes, such as: Direct Addressing, Indirect Addressing, Indirect with Displacement, | + | Addressing modes define how the processor accesses data and the target address of a jump. There are more than a dozen different addressing modes, such as: Direct Addressing, Indirect Addressing, Indirect with Displacement, |
| - | + | ||
| - | Details on addressing | + | |
| =====Direct Single Register Addressing===== | =====Direct Single Register Addressing===== | ||
| - | Direct single register addressing informs the processor that the instruction' | + | Direct single register addressing informs the processor that the instruction' |
| <code asm> | <code asm> | ||
| inc R0 | inc R0 | ||
| + | ldi R2, 0x05 | ||
| </ | </ | ||
| Line 56: | Line 55: | ||
| =====Data Indirect Addressing===== | =====Data Indirect Addressing===== | ||
| - | Indirect addressing uses the content of an index register as a pointer to memory. As shown in Fig {{ref> | + | Indirect addressing uses the content of an index register as a pointer to memory. As shown in Fig {{ref> |
| An example of the instruction is load data from memory addressed with an X pointer. | An example of the instruction is load data from memory addressed with an X pointer. | ||
| <code asm> | <code asm> | ||
| Line 105: | Line 104: | ||
| =====Program Memory Constant Addressing===== | =====Program Memory Constant Addressing===== | ||
| - | With this addressing mode, it is possible to read the byte from the program memory. As shown in Fig {{ref> | + | With this addressing mode, it is possible to read the byte from the program memory. As shown in Fig {{ref> |
| The upper 15 bits (Most Significant bits - MSbs) select the word address (each word contains 2 bytes). | The upper 15 bits (Most Significant bits - MSbs) select the word address (each word contains 2 bytes). | ||
| Line 124: | Line 123: | ||
| LPM R2, Z | LPM R2, Z | ||
| </ | </ | ||
| - | |||
| - | Some versions of AVR microcontrollers allow for writing to the program memory (Flash). They implement the **spm** (Store Program Memory) instruction. Normally, Flash is read‑only during program execution, but **spm** allows the microcontroller to modify or update its own program, for example, inside a bootloader. | ||
| - | For the **spm** instruction, | ||
| When the **elpm** instruction is used, the RAMPZ register provides extra address bits so the processor can access larger program memories. | When the **elpm** instruction is used, the RAMPZ register provides extra address bits so the processor can access larger program memories. | ||
| Line 153: | Line 149: | ||
| - | =====Store Program Memory===== | + | =====Store Program Memory |
| - | <todo @mfojcik> | + | Some versions of AVR microcontrollers allow for writing to the program memory (Flash). They implement the **spm** (Store Program Memory) instruction. Normally, Flash is read‑only during program execution, but **spm** allows the microcontroller to modify or update its own program, for example, inside a bootloader. |
| + | As visible in Fig {{ref> | ||
| + | |||
| + | <todo @mfojcik> | ||
| <figure avr_addr_11> | <figure avr_addr_11> | ||
| {{ : | {{ : | ||
| Line 160: | Line 159: | ||
| </ | </ | ||
| - | The Z-pointer is incremented by 2 after the operation. The Z-pointer contents specify a constant byte address before incrementing. The 15 MSbs select the word address, and the LSb should be left cleared. | ||
| =====Direct Program Memory Addressing===== | =====Direct Program Memory Addressing===== | ||
| + | This addressing mode does not address data but rather modifies the program execution flow. It is used in jump and subroutine call instructions. These instructions use the constant immediate to specify the absolute target address to jump to. As shown in Fig {{ref> | ||
| + | <code asm> | ||
| + | CALL function | ||
| + | </ | ||
| <figure avr_addr_12> | <figure avr_addr_12> | ||
| Line 169: | Line 171: | ||
| </ | </ | ||
| - | Program execution continues at the address immediate in the instruction word. | + | <todo @mfojcik> |
| - | <todo @mfojcik> | + | |
| =====Indirect Program Memory Addressing===== | =====Indirect Program Memory Addressing===== | ||
| + | The target address of the jump or call can be stored in the Z pointer register. After **ijmp** or **icall**, program execution continues at the address contained by the Z register (i.e., the PC is loaded with the contents of the Z register). It is shown in Fig {{ref> | ||
| + | <code asm> | ||
| + | ICALL | ||
| + | </ | ||
| <figure avr_addr_13> | <figure avr_addr_13> | ||
| {{ : | {{ : | ||
| Line 179: | Line 183: | ||
| </ | </ | ||
| - | Program execution continues at the address contained by the Z-register (i.e., the PC is loaded with the contents of the Z-register). | + | |
| =====Extended Indirect Program Memory Addressing===== | =====Extended Indirect Program Memory Addressing===== | ||
| + | For versions of AVR microcontrollers with bigger program memory than 128 kB, additional bits used to extend the address are stored in the EIND register. Program execution continues at the address contained by the Z register and the EIND register (i.e., the PC is loaded with the contents of the EIND and Z register) as shown in fig {{ref> | ||
| <figure avr_addr_14> | <figure avr_addr_14> | ||
| Line 188: | Line 193: | ||
| </ | </ | ||
| - | Program execution continues at the address contained by the Z-register and the EIND-register (i.e., the PC is loaded with the contents of the EIND and Z-register). | ||
| =====Relative Program Memory Addressing===== | =====Relative Program Memory Addressing===== | ||
| + | If the target address is within the range of -2048 to 2047 from the current address, the shorter relative control transfer instructions can be used. | ||
| + | As shown in fig {{ref> | ||
| + | <code asm> | ||
| + | RJMP target | ||
| + | </ | ||
| <figure avr_addr_15> | <figure avr_addr_15> | ||
| {{ : | {{ : | ||
| Line 197: | Line 205: | ||
| </ | </ | ||
| - | Program execution continues at the address PC + k + 1. The relative address k is from -2048 to 2047. | + | |