Use LEFT and RIGHT arrow keys to navigate between flashcards;
Use UP and DOWN arrow keys to flip the card;
H to show hint;
A reads text to speech;
64 Cards in this Set
- Front
- Back
ldi |
Load register with immediate value ldi r16, $F0 ldi Rd, K Rd must be r16-r32 |
|
in |
Read value in from pin to a register in r18, PIND |
|
out |
Output value from register to port out PORTA, r16 |
|
com |
Complement a value com r4 |
|
rjmp |
Relative jump to a label. Opcode will involve offset written in two's complement form calculated by the following: [CURRENT INSTR. NO.] + 1 - [LABEL INSTR. NO.] Example: main_loop: 0003 blah blah ... 000A rjmp main_loop To calculate offset: 000A + 1 = 000B --> 000B - 0003 = 0008 Calculate 2's complement: 0000 0000 0000 1000 --> 1111 1111 1111 1000 Now add to opcode (in this case 1100 kkkk kkkk kkkk). Strip the most significant nibble: 1100 1111 1111 1000 C F F 8 Opcode for rjmp main_loop is CFF8 |
|
nop |
Do nothing. Just PC <- PC + 1 (increment program counter, i.e. move on to the next instruction) |
|
sbi |
Set bit I/O - set bit in I/O space sbi PORTB, 6 sbi DDRB, 5 |
|
cbi |
Clear bit I/O - clear bit in I/O space cbi PORTB, 6 cbi DDRB, 5 |
|
and |
AND the bits of two registers together and place result in the leftmost register Example: ldi r16, 0b11001010 ldi r17, 0b01010011 and r16, r17 In the end, we would have: r16 = 0b01000010 ;we see a 1 only when both bits had a 1 r17 = 0b01010011 ;unchanged |
|
andi |
AND immediate: AND a register with an immediate value: ldi r16, 0b11001010 andi r16, 0b01010011 Final value: r16 = 0b01000010 Can be used as a mask: andi with a bit of 0 will clear that bit |
|
or |
OR the bits of two registers together, store value in the first register Example: ldi r16, 0b11001010 ldi r17, 0b01010011 or r16, r17 In the end, we would have: r16 = 0b11011011 ;we see a 0 only when both bits had a 0 r17 = 0b01010011 ;unchanged |
|
ori |
OR immediate: OR a register with an immediate value: ldi r16, 0b11001010 ori r16, 0b01010011 Final value: r16 = 0b11011011 Can be used as a mask: ori with a bit of 1 will set that bit |
|
eor |
XOR the bits of two registers together and place result in the left-most register: Example: ldi r16, 0b11001010 ldi r17, 0b01010011 eor r16, r17 In the end, we would have: r16 = 0b10011001 ;we see a 0 when bits match r17 = 0b01010011 ;unchanged Can be used as a mask: EORing a register with another register with bits set to 1 will COMPLEMENT the equivalent bit of the first register |
|
cbr |
Clear bit in register: cbr r16, $F0 ;clear upper nibble cbr r18, 1 ;clear bit 0 |
|
sbr |
Set bit in register sbr r16, $0F ;set lower nibble sbr r16, 1 ;set bit 0 |
|
clr |
Clear all bits in register - set register = $00 clr r18 |
|
ser |
Set all bits in register - set register = $FF ser r18 |
|
lsl |
Shift all bits in register to the left - bit 0 is cleared: ldi r16, $9F; 10101111 lsl r16 ;result is r16 = 01011110 |
|
lsr |
Shift all bits in register to the right - bit 7 is cleared: ldi r16, $F5 ;11110101 lsr r16 ;01111010 |
|
rol |
Rotate left - lsl, but C flag is shifted into bit 0, and bit 7 is shifted into C flag Example: sec ;set carry flag ldi r16, $9F ;10101111 rol r16 ;result is r16 = 0101111(1), C = 1 brcs main_loop ;branch if carry set, which it is |
|
ror |
Rotate right - lsr, but C flag is shifted into bit 7, and bit 0 is shifted into C flag Example: sec ;set carry flag ldi r16, $F6 ;11110101 ror r16 ;result is (1)1111010, C=1 brcs main_loop ;branch if carry set, which it is |
|
jmp |
Absolute jump: jmp main_loop Disadvantages are that it takes 2 words and 3 cycles to execute. |
|
sbic |
Skip if bit in I/O reg is clear sbic PIND, 7 ;skips next instr if PD7 reads in a 0 rjmp main_loop ;will be executed unless PD7 = 0 This turns into an effective: if (PIND7 != 0){ rjmp main_loop; } |
|
sbis |
Skip if bit in I/O reg is set sbis PIND, 7 ;skips next instr if PD7 reads in a 1 rjmp main_loop ;will be executed unless PD7 = 1 This turns into an effective: if (PIND7 != 1){ rjmp main_loop; } |
|
sbrc |
Skip if bit in reg is clear sbrc r16, 7 ;skips next instr if r16 == 0 rjmp main_loop ;will be executed unless r16 == 0 This turns into an effective: if (r16 != 0){ rjmp main_loop; } |
|
sbrs |
Skip if bit in reg is clear sbrs r16, 7 ;skips next instr if r16 == 1 rjmp main_loop ;will be executed unless r16 == 1 This turns into an effective: if (r16 != 1){ rjmp main_loop; } |
|
lpm |
Load Program Memory - loads 1 byte from the address stored in Z (r31:r30) register into given register: lpm r16, Z ;1 byte from address in Z stored in r16 |
|
cp |
Compare two registers - set zero flag if equal cp r17, r16 ;will set zero flag if equal breq main_loop ;if equal, branch to main loop |
|
cpc |
Compare two registers... with carry - set zero flag is equal ;Compare r3:r2 with r1:r0 cp r2, r0 cpc r3, r1 breq regs_are_equal |
|
cpi |
Compare immediate, set zero flag if equal cpi r16, $0F; is r16 = 00001111? set zero flag if so breq r16_is_equal_to_0F |
|
cpse |
Compare registers, skip if equal - compare two registers, skip next instruction if they are equal: cpse r4, r0 neg r4 ;if r4 != r0, this happens nop |
|
brne |
Branch if not equal - if Z = 0, branch brne main_loop |
|
breq |
Branch if equal - if Z = 1, branch breq main_loop |
|
brsh |
Branch if same or higher (after comparing two unsigned register) cpi r16, $F0 brsh main_loop ;branch if r16 >= $F0 |
|
brlo |
Branch if lower (after comparing two unsigned registers) cpi r16, $0F brlo main_loop ;branch if r16 < $0F |
|
brcs |
Branch if carry set ldi r16, $FE ldi r17, $02 add r16, r17 brcs main_loop ;will branch, since carry set |
|
brcc |
Branch if carry clear ldi r16, $0E ldi r17, $02 add r16, r17 brcc main_loop ;will branch, since carry set |
|
mov |
Copy register on right into register on left mov r16, r17 (r16 will have value of r17, r17 unchanged) |
|
swap |
Swaps high and low nibble of a register inc r16 ;Incremements low nibble swap r16 ;Swaps nibbles inc r16 ;Increments high nibble swap r16 ;Swaps nibbles back |
|
dec |
Decrement by 1 dec r16 |
|
inc |
Increment by 1 inc r16 |
|
adc |
Add with carry: add ZL, r17 adc ZH, r16 ;if r17 + ZL > $FF, will add r16 + 1) |
|
add |
Add, set carry flag if necessary add r17, r16 |
|
adiw |
Add immediate... to word adiw r25:r24, 1 adiw ZH:ZL, 63 |
|
clc |
Clear carry flag clc ;C=0 |
|
sec |
Set carry flag sec ;C = 1 |
|
push |
Save register onto stack, post-decrement stack pointer by 1 push r16 ;(r16's value is now on stack) clr r16 ;(clear all bits in register 16) pop r17 ;r16's stored value placed into r17 Stack is a LIFO structure: last in will be first out |
|
pop |
Pre-increment stack pointer by 1, then take value pointed to by SP and place into register push r16 clr r16 pop r17 ;value placed onto stack, in this case r16, will now be put into r17 |
|
rcall |
Relative call: same as rjmp except places "return address" (address of next instr) onto stack |
|
call |
Absolute call: same as jmp except places "return address" (address of next instr) onto stack |
|
icall |
Call subroutine pointed to by Z (r31:r30) (that is, Z should contain address of subroutine) |
|
ret |
Returns from subroutine (that is, pre-increments stack-pointer, then jumps to address that is pointed to by the stack pointer) |
|
.include |
Includes an include file, which has useful definitions and equivalences: .include "m16def.inc" |
|
.cseg |
Marks "code segment" of assembly file |
|
.dseg |
Marks "data segment" of assembly file |
|
.eseg |
Marks "EEPROM segment" of assembly file |
|
.def |
Give a label to a register .def temp = r16 |
|
.undef |
Free up a label of a register .undef temp |
|
.equ |
Give a label to some value .equ io_offset = 0x23 |
|
.org |
Set location counter to absolute value. This varies by segment. .cseg .org 0x10 ;set program counter to 0x10 .dseg .org 0x120 ;set SRAM to 0x120 .eseg .org 0x180 ;set EEPROM to 0x180 |
|
.nolist |
Don't list (in the .lss file) the code after this .nolist .include "m16def.inc" .list |
|
.list |
Start listing (in the .lss file) the code after this .nolist .include "m16def.inc" .list |
|
<< |
Assembler should shift this value to the left by (value on right) bits ($0F << 2) will result in ($3C) Why? (0b00001111 << 2 = 0b00111100) |
|
>> |
Assembler should shift this value to the right by (value on right) bits ($F0 >> 2) will result in ($3C) Why? (0b11110000 >> 2 = 0b00111100) |