ATmega64L
32 GPR
Groups of registers:
32 x 8-bit GPR (R0 R31); R(0:15), R(16:31), R(26:31)
1 cycle read/write various possible usage
X, Y, Z, (16 bits); indirect
addressing of instruction and
data memory
Instruction types
ARITHMETIC AND LOGIC INSTRUCTIONS
BRANCH INSTRUCTIONS
DATA TRANSFER INSTRUCTIONS
BIT AND BIT-TEST INSTRUCTIONS
MCU CONTROL INSTRUCTIONS
char a; char a, b;
a = 0x10; a = b;
============================ ================
ldi r24, 0x10 ; Load imm 10 lds r24, b ; Load from b
sts a, r24 ; Store to a sts a, r24 ; Store to a
---------------------------------------------- ----------------------------------------------
int a; int a, b;
a = 0x2030; a = b;
=========================== ===============
??? ???
Direct Program Addressing, JMP, CALL Indirect Program Addressing, IJMP, ICALL
Relative Program Addressing, RJMP, RCALL Conditional Branch short relative jump
Data Transfer Instructions - examples
Load Indirect Store Indirect
int a = *pInt; * (int*) (0x0100) = b;
============================ ===========================
; Use the Z register (R31:R30) ; Use Z register (R31:R30)
lds R30, pInt ; Load from pInt ldi r30, 0 ; load imm 0x0100
lds R31, pInt+1 ; ldi r31, 0x01 ;
ld r24, Z ; load from (*pInt) lds r24, b ; load b
ldd r25, Z+1 ; lds r25, b+1 ;
sts a, r24 ; store to a st Z, r24 ; store to 0x0100
sts a+1, r25 ; std Z+1, r25 ;
------------------------------------------------ -----------------------------------------------
CP: Rd Rr
CPC: Rd - Rr - C
Branch Instructions - examples
If-else Statement WHILE Loop
unsigned char sum, n;
char ch;
while (n<10) {
sum += n;
if (ch < 0)
n++;
ch = -1;
}
else
==================
ch = 1;
C IF version:
========================
unsigned char sum n;
lds r24, ch ; load ch
tst r24 ; test ch
loop:
brge else ; if GE goto else
if (n >= 10) goto done;
; part
sum += n;
then:
n ++;
ldi r24, -1 ; ch=-1
goto loop;
rjmp endif ; skip the else
done:
; part
=====================
else:
; assume r16=n, r3=initial value for sum
ldi r24, 1 ; ch=1
loop: cpi r16, 10
endif:
brsh next ; branch if same or higher (C==0)
sts ch, R24
add r3, r16
-----------------------------------------------
incr 16
rjmp loop
next:
Bit & Bit-test Instructions. MCU Control
Bit & Bit-test Instructions. MCU Control
Instruction formats and restrictions
AVR instructions - summary
References