This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revision | |||
| en:multiasm:piot:chapter_4_5 [2026/02/17 15:19] – ToDo checked: Marcin, czy tu nie brakuje rysunku? jtokarz | en:multiasm:piot:chapter_4_5 [2026/02/19 18:10] (current) – jtokarz | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== 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, | ||
| + | |||
| + | Details on addressing modes are presented in Fig. {{ref> | ||
| + | |||
| + | **1. Direct Single Register Addressing** | ||
| + | |||
| + | <figure avr_addr_1> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The operand is contained in the destination register (Rd). | ||
| + | |||
| + | **2. Direct Register Addressing, Two Registers** | ||
| + | |||
| + | <figure avr_addr_2> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Operands are contained in the source register (Rr) and destination register (Rd). The result is stored in the destination register (Rd). | ||
| + | |||
| + | **3. I/O Direct Addressing** | ||
| + | |||
| + | <figure avr_addr_3> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Operand address A is contained in the instruction word. Rr/Rd specifies the destination or source register. | ||
| + | |||
| + | **4. Data Direct Addressing** | ||
| + | |||
| + | <figure avr_addr_4> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | A 16-bit Data Address is contained in the 16 LSBs of a two-word instruction. Rd/Rr specify the destination or source register. The LDS instruction uses the RAMPD register to access memory above 64 KB. | ||
| + | |||
| + | **5. Data Indirect Addressing** | ||
| + | |||
| + | <figure avr_addr_5> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The operand address is the contents of the X-, Y-, or Z-pointer. In AVR devices without SRAM, Data Indirect Addressing is called Register Indirect Addressing. | ||
| + | |||
| + | **6. Data Indirect Addressing with Pre-decrement** | ||
| + | |||
| + | <figure avr_addr_6> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The X,- Y-, or the Z-pointer is decremented before the operation. The operand address is the decremented contents of the X-, Y-, or Z-pointer. | ||
| + | |||
| + | **7. Data Indirect Addressing with Post-increment** | ||
| + | |||
| + | <figure avr_addr_7> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The X-, Y-, or Z-pointer is incremented after the operation. The operand address is the content of the X-, Y-, or Z-pointer before incrementing. | ||
| + | |||
| + | **8. Data Indirect with Displacement** | ||
| + | |||
| + | <figure avr_addr_8> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The operand address is the result of the q displacement contained in the instruction word added to the Y- or Z-pointer. Rd/Rr specify the destination or source register. | ||
| + | |||
| + | **9. Program Memory Constant Addressing** | ||
| + | |||
| + | <figure avr_addr_9> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The byte address in program memory is determined by the value stored in the Z-pointer. | ||
| + | |||
| + | The upper 15 bits (Most Significant bits - MSbs) select the word address (each word contains 2 bytes). | ||
| + | |||
| + | The lowest bit (Less Significant bit - LSb) selects which byte of that word is used: | ||
| + | |||
| + | * 0 → low byte, | ||
| + | |||
| + | * 1 → high byte. | ||
| + | |||
| + | 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. | ||
| + | ELPM (Extended Load Program Memory) is an instruction used to read bytes from program memory when the memory is larger than 64 KB. | ||
| + | The normal LPM instruction can only access 64 KB because it uses the 16‑bit Z register. | ||
| + | ELPM adds extra address bits from the RAMPZ register, allowing access to extended program memory on larger AVR devices. | ||
| + | |||
| + | In short: | ||
| + | ELPM = LPM with support for large program memory using RAMPZ. | ||
| + | |||
| + | |||
| + | **10. Program Memory Addressing with Post-increment** | ||
| + | <todo @pczekalski> | ||
| + | <todo @mfojcik # | ||
| + | |||
| + | <figure avr_addr_10> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | The Z-pointer contents specify a constant byte address. The 15 MSbs select the word address. The LSb selects the low byte if cleared (LSb == 0) or the high byte if set (LSb == 1). If ELPM Z+ is used, the RAMPZ Register is used to extend the Z-register. | ||
| + | |||
| + | **11. Store Program Memory** | ||
| + | <todo @mfojcik> | ||
| + | <figure avr_addr_11> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | 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. | ||
| + | |||
| + | **12. Direct Program Memory Addressing** | ||
| + | |||
| + | <figure avr_addr_12> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Program execution continues at the address immediate in the instruction word. | ||
| + | <todo @mfojcik> | ||
| + | |||
| + | **13. Indirect Program Memory Addressing** | ||
| + | |||
| + | <figure avr_addr_13> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Program execution continues at the address contained by the Z-register (i.e., the PC is loaded with the contents of the Z-register). | ||
| + | |||
| + | **14. Extended Indirect Program Memory Addressing** | ||
| + | |||
| + | <figure avr_addr_14> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | 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). | ||
| + | |||
| + | **15. Relative Program Memory Addressing** | ||
| + | |||
| + | <figure avr_addr_15> | ||
| + | {{ : | ||
| + | < | ||
| + | </ | ||
| + | |||
| + | Program execution continues at the address PC + k + 1. The relative address k is from -2048 to 2047. | ||