cv | links | blog | quotes | ascii | tgtimes | gopher | mail | rss


MCU with AVR 8-bit architecture.

ATmega328P on Elegoo Nano

Can still use 16-bit addresses through "pointer registers" pair of register splitting upper and lower bits: X (R26 low, R27 high), Y (R28 low, R29 high), Z (R30 low, R31 high).

IO(0x0000-0x001F) - IO Space

Addresses for communicating through the MCU pins. Every bit are mapping to one pin, grouped into ports.

When using the I/O specific commands IN and OUT, the I/O addresses 0x00 - 0x3F must be used. When addressing I/O registers as data space using LD and ST instructions, 0x20 must be added to these addresses.

Encountered as #define __SFR_OFFSET 0x20 in avr/sfr_defs.h.

IO(0x003E-0x003F) - Stack pointer

16-bit address to the top of the stack, which must be set before the stack memory gets used. By default, the crt.o file for the ATmega328p of AVR-gcc is already setting it (used from C and ASM), so no need to set it by hand:

$ avr-objdump -d -j .init2 avr/lib/avr5/crtatmega328p.o

00000000 <.init2>:
   0:   11 24           eor     r1, r1
   2:   1f be           out     0x3f, r1        ; SREG = 0x01
   4:   c0 e0           ldi     r28, 0x00       ; 0
   6:   d0 e0           ldi     r29, 0x00       ; 0
   8:   de bf           out     0x3e, r29       ; SPL = 0x00
   a:   cd bf           out     0x3d, r28       ; SPH = 0x00

PROG(0x0000-0x0032) - Interrupt handlers addresses

--- #draft