TOPIC 6 AVR Addressing Modes (review).
AVR Addressing Modes. Register Direct, with 1 and 2 registers I/O Direct Data Direct Data Indirect: – with pre-decrement – with post-increment.
Register Direct : 1 register. Instruction operands involve only 1 single register.
Register Direct : 2 registers. Instruction operands (source and destination) involve only registers.
I/O Direct. Instructions are used to access I/O space i.e. I/O registers Port Address:$00 (Mem:$20) - Port Address:$3F (Mem: $5F).
Data Direct. LDS - Data loaded into a register from data space described by 16-bit addr . in opcode LDS Rd, <mem>.
Data Indirect : LD. LD – Load data from a location in data space pointed by 16-bit addr . pointer of register X, Y,or Z. into a destination register (Rd).
Data Indirect : LD. LD – Load 1 byte data from a location in data space pointed by 16-bit addr . pointer of register X, Y or Z. into a destination register (Rd). Register X, Y and Z are made out of combination of registers R26..R31. These registers are 16-bit address pointers for indirect addressing of the data space..
Data Indirect : LD/ ST. LD/ ST – Load/ Store 1 byte data from / into a location in data space pointed by 16-bit addr . pointer of register X, Y or Z. into a destination register (Rd). Register X, Y and Z are made out of combination of registers R26..R31. These registers are 16-bit address pointers for indirect addressing of the data space..
Data Indirect : LD. Data indirect uses the X, Y, Z registers as a pointer to access data location in the data memory area, purposefully at general purpose RAM (data) area. AVR ATmega32 comes with 2KB RAM, therefore the memory area is: 0x0060 – 0x03FF.
0 0 6 3 0x0063 X – r27:r26 6 3 r12. What is the difference between instructions LDS r12, 0x0063 and LD r12, X (shown above) ?.
Data Indirect : LD - Pre decrement & Post increment.
Data Indirect : LD - Pre decrement & Post increment.
Data Indirect : ST - Pre decrement & Post increment.
Data Indirect : Pre decrement & Post increment. The pre decrement and post increment feature is extremely useful as it keeps you from having to reload your pointers each time you need to access data. It is best used to access array..
Registers. r16. 01. r17. 23. VAR: .byte 4 ;reserves 4 bytes of data at location VAR ldi r16,0x01 ; r16= 01 ldi r17,0x23 ; r17 = 23 ldi r18,0x45 ; r18 = 45 ldi r19,0x67 ; r19 = 67 ldi r27,high(VAR) ; initialize X pointer ldi r26,low(VAR) ; to var address ; [R27:R26] = [X] = address VAR ; lets assume ‘VAR’ holds address is 0x0200 st X+,r16 ; store r16 to VAR+0 and increment pointer ; ( i ) store data ~ VAR R16 , [VAR] = 0x01 ; (ii) increment pointer ~ X = VAR VAR + 1 st X+,r17 ; store r17 to var+1 and increment pointer ; ( i ) store data ~ VAR R17 , [VAR] = 0x23 ; (ii) increment pointer ~ X = VAR VAR + 1 st X+,r18 ; store r18 to var+2 and increment pointer.
45. X= VAR. $0203. VAR: .byte 4 ;reserves 4 bytes of data at location VAR : : : : : continue from previous slide st X+,r18 ; store r18 to var+2 and increment pointer ; ( i ) store data ~ VAR R18 , [VAR] = 0x45 ; (ii) increment pointer ~ X = VAR VAR + 1 st X+,r19 ; store r19 to var+3 and increment pointer ; ( i ) store data ~ VAR R19 , [VAR] = 0x67 ; (ii) increment pointer ~ X = VAR VAR + 1.
r26. r27. 03. VAR: .byte 4 ;reserves 4 bytes of data at location VAR : : : : : continue from previous slide ld r3,-X ; decrement pointer and load var+3 to r3 ; ( i ) decrement pointer ~ X = VAR VAR – 1 ; (ii) load data ~ R3 VAR , R3=[$203] ld r2,-X ; decrement pointer and load var+2 to r2 ; ( i ) decrement pointer ~ X = VAR VAR – 1 ; (ii) load data ~ R2 VAR , R2=[$202] ld r1,-X ; decrement pointer and load var+1 to r1 ; ( i ) decrement pointer ~ X = VAR VAR – 1 ; (ii) load data ~ R1 VAR , R1=[$201] ld r0,-X ; decrement pointer and load var+0 to r0.
Data Indirect With displacement – LDD / STD. This functionality on Data Indirect addressing mode only uses register Y and Z.
Data Indirect With displacement – LDD / STD. LDI R16, 0x55 STS 0x0230, R16 LDI YH,0x02 LDI YL, 0x20 ;Y=$220 LDD R3, Y + 0x10 ; pointer =Y + 0x10 = $0230 ; R3 DS($0230) ;R3 = 0x55 LDI ZH,0x03 LDI ZL, 0x00 ;Z =$300 STD Z+10, R3 ;[ 310]=$55.
Data Indirect: Summary. Table 5: AVR Auto-Increment/Decrement of Pointer Registers for LD Instruction Instruction LD LD LD LD LD LD LDD LD LD LD LDD Rn,x Rn,X+ Rn,-x Rn,Y Rn,Y+ Rn,-Y Rn,Y+q Rn,Z Rn,Z+ Rn,-Z Rn,Z+q Function After loading location pointed to by X, the X stays the same. After loading location pointed to by X, the X is incremented. The X is decremented, then the location pointed to by X is loaded. After loading location pointed to by Y, the Y stays the same. After loading location pointed to by Y, the Y is incremented. The Y is decremented, then the location pointed to by Y is loaded. After loading location pointed to by Y+q, the Y stays the same. After loading location pointed to by Z, the Z stays the same. After loading location pointed to by Z, the Z is incremented. The Z is decremented, then the location pointed to by Z is loaded. After loading location pointed to by Z+q, the Z stays the same..
Instruction & Memory Space: Summary.