1214571Sdim@c Copyright 2006 2214571Sdim@c Free Software Foundation, Inc. 3214571Sdim@c This is part of the GAS manual. 4214571Sdim@c For copying conditions, see the file as.texinfo. 5214571Sdim 6214571Sdim@ifset GENERIC 7214571Sdim@page 8214571Sdim@node AVR-Dependent 9214571Sdim@chapter AVR Dependent Features 10214571Sdim@end ifset 11214571Sdim 12214571Sdim@ifclear GENERIC 13214571Sdim@node Machine Dependencies 14214571Sdim@chapter AVR Dependent Features 15214571Sdim@end ifclear 16214571Sdim 17214571Sdim@cindex AVR support 18214571Sdim@menu 19214571Sdim* AVR Options:: Options 20214571Sdim* AVR Syntax:: Syntax 21214571Sdim* AVR Opcodes:: Opcodes 22214571Sdim@end menu 23214571Sdim 24214571Sdim@node AVR Options 25214571Sdim@section Options 26214571Sdim@cindex AVR options (none) 27214571Sdim@cindex options for AVR (none) 28214571Sdim 29214571Sdim@table @code 30214571Sdim 31214571Sdim@cindex @code{-mmcu=} command line option, AVR 32214571Sdim@item -mmcu=@var{mcu} 33214571SdimSpecify ATMEL AVR instruction set or MCU type. 34214571Sdim 35214571SdimInstruction set avr1 is for the minimal AVR core, not supported by the C 36214571Sdimcompiler, only for assembler programs (MCU types: at90s1200, attiny10, 37214571Sdimattiny11, attiny12, attiny15, attiny28). 38214571Sdim 39214571SdimInstruction set avr2 (default) is for the classic AVR core with up to 40214571Sdim8K program memory space (MCU types: at90s2313, at90s2323, attiny22, 41214571Sdimattiny26, at90s2333, at90s2343, at90s4414, at90s4433, at90s4434, 42214571Sdimat90s8515, at90c8534, at90s8535, at86rf401, attiny13, attiny2313, 43214571Sdimattiny261, attiny461, attiny861, attiny24, attiny44, attiny84, attiny25, 44214571Sdimattiny45, attiny85). 45214571Sdim 46214571SdimInstruction set avr3 is for the classic AVR core with up to 128K program 47214571Sdimmemory space (MCU types: atmega103, atmega603, at43usb320, at43usb355, 48214571Sdimat76c711). 49214571Sdim 50214571SdimInstruction set avr4 is for the enhanced AVR core with up to 8K program 51214571Sdimmemory space (MCU types: atmega48, atmega8, atmega83, atmega85, atmega88, 52214571Sdimatmega8515, atmega8535, atmega8hva, at90pwm1, at90pwm2, at90pwm3). 53214571Sdim 54214571SdimInstruction set avr5 is for the enhanced AVR core with up to 128K program 55214571Sdimmemory space (MCU types: atmega16, atmega161, atmega162, atmega163, 56214571Sdimatmega164p, atmega165, atmega165p, atmega168, atmega169, atmega169p, 57214571Sdimatmega32, atmega323, atmega324p, atmega325, atmega325p, atmega329, 58214571Sdimatmega329p, atmega3250, atmega3250p, atmega3290, atmega3290p, atmega406, 59214571Sdimatmega64, atmega640, atmega644, atmega644p, atmega128, atmega1280, 60214571Sdimatmega1281, atmega645, atmega649, atmega6450, atmega6490, atmega16hva, 61214571Sdimat90can32, at90can64, at90can128, at90usb82, at90usb162, at90usb646, 62214571Sdimat90usb647, at90usb1286, at90usb1287, at94k). 63214571Sdim 64214571SdimInstruction set avr6 is for the enhanced AVR core with 256K program 65214571Sdimmemory space (MCU types: atmega2560, atmega2561). 66214571Sdim 67214571Sdim@cindex @code{-mall-opcodes} command line option, AVR 68214571Sdim@item -mall-opcodes 69214571SdimAccept all AVR opcodes, even if not supported by @code{-mmcu}. 70214571Sdim 71214571Sdim@cindex @code{-mno-skip-bug} command line option, AVR 72214571Sdim@item -mno-skip-bug 73214571SdimThis option disable warnings for skipping two-word instructions. 74214571Sdim 75214571Sdim@cindex @code{-mno-wrap} command line option, AVR 76214571Sdim@item -mno-wrap 77214571SdimThis option reject @code{rjmp/rcall} instructions with 8K wrap-around. 78214571Sdim 79214571Sdim@end table 80214571Sdim 81214571Sdim 82214571Sdim@node AVR Syntax 83214571Sdim@section Syntax 84214571Sdim@menu 85214571Sdim* AVR-Chars:: Special Characters 86214571Sdim* AVR-Regs:: Register Names 87214571Sdim* AVR-Modifiers:: Relocatable Expression Modifiers 88214571Sdim@end menu 89214571Sdim 90214571Sdim@node AVR-Chars 91214571Sdim@subsection Special Characters 92214571Sdim 93214571Sdim@cindex line comment character, AVR 94214571Sdim@cindex AVR line comment character 95214571Sdim 96214571SdimThe presence of a @samp{;} on a line indicates the start of a comment 97214571Sdimthat extends to the end of the current line. If a @samp{#} appears as 98214571Sdimthe first character of a line, the whole line is treated as a comment. 99214571Sdim 100214571Sdim@cindex line separator, AVR 101214571Sdim@cindex statement separator, AVR 102214571Sdim@cindex AVR line separator 103214571Sdim 104214571SdimThe @samp{$} character can be used instead of a newline to separate 105214571Sdimstatements. 106214571Sdim 107214571Sdim@node AVR-Regs 108214571Sdim@subsection Register Names 109214571Sdim 110214571Sdim@cindex AVR register names 111214571Sdim@cindex register names, AVR 112214571Sdim 113214571SdimThe AVR has 32 x 8-bit general purpose working registers @samp{r0}, 114214571Sdim@samp{r1}, ... @samp{r31}. 115214571SdimSix of the 32 registers can be used as three 16-bit indirect address 116214571Sdimregister pointers for Data Space addressing. One of the these address 117214571Sdimpointers can also be used as an address pointer for look up tables in 118214571SdimFlash program memory. These added function registers are the 16-bit 119214571Sdim@samp{X}, @samp{Y} and @samp{Z} - registers. 120214571Sdim 121214571Sdim@smallexample 122214571SdimX = @r{r26:r27} 123214571SdimY = @r{r28:r29} 124214571SdimZ = @r{r30:r31} 125214571Sdim@end smallexample 126214571Sdim 127214571Sdim@node AVR-Modifiers 128214571Sdim@subsection Relocatable Expression Modifiers 129214571Sdim 130214571Sdim@cindex AVR modifiers 131214571Sdim@cindex syntax, AVR 132214571Sdim 133214571SdimThe assembler supports several modifiers when using relocatable addresses 134214571Sdimin AVR instruction operands. The general syntax is the following: 135214571Sdim 136214571Sdim@smallexample 137214571Sdimmodifier(relocatable-expression) 138214571Sdim@end smallexample 139214571Sdim 140214571Sdim@table @code 141214571Sdim@cindex symbol modifiers 142214571Sdim 143214571Sdim@item lo8 144214571Sdim 145214571SdimThis modifier allows you to use bits 0 through 7 of 146214571Sdiman address expression as 8 bit relocatable expression. 147214571Sdim 148214571Sdim@item hi8 149214571Sdim 150214571SdimThis modifier allows you to use bits 7 through 15 of an address expression 151214571Sdimas 8 bit relocatable expression. This is useful with, for example, the 152214571SdimAVR @samp{ldi} instruction and @samp{lo8} modifier. 153214571Sdim 154214571SdimFor example 155214571Sdim 156214571Sdim@smallexample 157214571Sdimldi r26, lo8(sym+10) 158214571Sdimldi r27, hi8(sym+10) 159214571Sdim@end smallexample 160214571Sdim 161214571Sdim@item hh8 162214571Sdim 163214571SdimThis modifier allows you to use bits 16 through 23 of 164214571Sdiman address expression as 8 bit relocatable expression. 165214571SdimAlso, can be useful for loading 32 bit constants. 166214571Sdim 167214571Sdim@item hlo8 168214571Sdim 169214571SdimSynonym of @samp{hh8}. 170214571Sdim 171214571Sdim@item hhi8 172214571Sdim 173214571SdimThis modifier allows you to use bits 24 through 31 of 174214571Sdiman expression as 8 bit expression. This is useful with, for example, the 175214571SdimAVR @samp{ldi} instruction and @samp{lo8}, @samp{hi8}, @samp{hlo8}, 176214571Sdim@samp{hhi8}, modifier. 177214571Sdim 178214571SdimFor example 179214571Sdim 180214571Sdim@smallexample 181214571Sdimldi r26, lo8(285774925) 182214571Sdimldi r27, hi8(285774925) 183214571Sdimldi r28, hlo8(285774925) 184214571Sdimldi r29, hhi8(285774925) 185214571Sdim; r29,r28,r27,r26 = 285774925 186214571Sdim@end smallexample 187214571Sdim 188214571Sdim@item pm_lo8 189214571Sdim 190214571SdimThis modifier allows you to use bits 0 through 7 of 191214571Sdiman address expression as 8 bit relocatable expression. 192214571SdimThis modifier useful for addressing data or code from 193214571SdimFlash/Program memory. The using of @samp{pm_lo8} similar 194214571Sdimto @samp{lo8}. 195214571Sdim 196214571Sdim@item pm_hi8 197214571Sdim 198214571SdimThis modifier allows you to use bits 8 through 15 of 199214571Sdiman address expression as 8 bit relocatable expression. 200214571SdimThis modifier useful for addressing data or code from 201214571SdimFlash/Program memory. 202214571Sdim 203214571Sdim@item pm_hh8 204214571Sdim 205214571SdimThis modifier allows you to use bits 15 through 23 of 206214571Sdiman address expression as 8 bit relocatable expression. 207214571SdimThis modifier useful for addressing data or code from 208214571SdimFlash/Program memory. 209214571Sdim 210214571Sdim@end table 211214571Sdim 212214571Sdim@node AVR Opcodes 213214571Sdim@section Opcodes 214214571Sdim 215214571Sdim@cindex AVR opcode summary 216214571Sdim@cindex opcode summary, AVR 217214571Sdim@cindex mnemonics, AVR 218214571Sdim@cindex instruction summary, AVR 219214571SdimFor detailed information on the AVR machine instruction set, see 220214571Sdim@url{www.atmel.com/products/AVR}. 221214571Sdim 222214571Sdim@code{@value{AS}} implements all the standard AVR opcodes. 223214571SdimThe following table summarizes the AVR opcodes, and their arguments. 224214571Sdim 225214571Sdim@smallexample 226214571Sdim@i{Legend:} 227214571Sdim r @r{any register} 228214571Sdim d @r{`ldi' register (r16-r31)} 229214571Sdim v @r{`movw' even register (r0, r2, ..., r28, r30)} 230214571Sdim a @r{`fmul' register (r16-r23)} 231214571Sdim w @r{`adiw' register (r24,r26,r28,r30)} 232214571Sdim e @r{pointer registers (X,Y,Z)} 233214571Sdim b @r{base pointer register and displacement ([YZ]+disp)} 234214571Sdim z @r{Z pointer register (for [e]lpm Rd,Z[+])} 235214571Sdim M @r{immediate value from 0 to 255} 236214571Sdim n @r{immediate value from 0 to 255 ( n = ~M ). Relocation impossible} 237214571Sdim s @r{immediate value from 0 to 7} 238214571Sdim P @r{Port address value from 0 to 63. (in, out)} 239214571Sdim p @r{Port address value from 0 to 31. (cbi, sbi, sbic, sbis)} 240214571Sdim K @r{immediate value from 0 to 63 (used in `adiw', `sbiw')} 241214571Sdim i @r{immediate value} 242214571Sdim l @r{signed pc relative offset from -64 to 63} 243214571Sdim L @r{signed pc relative offset from -2048 to 2047} 244214571Sdim h @r{absolute code address (call, jmp)} 245214571Sdim S @r{immediate value from 0 to 7 (S = s << 4)} 246214571Sdim ? @r{use this opcode entry if no parameters, else use next opcode entry} 247214571Sdim 248214571Sdim1001010010001000 clc 249214571Sdim1001010011011000 clh 250214571Sdim1001010011111000 cli 251214571Sdim1001010010101000 cln 252214571Sdim1001010011001000 cls 253214571Sdim1001010011101000 clt 254214571Sdim1001010010111000 clv 255214571Sdim1001010010011000 clz 256214571Sdim1001010000001000 sec 257214571Sdim1001010001011000 seh 258214571Sdim1001010001111000 sei 259214571Sdim1001010000101000 sen 260214571Sdim1001010001001000 ses 261214571Sdim1001010001101000 set 262214571Sdim1001010000111000 sev 263214571Sdim1001010000011000 sez 264214571Sdim100101001SSS1000 bclr S 265214571Sdim100101000SSS1000 bset S 266214571Sdim1001010100001001 icall 267214571Sdim1001010000001001 ijmp 268214571Sdim1001010111001000 lpm ? 269214571Sdim1001000ddddd010+ lpm r,z 270214571Sdim1001010111011000 elpm ? 271214571Sdim1001000ddddd011+ elpm r,z 272214571Sdim0000000000000000 nop 273214571Sdim1001010100001000 ret 274214571Sdim1001010100011000 reti 275214571Sdim1001010110001000 sleep 276214571Sdim1001010110011000 break 277214571Sdim1001010110101000 wdr 278214571Sdim1001010111101000 spm 279214571Sdim000111rdddddrrrr adc r,r 280214571Sdim000011rdddddrrrr add r,r 281214571Sdim001000rdddddrrrr and r,r 282214571Sdim000101rdddddrrrr cp r,r 283214571Sdim000001rdddddrrrr cpc r,r 284214571Sdim000100rdddddrrrr cpse r,r 285214571Sdim001001rdddddrrrr eor r,r 286214571Sdim001011rdddddrrrr mov r,r 287214571Sdim100111rdddddrrrr mul r,r 288214571Sdim001010rdddddrrrr or r,r 289214571Sdim000010rdddddrrrr sbc r,r 290214571Sdim000110rdddddrrrr sub r,r 291214571Sdim001001rdddddrrrr clr r 292214571Sdim000011rdddddrrrr lsl r 293214571Sdim000111rdddddrrrr rol r 294214571Sdim001000rdddddrrrr tst r 295214571Sdim0111KKKKddddKKKK andi d,M 296214571Sdim0111KKKKddddKKKK cbr d,n 297214571Sdim1110KKKKddddKKKK ldi d,M 298214571Sdim11101111dddd1111 ser d 299214571Sdim0110KKKKddddKKKK ori d,M 300214571Sdim0110KKKKddddKKKK sbr d,M 301214571Sdim0011KKKKddddKKKK cpi d,M 302214571Sdim0100KKKKddddKKKK sbci d,M 303214571Sdim0101KKKKddddKKKK subi d,M 304214571Sdim1111110rrrrr0sss sbrc r,s 305214571Sdim1111111rrrrr0sss sbrs r,s 306214571Sdim1111100ddddd0sss bld r,s 307214571Sdim1111101ddddd0sss bst r,s 308214571Sdim10110PPdddddPPPP in r,P 309214571Sdim10111PPrrrrrPPPP out P,r 310214571Sdim10010110KKddKKKK adiw w,K 311214571Sdim10010111KKddKKKK sbiw w,K 312214571Sdim10011000pppppsss cbi p,s 313214571Sdim10011010pppppsss sbi p,s 314214571Sdim10011001pppppsss sbic p,s 315214571Sdim10011011pppppsss sbis p,s 316214571Sdim111101lllllll000 brcc l 317214571Sdim111100lllllll000 brcs l 318214571Sdim111100lllllll001 breq l 319214571Sdim111101lllllll100 brge l 320214571Sdim111101lllllll101 brhc l 321214571Sdim111100lllllll101 brhs l 322214571Sdim111101lllllll111 brid l 323214571Sdim111100lllllll111 brie l 324214571Sdim111100lllllll000 brlo l 325214571Sdim111100lllllll100 brlt l 326214571Sdim111100lllllll010 brmi l 327214571Sdim111101lllllll001 brne l 328214571Sdim111101lllllll010 brpl l 329214571Sdim111101lllllll000 brsh l 330214571Sdim111101lllllll110 brtc l 331214571Sdim111100lllllll110 brts l 332214571Sdim111101lllllll011 brvc l 333214571Sdim111100lllllll011 brvs l 334214571Sdim111101lllllllsss brbc s,l 335214571Sdim111100lllllllsss brbs s,l 336214571Sdim1101LLLLLLLLLLLL rcall L 337214571Sdim1100LLLLLLLLLLLL rjmp L 338214571Sdim1001010hhhhh111h call h 339214571Sdim1001010hhhhh110h jmp h 340214571Sdim1001010rrrrr0101 asr r 341214571Sdim1001010rrrrr0000 com r 342214571Sdim1001010rrrrr1010 dec r 343214571Sdim1001010rrrrr0011 inc r 344214571Sdim1001010rrrrr0110 lsr r 345214571Sdim1001010rrrrr0001 neg r 346214571Sdim1001000rrrrr1111 pop r 347214571Sdim1001001rrrrr1111 push r 348214571Sdim1001010rrrrr0111 ror r 349214571Sdim1001010rrrrr0010 swap r 350214571Sdim00000001ddddrrrr movw v,v 351214571Sdim00000010ddddrrrr muls d,d 352214571Sdim000000110ddd0rrr mulsu a,a 353214571Sdim000000110ddd1rrr fmul a,a 354214571Sdim000000111ddd0rrr fmuls a,a 355214571Sdim000000111ddd1rrr fmulsu a,a 356214571Sdim1001001ddddd0000 sts i,r 357214571Sdim1001000ddddd0000 lds r,i 358214571Sdim10o0oo0dddddbooo ldd r,b 359214571Sdim100!000dddddee-+ ld r,e 360214571Sdim10o0oo1rrrrrbooo std b,r 361214571Sdim100!001rrrrree-+ st e,r 362214571Sdim1001010100011001 eicall 363214571Sdim1001010000011001 eijmp 364214571Sdim@end smallexample 365