Home
AVR Assembler User Guide
Contents
1. AVR Assembler User Guide 4 26 AIMEL Development Tools User Guide
2. The Assembler is not case sensitive The operands have the following forms Rd RO R31 or R16 R31 depending on instruction Rr RO R31 b Constant 0 7 can be a constant expression s Constant 0 7 can be a constant expression P Constant 0 31 63 can be a constant expression K Constant 0 255 can be a constant expression k Constant value range depending on instruction Can be a constant expression q Constant 0 63 can be a constant expression The Assembler supports a number of directives The directives are not translated directly into opcodes Instead they are used to adjust the location of the program in memory define macros initialize memory and so on An overview of the directives is given in the following table Summary of directives Directive Description BYTE Reserve byte to a variable CSEG Code Segment DB Define constant byte s DEF Define a symbolic name on a register DEVICE Define which device to assemble for DSEG Data Segment DW Define constant word s ENDMACRO End macro EQU Set a symbol equal to an expression ESEG EEPROM Segment EXIT Exit from file INCLUDE Read source from another file LIST Turn listfile generation on LISTMAC Turn macro expansion on MACRO Begin macro NOLIST Turn listfile generation off ORG Set program origin SET Set a symbol to an expression Note All directives must be preceded by a period
3. The DEF directive allows the registers to be referred to through symbols A defined sym bol can be used in the rest of the program to refer to the register it is assigned to A reg ister can have several symbolic names attached to it A symbol can be redefined later in the program Syntax DEF Symbol Register Example DEF temp R16 DEF ior R0 CSEG ldi temp 0xf0 Load Oxf0 into temp register in ior 0x3f Read SREG into ior register eor temp ior Exclusive or temp and ior AIMEL 4 11 AVR Assembler User Guide 4 5 5 DEVICE Define which device to assemble for 4 5 6 DSEG Data Segment 4 12 The DEVICE directive allows the user to tell the Assembler which device the code is to be executed on If this directive is used a warning is issued if an instruction not sup ported by the specified device occurs in the code If the size of the Code Segment or EEPROM Segment is larger than supported by the specified device a warning is issued If the DEVICE directive is not used it is assumed that all instructions are sup ported and that there are no restrictions on memory sizes Syntax DEVICE AT90S1200 AT90S2313 AT90S4414 AT90S8515 Example DEVICE AT90S1200 Use the AT90S1200 CSEG push r30 This statement will generate a warning since the specified device does not have this instruction The DSEG directive defines the start of a Data Segment An Asse
4. Double click on the error message in the Message window and observe that the Editor window becomes active while the cursor is positioned at the start of the line containing the error Correct the mistake by changing r32 to r19 in the Editor window One down five to go Now click on the next error in the list The message Illegal argument type or count tells that something is wrong with the arguments following the compare cp instruction Notice that the register named BH is one of the arguments which happens to be the variable we just corrected By clicking along on the remaining errors it appears that the first error generated all the messages To find out whether all errors have been corrected double click on any error to activate the Editor window or click inside the Editor window before you assemble once more If you have done it all right up till now the Message window will tell that you are crowned with success AIMEL 43 AVR Assembler User Guide 4 3 4 4 Assembler source The Assembler works on source files containing instruction mnemonics labels and directives The instruction mnemonics and the directives often take operands Code lines should be limited to 120 characters Every input line can be preceded by a label which is an alphanumeric string terminated by a colon Labels are used as targets for jump and branch instructions and as variable names in Program memory and RAM An in
5. Selecting text with the keyboard 1 Use the arrow keys to move the insertion point to the beginning of the text to select 2 Press and hold the Shift key while moving the insertion point to the end of the text to select Release the Shift key To cancel the selection press one of the arrow keys 4 22 AIMEL Development Tools User Guide 4 7 9 Replacing Text 4 7 10 Moving Text 4 7 11 Copying Text 4 7 12 Undoing an Edit 4 7 13 Click On Errors Development Tools User Guide AVR Assembler User Guide Selecting text with the mouse 1 Move the mouse cursor to the beginning of the text to select 2 Hold down the left mouse button while moving the cursor to the end of the text to select Release the mouse button 3 To cancel the selection press the left mouse button or one of the arrow keys When text is selected it can be immediately replaced it by typing new text The selected text is deleted when the first new character is typed Replacing text 1 Select the text to replace 2 Type the new text Deleting Text 1 Select the text to delete 2 Press the Del key To restore the deleted text press the 3 key on the toolbar or choose Edit Undo Alt Backspace from the menu immediately after deleting the text Text can be moved from one location in the editor by first copy the text to the Clipboard with the Cut command and then pasting it to its new location using the Paste command To move text
6. AIMEL 4 9 AVR Assembler User Guide 4 5 1 4 5 2 4 10 BYTE Reserve bytes to a variable CSEG Code Segment The BYTE directive reserves memory resources in the SRAM In order to be able to refer to the reserved location the BYTE directive should be preceded by a label The directive takes one parameter which is the number of bytes to reserve The directive can only be used within a Data Segment see directives CSEG DSEG and ESEG Note that a parameter must be given The allocated bytes are not initialized Syntax LABEL BYTE expression Example DSEG varl BYTE 1 reserve 1 byte to varl table BYTE tab size reserve tab size bytes CSEG ldi r30 low varl Load Z register low ldi r31 high varl Load Z register high ld ELPA Load VARI into register 1 The CSEG directive defines the start of a Code Segment An Assembler file can consist of several Code Segments which are concatenated into one Code Segment when assembled The BYTE directive can not be used within a Code Segment The default segment type is Code The Code Segments have their own location counter which is a word counter The ORG directive see description later in this document can be used to place code and constants at specific locations in the Program memory The directive does not take any parameters Syntax CSEG Example DSEG Start data segment vartab BYTE 4 Reserve 4 bytes in SRAM CSEG Start code
7. down in a body of text Down arrow key to the beginning of a line of text Home to the end of a line of text End to the beginning of the file Ctrl Home to the end of the file Ctrl End 4 7 5 Formatting Text The keys in the table below describes the necessary operations to type in the text exactly as wanted To Press insert a space Spacebar delete a character to the left Backspace delete a character to the right Del end a line Enter indent a line Tab insert a tab stop Tab To split a line move the insertion point to the position where the break is wanted and press Enter To join two lines move the insertion point to the beginning of the line to move and press Backspace The editor joins the line with the line above 4 7 6 Scrolling If a line of text is longer or wider than can be shown at one time the file can be scrolled by using the scroll bars 4 7 7 Editing Text The Edit menu contains some functions which can be of much help in editing Text can be deleted moved or copied to new locations The Undo command can be used to revert the last edit Transferring text to and from other windows or applications can be done via the clipboard When text is deleted or copied with the commands Cut or Copy the text is placed in the Clipboard The Paste command copies text from the Clipboard to the editor 4 7 8 Selecting Text Before a command is selected from the Edit menu to edit text the text to operate on must first be selected
8. expression 4 6 Expressions 4 6 1 Operands 4 6 2 Functions 4 6 3 Operators Development Tools User Guide AVR Assembler User Guide The SET directive assigns a value to a label This label can then be used in later expres sions A label assigned to a value by the SET directive can be changed later in the pro gram Syntax SET label expression Example SET io_offset 0x23 SET porta io_offset 2 CSEG Start code segment clr r2 Clear register 2 out porta r2 Write to Port A The Assembler incorporates expressions Expressions can consist of operands opera tors and functions All expressions are internally 32 bits The following operands can be used m User defined labels which are given the value of the location counter at the place they appear m User defined variables defined by the SET directive m User defined constants defined by the EQU directive m Integer constants constants can be given in several formats including a Decimal default 10 255 b Hexadecimal two notations 0x0a 0a Oxff ff c Binary 0b00001010 0b11111111 m PC the current value of the Program memory location counter The following functions are defined LOW expression returns the low byte of an expression HIGH expression returns the second byte of an expression BYTE2 expression is the same function as HIGH BYTE3 expression returns the third byte of an expression BYTE4 expression retu
9. 1 2 BRLT k Branch if Less Than Signed if N V 1 then PC PC k 1 None 1 2 BRHS k Branch if Half Carry Flag Set if H 1 then PC e PC k 1 None 1 2 BRHC k Branch if Half Carry Flag Cleared if H 0 then PC e PC k 1 None 1 2 BRTS k Branch if T Flag Set if T 1 then PC e PC k 1 None 1 2 BRTC k Branch if T Flag Cleared if T 0 then PC e PC k 1 None 1 2 BRVS k Branch if Overflow Flag is Set if V 1 then PC PC k 1 None 1 2 BRVC k Branch if Overflow Flag is Cleared if V 0 then PC PC k 1 None 1 2 BRIE k Branch if Interrupt Enabled if I 1 then PC PC k 1 None 1 2 BRID k Branch if Interrupt Disabled if I 0 then PC PC k 1 None 1 2 4 6 AIMEL Development Tools User Guide AVR Assembler User Guide Mnemonics Operands Description Operation Flags das DATA TRANSFER INSTRUCTIONS MOV Rd Rr Copy Register Rd Rr None 1 LDI Rd K Load Immediate Rd K None 1 LDS Rd k Load Direct from SRAM Rd lt k None 3 LD Rd X Load Indirect Rd lt X None 2 LD Rd X Load Indirect and Post Increment Rd amp X Xe X 1 None 2 LD Ra X Load Indirect and Pre Decrement Xe X 1 Rd X None 2 LD Rd Y Load Indirect Rd Y None 2 LD Rd Y Load Indirect and Post Increment Rd Y Y Y 1 None 2 LD Rd Y Load Indirect and Pre Decrement Y lt Y 1 Rd Y None 2 LDD Rd Y q Load Indirect with Displacement Rd amp Y q
10. Indirect Call to Z PC Z None 3 CALL k Call Subroutine PC k None 4 RET Subroutine Return PC STACK None 4 RETI Interrupt Return PC lt STACK l 4 CPSE Rd Rr Compare Skip if Equal if Rd Rr PC e PC 20r3 None 1 2 3 CP Rd Rr Compare Rd Rr Z C N V H 1 CPC Rd Rr Compare with Carry Rd Rr C Z C N V H 1 CPI Rd K Compare with Immediate Rd K Z C N V H 1 SBRC Rr b Skip if Bit in Register Cleared if Rr b 0 PC PC 2 or 3 None 1 2 3 SBRS Rr b Skip if Bit in Register Set if Rr b 1 PC PC 20r3 None 1 2 3 SBIC P b Skip if Bit in I O Register Cleared if I O P b 0 PC PC 20r 3 None 1 2 3 SBIS P b Skip if Bit in I O Register Set if I O P b 1 PC PC 20r 3 None 1 2 3 BRBS s k Branch if Status Flag Set if SREG s 1 then PC PC k 1 None 1 2 BRBC s k Branch if Status Flag Cleared if SREG s 0 then PC PC k 1 None 1 2 BREQ k Branch if Equal if Z 1 then PC e PC k 1 None 1 2 BRNE k Branch if Not Equal if Z 0 then PC PC k 1 None 1 2 BRCS k Branch if Carry Set if C 1 then PC PC k 1 None 1 2 BRCC k Branch if Carry Cleared if C 0 then PC e PC k 1 None 1 2 BRSH k Branch if Same or Higher if C 0 then PC e PC k 1 None 1 2 BRLO k Branch if Lower if C 1 then PC PC k 1 None 1 2 BRMI k Branch if Minus if N 1 then PC PC k 1 None 1 2 BRPL k Branch if Plus if N 0 then PC e PC k 1 None 1 2 BRGE k Branch if Greater or Equal Signed if N V 0 then PC PC k 1 None
11. LSL Rd Logical Shift Left Rd n 1 lt Rd n Rd 0 0 C Rd 7 Z C N V H 1 LSR Rd Logical Shift Right Rd n Rd n 1 Rd 7 0 C Rd 0 Z C N V 1 ROL Rd Rotate Left Through Carry Rd 0 C Rd n 1 Rd n C Rd 7 Z C N V H 1 ROR Rd Rotate Right Through Carry Rd 7 C Rd n Rd n 1 C Rd 0 Z C N V 1 ASR Rd Arithmetic Shift Right Rd n Rd n 1 n 0 6 Z C N V 1 SWAP Rd Swap Nibbles Rd 3 0 lt gt Rd 7 4 None 1 BSET s Flag Set SREG s lt 1 SREG s 1 BCLR s Flag Clear SREG s 0 SREG s 1 SBI Pb Set Bit in I O Register VO P b 1 None 2 CBI Pb Clear Bit in I O Register VO P b 0 None 2 BST Rr b Bit Store from Register to T T lt Rr b T 1 BLD Rd b Bit load from T to Register Rd b T None 1 SEC Set Carry Cel C 1 CLC Clear Carry CO C 1 SEN Set Negative Flag Nei N 1 CLN Clear Negative Flag NO N 1 SEZ Set Zero Flag Zei Z 1 CLZ Clear Zero Flag Z lt 0 Z 1 SEI Global Interrupt Enable le 1 l 1 CLI Global Interrupt Disable l 0 l 1 SES Set Signed Test Flag Sei S 1 CLS Clear Signed Test Flag S0 S 1 SEV Set Two s Complement Overflow Vei V 1 CLV Clear Two s Complement Overflow Veo0 V 1 SET Set T in SREG Tei T 1 CLT Clear T in SREG T0 T 1 SEH Set Half Carry Flag in SREG H 1 H 1 CLH Clear Half Carry Flag in SREG H0 H 1 NOP No Operation None 1 SLEEP Sleep None 1 WDR Watchdog Reset None 1 4 8 AIMEL Development Tools User Guide 4 5 Development Tools User Guide Assembler directives AVR Assembler User Guide
12. Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Binary operator which returns 1 if the signed expression to the left is Not Equal to the signed expression to the right 0 otherwise 9 SET flag cl c2 amp Binary operator which returns the bitwise And between two expressions 8 ldi Set flag to 1 or 0 r18 High c1 amp c2 Load r18 with an expression A Binary operator which returns the bitwise Exclusive Or between two expressions 7 ldi Binary operator which returns the bitwise Or between two expressions 6 ldi amp amp Binary operator which returns 1 if the expressions are both nonzero 0 otherwise 5 ldi Binary operator which returns 1 if one or both of the expressions are nonzero 0 otherwise 4 ldi r18 Low cl c2 Load r18 with an expression r18 Low cl c2 Load r18 with an expression r18 Low cl amp amp c2 Load r18 with an expression r18 Low cl c2 Load r18 with an expression AIMEL Development Tools User Guide 4 7 4 7 1 4 7 2 4 7 3 4 7 4 Development Tools User Guide Microsoft Windows specifics Opening Assembly Files The Integrated Editor Typing and Formatting Text Moving the Insertion Point AVR Assembler User Guide This section describes the features specific to
13. Subtract Immediate Rd lt Rd K Z C N V H 1 SBC Rd Rr Subtract with Carry Rd e Rd Rr C Z C N V H 1 SBCI Rd K Subtract Immediate with Carry Rd Rd K C Z C N V H 1 SBIW Rd K Subtract Immediate from Word Rd 1 Rd Rd 1 Rd K Z C N V 2 AND Rd Rr Logical AND Rd Rd e Rr ZNV 1 ANDI Rd K Logical AND with Immediate Rd lt Rd K Z N V 1 OR Rd Rr Logical OR Rd lt Rd v Rr Z N V 1 ORI Rd K Logical OR with Immediate Rd e Rdv K Z N V 1 EOR Rd Rr Exclusive OR Rd lt Rd Rr Z N V 1 COM Rd One s Complement Rd lt FF Rd Z C N V 1 NEG Rd Two s Complement Rd 00 Rd Z C N V H 1 SBR Rd K Set Bit s in Register Rd Rd v K Z N V 1 CBR Rd K Clear Bit s in Register Rd lt Rd e FFh K Z N V 1 INC Rd Increment Rd Rd 1 Z N V 1 DEC Rd Decrement Rd Rd 1 Z N V 1 TST Rd Test for Zero or Minus Rd Rd e Rd ZNV 1 CLR Rd Clear Register Rd Rd Rd Z N V 1 SER Rd Set Register Rd FF None 1 MUL Rd Rr Multiply Unsigned R1 RO lt Rd x Rr C 2 1 Note 1 Not available in base line microcontrollers Development Tools User Guide AIMEL 4 5 AVR Assembler User Guide Mnemonics Operands Description Operation Flags BRANCH INSTRUCTIONS RJMP k Relative Jump PC PC k 1 None 2 IJMP Indirect Jump to Z PC lt Z None 2 JMP k Jump PC lt k None 3 RCALL k Relative Call Subroutine PC PC k 1 None 3 ICALL
14. WAVRASM Only the menu items specific to the Assembler are described It is assumed that the user is familiar with the Search and Window menu items typical editing session with the Assembler is shown in the following figure TE EEE He Edt Semch Assemble Options Window Hep Be B def temp x16 serer Code ldi tenp low RAMEND SPL tenp out init Stack Pointer Low ax If device with less thon 256 bytes SRAN j 8488 dolote the folloving tvo lines ldi tenp high RANEND out SPL 1 tenp init Stack Pointer High inenen Henory fill cir Zi lai Z tableendw2 1 Z pointer lt ROM table end 1 cir ldi YL T START SIZE Y pointer t SRAM table cnd 1 loop lpm get ROH constant cpi YL T START if end breq sort git loop st V r0 store in SRAM and decrenent Y pointer dunny load decrenents Z pointer rj p loop sleop nore peewee Sort date sort 1di last T_START SIZE 1 last lt end of array address SI 1 ldi cnti SIZE 1 enti lt size of ortay 4 12 74 LIRE BEE Creating AVR220 EEP Creating AYR220 ROM Creating AVR220 OBJ Creating AVR220 EST Assenbling AVR220 ASH Including 2313def inc Erogran nenory usage 2 words Constants dw db 30 words nused b 0 words Total 62 vords Te a RE TATU str TE Co NOM mI new or existing assembly files can be opened in WAVRASM Theoretically there is no limit on how many assembly files which can be open at o
15. segment const DW 2 Write 0x0002 in prog mem mov rl r0 Do something AIMEL Development Tools User Guide 4 5 3 DB Define constant byte s in program memory or EPROM memory 4 5 4 DEF Set a symbolic name on a register Development Tools User Guide AVR Assembler User Guide The DB directive reserves memory resources in the program memory or the EEPROM memory In order to be able to refer to the reserved locations the DB directive should be preceded by a label The DB directive takes a list of expressions and must contain at least one expression The DB directive must be placed in a Code Segment or an EEPROM Segment The expression list is a sequence of expressions delimited by commas Each expres sion must evaluate to a number between 128 and 255 If the expression evaluates to a negative number the 8 bits two s complement of the number will be placed in the pro gram memory or EEPROM memory location If the DB directive is used in a Code Segment and the expressionlist contains more than one expression the expressions are packed so that two bytes are placed in each pro gram memory word If the expressionlist contains an odd number of expressions the last expression will be placed in a program memory word of its own even if the next line in the assembly code contains a DB directive Syntax LABEL DB expressionlist Example CSEG consts DB 0 255 0b01010101 128 Oxaa eeconst DB Oxff
16. the expression evaluates to a negative number the 16 bits two s complement of the number will be placed in the program memory location Syntax LABEL DW expressionlist Example CSEG varlist DW 0 0xffff 0b1001110001010101 32768 65535 eevar DW Oxffff The ENDMACRO directive defines the end of a Macro definition The directive does not take any parameters See the MACRO directive for more information on defining Mac ros Syntax ENDMACRO Example MACRO SUBI16 Start macro definition subi r16 low 0 Subtract low byte sbci r17 high 0 Subtract high byte ENDMACRO End macro definition The EQU directive assigns a value to a label This label can then be used in later expressions A label assigned to a value by the EQU directive is a constant and can not be changed or redefined Syntax EQU label expression Example EQU io offset 0x23 EQU porta io offset 2 CSEG Start code segment ely r2 Clear register 2 out porta r2 Write to Port A AIMEL 4 13 AVR Assembler User Guide 4 5 10 4 5 11 4 5 12 ESEG EEPROM Segment EXIT Exit this file INCLUDE Include another file The ESEG directive defines the start of an EEPROM Segment An Assembler file can consist of several EEPROM Segments which are concatenated into one EEPROM Segment when assembled The BYTE directive can not be used within an EEPROM Segment The EEPROM Segments have t
17. 1 Select the text to move 2 Press the XZ button on the toolbar or choose Edit gt Cut Shift Del from the menu The text is placed in the Clipboard 3 Move the insertion point to the new location 4 Press the H button on the toolbar or choose Edit gt Paste Shift Ins from the menu If some text will be used more than once it need not be typed each time The text can be copied to the Clipboard with Copy and can then be pasted in many places by using the Paste command To copy text 1 Select the text to copy 2 Click the 4 button on the toolbar or choose Edit gt Copy Ctrl Ins from the menu The text is placed in the Clipboard 3 Move the insertion point to the location to place the text 4 Click the Eg button on the toolbar or choose Edit gt Paste Shift Ins from the menu The Undo command can be used to cancel the last edit For example text may acciden tally have been deleted or it has been copied to a wrong location If the Undo command is chosen immediately after the mistake was done the text will be restored to what it was before the mistake To undo the last edit click the 3 button on the toolbar or choose Edit gt Undo Alt Backspace from the menu The Assembler has a click on error function When a program is assembled a message window appears on the screen If errors are encountered the errors are listed in this message window If one of the error lines in the me
18. 10 parameters These parameters are referred to as 0 9 within the Macro definition When issuing a Macro call the parameters are given as a comma sep arated list The Macro definition is terminated by an ENDMACRO directive By default only the call to the Macro is shown on the listfile generated by the Assem bler In order to include the macro expansion in the listfile a LISTMAC directive must be used macro is marked with a in the opcode field of the listfile Syntax MACRO macroname Example MACRO SUBI16 Start macro definition subi 1 low 0 Subtract low byte sbci 2 high 0 Subtract high byte ENDMACRO End macro definition CSEG Start code segment SUBI16 AIMEL 0x1234 r16 r17 Sub 0x1234 from rl7 r16 Development Tools User Guide II III 4 15 AVR Assembler User Guide 4 5 16 NOLIST Turn listfile The NOLIST directive tells the Assembler to turn listfile generation off The Assembler generation off normally generates a listfile which is a combination of assembly source code addresses and opcodes Listfile generation is turned on by default but can be disabled by using this directive The directive can also be used together with the LIST directive in order to only generate listfile of selected parts of an assembly source file Syntax NOLIST Enable listfile generation Example NOLIST Disable listfile generation INCLUDE macro inc The included
19. AIMEL 4 1 Introduction Development Tools User Guide Section 4 AVR Assembler User Guide Welcome to the Atmel AVR Assembler This manual describes the usage of the Assem bler The Assembler covers the whole range of microcontrollers in the AT90S family The Assembler translates assembly source code into object code The generated object code can be used as input to a simulator or an emulator such as the Atmel AVR In Cir cuit Emulator The Assembler also generates a PROMable code and an optional EEPROM file which can be programmed directly into the program memory and EEPROM memory of an AVA microcontroller The Assembler generates fixed code allocations consequently no linking is necessary The Assembler runs under Microsoft Windows 3 11 Microsoft Windows95 and Microsoft Windows NT In addition there is an MS DOS command line version The Windows version of the program contains an on line help function covering most of this document The instruction set of the AVR family of microcontrollers is only briefly described refer to the AVR Data Book also available on CD ROM in order to get more detailed knowl edge of the instruction set for the different microcontrollers To get quickly started the Quick Start Tutorial is an easy way to get familiar with the Atmel AVR Assembler 4 1 Rev 1022A A 01 98 AVR Assembler User Guide 4 2 4 2 1 4 2 2 Assembler Quick This tutorial assumes that the AVR Assembler and all p
20. None 2 LD Rd Z Load Indirect Rd lt Z None 2 LD Rd Z Load Indirect and Post Increment Rd amp Z Z Z 1 None 2 LD Rd Z Load Indirect and Pre Decrement Ze Z 1 Rd Z None 2 LDD Rd Z q Load Indirect with Displacement Rd amp Z q None 2 STS k Rr Store Direct to SRAM k lt Rr None 3 ST X Rr Store Indirect X Rr None 2 ST X Rr Store Indirect and Post Increment X Rr XX 1 None 2 ST X Rr Store Indirect and Pre Decrement XX 1 X Rr None 2 ST Y Rr Store Indirect Y lt Rr None 2 ST Y Rr Store Indirect and Post Increment Y e Ri Ye VY 1 None 2 ST Y Rr Store Indirect and Pre Decrement Y lt Y 1 Y lt lt Rr None 2 STD Y q Rr Store Indirect with Displacement Y q lt Rr None 2 ST Z Rr Store Indirect 2 lt Rr None 2 ST Z Rr Store Indirect and Post Increment Z Rr ZeZ 1 None 2 ST Z Rr Store Indirect and Pre Decrement Ze Z 1 Z2 Rr None 2 STD Z q Rr Store Indirect with Displacement Z gje Rr None 2 LPM Load Program Memory RO lt Z None 3 IN Rd P In Port Rd P None 1 OUT P Rr Out Port P lt Rr None 1 PUSH Rr Push Register on Stack STACK lt Rr None 2 POP Rd Pop Register from Stack Rd STACK None 2 Development Tools User Guide AIMEL 4 7 AVR Assembler User Guide Mnemonics Operands Description Operation Flags ae BIT AND BIT TEST INSTRUCTIONS
21. e generation on 4 5 14 LISTMAC Turn macro expansion on 4 5 15 MACRO Begin macro AVR Assembler User Guide The LIST directive tells the Assembler to turn listfile generation on The Assembler gen erates a listfile which is a combination of assembly source code addresses and opcodes Listfile generation is turned on by default The directive can also be used together with the NOLIST directive in order to only generate listfile of selected parts of an assembly source file Syntax LIST Example NOLIST Disable listfile generation INCLUDE macro inc The included files will not INCLUDE const def be shown in the listfile LIST Reenable listfile generation The LISTMAC directive tells the Assembler that when a macro is called the expansion of the macro is to be shown on the listfile generated by the Assembler The default is that only the macro call with parameters is shown in the listfile Syntax LISTMAC Example MACRO MACX Define an example macro add r0 0 Do something eor r1 1 Do something ENDMACRO End macro definition LISTMAC Enable macro expansion MACX r2 ri Call macro show expansion The MACRO directive tells the Assembler that this is the start of a Macro The MACRO directive takes the Macro name as parameter When the name of the Macro is written later in the program the Macro definition is expanded at the place it was used Macro can take up to
22. f0 Load r16 with OxOf Unary operator which returns the arithmetic negation of an expression 14 Idi r16 2 i Load 2 0xfe in r16 Binary operator which returns the product of two expressions 13 ldi Binary operator which returns the integer quotient of the left expression divided by the right expression 13 ldi r30 label 2 Load r30 with label 2 r30 label 2 Load r30 with label 2 Binary operator which returns the sum of two expressions 12 ldi r30 c1 c2 Load r30 with cl c2 Binary operator which returns the left expression minus the right expression 12 ldi L7 e1 cC2 Load r17 with cl c2 lt lt Binary operator which returns the left expression shifted left a number of times given by the right expression 11 ldi r17 1 lt lt bitmask Load r17 with 1 shifted left bitmask times AIMEL Development Tools User Guide 4 6 3 9 4 6 3 10 4 6 3 11 4 6 3 12 4 6 3 13 4 6 3 14 Development Tools User Guide Shift right Less than Less or Equal Greater than Greater or Equal Equal Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example AVR Assembler User Guide gt gt Binary operator which returns the left expre
23. files will not INCLUDE const def be shown in the listfile LIST Reenable listfile generation 4 5 17 ORG Set program The ORG directive sets the location counter to an absolute value The value to set is origin given as a parameter If an ORG directive is given within a Data Segment then it is the SRAM location counter which is set if the directive is given within a Code Segment then it is the Program memory counter which is set and if the directive is given within an EEPROM Segment then it is the EEPROM location counter which is set If the directive is preceded by a label on the same source code line the label will be given the value of the parameter The default values of the Code and EEPROM location counters are zero whereas the default value of the SRAM location counter is 32 due to the registers occupying addresses 0 31 when the assembling is started Note that the EEPROM and SRAM location counters count bytes whereas the Program memory location counter counts words Syntax ORG expression Example DSEG Start data segment ORG 0x67 Set SRAM address to hex 67 variable BYTE 1 Reserve a byte at SRAM adr 67H ESEG Start EEPROM Segment ORG 0x20 Set EEPROM location counter eevar DW Oxfeff Initialize one word CSEG ORG Ox10 Set Program Counter to hex 0 mov rO r1i Do something Development Tools User Guide 4 5 18 SET Set a symbol equal to an
24. heir own location counter which is a byte counter The ORG directive see description later in this document can be used to place constants at specific locations in the EEPROM memory The directive does not take any parameters Syntax ESEG Example DSEG Start data segment vartab BYTE 4 Reserve 4 bytes in SRAM SEG eevar DW OxffOf Initialize one word in EEPROM CSEG Start code segment const DW 2 Write 0x0002 in prog mem mov rl r0 Do something The EXIT directive tells the Assembler to stop assembling the file Normally the Assem bler runs until end of file EOF If an EXIT directive appears in an included file the Assembler continues from the line following the INCLUDE directive in the file containing the INCLUDE directive Syntax EXI Example EXT Exit this file The INCLUDE directive tells the Assembler to start reading from a specified file The Assembler then assembles the specified file until end of file EOF or an EXIT directive is encountered An included file may itself contain INCLUDE directives Syntax INCLUDE filename Example iodefs asm EQU sreg 0x3f Status register EQU sphigh 0x3e Stack pointer high EQU splow 0x3d Stack pointer low incdemo asm INCLUDE iodefs asm Include I O definitions in r0 sreg Read status register AIMEL Development Tools User Guide 4 5 13 LIST Turnthe listfil
25. lways the same If an EEPROM Segment has been defined in the code the assem bler will also generate a file with extension EEP which is the initial values for the EEPROM memory This EEPROM initialization file is in the same format as the Output file format selected The Wrap relative jumps option tells the Assembler to use wrapping of addresses This feature is only useful when assembling for devices with 4K words of program memory Using this option on such devices the relative jump and call instructions will reach the entire program memory The Save before assemble option makes the Assembler automatically save the con tents of the editor before assembling is done For the MS DOS command line version the Assembler is invoked by the command AVRASM m i g w input asm output lst output rom AVRASM will now read source from input asm produce the listfile output Ist output rom and the object file input obj The objectfile obj is used by the MS Windows simulator The user can select which output format to generate by using one of the options m Motorola S record i Intel Hex or g Generic The Generic file format is used by default The w option tells the Assembler to use wrapping of addresses This feature is only used when assembling for devices with 4K words of program memory Using this switch on these devices the relative jump and call instructions will reach the entire program memory AIMEL 425
26. mbler file can consist of several Data Segments which are concatenated into one Data Segment when assembled Data Segment will normally only consist of BYTE directives and labels The Data Segments have their own location counter which is a byte counter The ORG directive see description later in this document can be used to place the variables at specific locations in the SRAM The directive does not take any parameters Syntax DSEG Example DSEG Start data segment varl BYTE 1 reserve 1 byte to varl table BYTE tab size reserve tab size bytes CSEG ldi r30 low varl Load Z register low tdi r31 high varl Load Z register high ld r1 Z Load varl into register 1 AIMEL Development Tools User Guide 4 5 7 DW Define constant word s in program memory or E2PROM memory 4 5 8 ENDMACRO End macro 4 5 9 EQU Set a symbol equal to an expression Development Tools User Guide AVR Assembler User Guide The DW directive reserves memory resources in the program memory or EEPROM memory In order to be able to refer to the reserved locations the DW directive should be preceded by a label The DW directive takes a list of expressions and must contain at least one expression The DB directive must be placed in a Code Segment or an EEPROM Segment The expression list is a sequence of expressions delimited by commas Each expres sion must evaluate to a number between 32768 and 65535 If
27. ne time The size of each file must be less than about 28K bytes due to a limitation in MS Windows It is still possible to assemble files larger than this but they can not be edited in the integrated editor A new editor window is created for every assembly file which is opened To create a new assembly file click the 5 button on the toolbar or choose File New ALT F N from the menu To open an existing file click the 22 button on the toolbar or choose File gt Open ALT F O from the menu When WAVRASM is finished loading a file the text editor will be inactive Refer to the section on opening files on how to open a file Right after a file is loaded into an editor window of the Assembler the insertion point appears in the upper left corner of the win dow The insertion point moves to the right when typing If text is written beyond the right mar gin the text automatically scrolls to the left so that the insertion point is always visible The insertion point can be moved anywhere by moving the mouse cursor to the point where the insertion point is wanted and click the left button AIMEL 4 21 AVR Assembler User Guide To move the insertion point with the keyboard use the following keys or key combina tions To move the insertion point Press to the right in a line of text Right arrow key to the left in a line of text Left arrow key up in a body of text Up arrow key
28. ned variable names That is true since the AVR has exactly 32 General Pur pose working registers numbered RO R31 and tutor1 asm tries to assign a name to register 32 See the figure below FR File Edit Semch Assemble Options Window Hep i HER B A TUTORT ASM i Murber of cycles 8 9 min nax i Low registers used None ix High registers used 4 AH AL BH BL AM B AE D aN EE EEE a BE AG DE AGA DE AE AE A DEAE HE AAE DE AE AE a DE Ea aE a s s Subroutine Register Variables def AL x16 det H 2x17 det BL ari det Eli r4 xuxx Code conpi6s cp BH AK Compare lov bytes cpe BL L Compare high bytes brlo ci si if B gt nov H BE AH BH nov AL BL AL BL cl si ret HELELELLECELCECE LEE MM GE DEM KE EM i Hain Progran This progran calls the routine compl s three times for comparison of i three 16 bit signed number pairs x T B Message BEE ssenblins TUTOR1 ASH 1200 Includin def inc OR ET Register RO R31 expected TUTOR1 ASK 59 error Illegal argunent type or count TUTOR1 ASH 62 error Illegal srgunent type or count TUTOR1 ASH 96 error Illegal orgunent type or count TUTOR1 ASH 104 error Illogal argunent type or count TUTOR1 ASH 112 error Illegal argunent type or count Assembly conplete vith 6 errors Deleting TUTOR1 EEP Deleting TUTOR OB leting TUTOR ROH 4 AE me A i j 5 ker Co 1
29. put line may take one of the four following forms 1 label directive operands Comment 2 label instruction operands Comment 3 Comment 4 Empty line A comment has the following form Text Items placed in braces are optional The text between the comment delimiter and the end of line EOL is ignored by the Assembler Labels instructions and directives are described in more detail later Examples label EQU varl 100 Set varl to 100 Directive EQU var2 200 Set var2 to 200 test rjmp test Infinite loop Instruction Pure comment line Another comment line Note There are no restrictions with respect to column placement of labels directives comments or instructions AIMEL Development Tools User Guide AVR Assembler User Guide 4 4 Instruction The Assembler accepts mnemonic instructions from the instruction set A summary of mnemonics the instruction set mnemonics and their parameters is given here For a detailed description of the Instruction set refer to the AVR Data Book Mnemonics Operands Description Operation Flags NA ARITHMETIC AND LOGIC INSTRUCTIONS ADD Rd Rr Add without Carry Rd lt Rd Rr Z C N V H 1 ADC Rd Rr Add with Carry Rd lt Rd Rr C Z C N V H 1 ADIW Rd K Add Immediate to Word Rd 1 Rd Rd 1 Rd K Z C N V 2 SUB Rd Rr Subtract without Carry Rd Rd Rr Z C N V H 1 SUBI Rd K
30. rns the fourth byte of an expression LWRD expression returns bits 0 15 of an expression HWRD expression returns bits 16 31 of an expression PAGE expression returns bits 16 21 of an expression EXP2 expression returns 2 expression LOG2 expression returns the integer part of log2 expression The Assembler supports a number of operators which are described here The higher the precedence the higher the priority Expressions may be enclosed in parentheses and such expressions are always evaluated before combined with anything outside the parentheses AIMEL 417 AVR Assembler User Guide 4 6 3 1 4 6 3 2 4 6 3 3 4 6 3 4 4 6 3 5 4 6 3 6 4 6 3 7 4 6 3 8 4 18 Logical Not Bitwise Not Unary Minus Multiplication Division Addition Subtraction Shift left Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Symbol Description Precedence Example Unary operator which returns 1 if the expression was zero and returns 0 if the expression was nonzero 14 ldi r16 0xf0 Load r16 with 0x00 Unary operator which returns the input expression with all bits inverted 14 ldi r16 0x
31. rogram files that come with it are Start Tutorial Getting Started Assembling Your First File properly installed on your computer Please refer to the installation instructions Start the AVR Assembler By selecting File Open from the menu or by clicking Ca on the toolbar open the file tutor1 asm This loads the assembly file into the Editor window Read the program header and take a look at the program but do not make any changes yet Once you have had a look at the program select Assemble from the menu second window the Message window appears containing a lot of error messages This win dow will overlap the editor window so it is a good idea to clean up your work space on the screen Select the Editor window containing the program code and select Window gt Tile Horizontal from the menu It is useful to have the Editor window larger than the Message window so move the top of the Message window down a bit and follow with the bottom of the Editor window Your screen should look like this H EES ERR Fie Edt Semch Assemble Options Window Hep BP ES 5 i Munber of cycles 8 man nax i Low registers used one i High registers used 4 AM AL BH BL 2 AU D DE DE D DE DE D DD DE DEAE AE A AE DEA EAA DAE MAAE DAE BAG E BE 06 aE 6 s s Subroutine Register Variables det AL x16 det AH x17 det BL r18 det BH ar32 xxnxn Code conpi s c BH H Conpare lov byte
32. rsor is placed at the beginning of the line containing the error If the file containing the error is not opened for instance an included file then the file is automatically opened Note that this function points to lines in the assembled file This means that if lines are added or removed in the source file the file must be reassembled in order to get the line numbers right 4 7 14 Setting Program Some of the default values of WAVRASM can be changed in the options menu If Options Options is selected on the menu bar the following dialog box pops up LST List file extension FROM Output file extension Output file format Generic format Motorola S tecord Intel Intellec 8 MDS Cancel I Wrap relative jumps M Save before assemble 4 24 AIMEL Development Tools User Guide 4 8 Command line version Development Tools User Guide AVR Assembler User Guide In the box labeled List file extension the default extension on the list file s is written and in the box labeled Output file extension the default extension of the output file is written In the box labeled Output file format the type of format wanted on the output file can be selected If the OK button is clicked the values are remembered in subse quent runs of the Assembler Note that the object file used by the simulator is not affected by these options the extension of the object file is always OBJ and the format is a
33. s cre BL aL Coxpare high bytes brlo ci si if B gt nov AB BE A AH BH nov AL BL 3 AL BL cl6si ret Mririiririiiiririiiiiiiritiiritiiiitieririiiiritiitiriiritiiiitiiririiriri ig Moin Progran 18 This progran calls the routine compl s three ties for comparison of three 16 bit signed number pairs Mk Message dssenbling TUTOR1 ASH Including 1200def inc TUTOR1 ASK 54 error Register RO R31 expected TUTOR1 ASK 59 error Illegal argument type or count TUTOR1 ASK 62 error Illegal srgunent type or count TOTOR1 ASK 96 error Illegal argunent type or count TOTOR1 ASH 104 error Illcgal argunent type or count TUTOR1 ASH 112 error Illegal argunent type or count Assenbly conplete vith 6 errors Deleting TUTOR1 EEP Deleting TUTOR1 OBJ Deleting TUTOR1 ROW s E l AIMEL Development Tools User Guide 4 2 3 4 2 4 Development Tools User Guide Finding and Correcting Errors Reassembling AVR Assembler User Guide From the looks of the Message window it seems that you have attempted to assemble a program with lots of bugs To get any further the errors must be found and corrected Point to the first error message in the Message window the one reported to be on line 54 and press the left mouse button Notice that in the Editor window a red vertical bar is displayed all over line 54 The error message says that only registers RO to R31 can be assig
34. ssage window is clicked the source line turns inverted red If the error is in a included file nothing happens AIMEL 423 AVR Assembler User Guide This feature is demonstrated in the following figure TRE EE Fie Edt Semch Assemble Options Window Help HeRE KER EEE MAVR220 ASM def tenp x16 serrer Code 1di tenp law RAKEND SPL tenp out iinit Stack Pointer Low ieee TE device vith less thon 256 bytes SRAN s x dolote the folloving tvo lines ldi tenp high RANEND out SPL 1 tenp init Stack Pointer High zraze Henory fill ldi TL tableendu2 l iZ pointer lt RON table end 1 cir YH ldi YL T START SIZE Y pointer t SRAM table cnd 1 loop lpm iget ROH constant cpi YL T START if end breg sort A exit loop st r0 store in SRAM and decrenent Y pointer ld r0 Z dunny load decrenents Z pointer rixp loop sleop nore jeeexe Sort date sort ldi last T_START SIZE 1 last lt end of srray address ldi cnti SIZE 1 senti lt size of array 1 a B Message Creating AVR220 EEP Creating AVR220 ROM Creating AVR220 0BJ Creating AVR220 EST Assenblins AVR220 ASH Including 2313def inc Av METEN error Unknown instruction opcode Assembly conplete vith I error Deleting AVR220 EEP Deleting AVR220 OBJ Deleting AVR220 ROH LE Il sn NUM one If the message window line is doubleclicked the file containing the error becomes the active window and the cu
35. ssion shifted right a number of times given by the right expression 11 ldi rITseL gt gt a2 Load r17 with cl shifted right c2 times lt Binary operator which returns 1 if the signed expression to the left is Less than the signed expression to the right 0 otherwise 10 ori r18 bitmask cl lt c2 1 Or r18 with jan expression lt Binary operator which returns 1 if the signed expression to the left is Less than or Equal to the signed expression to the right 0 otherwise 10 ori r18 bitmask cl lt c2 1 Or r18 with jan expression gt Binary operator which returns 1 if the signed expression to the left is Greater than the signed expression to the right 0 otherwise 10 ori r18 bitmask cl gt c2 1 Or r18 with an expression gt Binary operator which returns 1 if the signed expression to the left is Greater than or Equal to the signed expression to the right 0 otherwise 10 ori r18 bitmask cl gt c2 1 Or r18 with an expression Binary operator which returns 1 if the signed expression to the left is Equal to the signed expression to the right 0 otherwise 9 andi r19 bitmask cl c2 1 And r19 with an expression AIMEL 4 19 AVR Assembler User Guide 4 6 3 15 4 6 3 16 4 6 3 17 4 6 3 18 4 6 3 19 4 6 3 20 4 20 Not Equal Bitwise And Bitwise Xor Bitwise Or Logical And Logical Or Symbol Description Precedence Example Symbol Description
Download Pdf Manuals
Related Search
Related Contents
取扱説明書 - ロジテック PDF: Baxter Mounting Guide Genome-TALER™ & Genome-CRISPR™ Mouse Samsung SC9540 คู่มือการใช้งาน User's Manual: - ADD MANUAL COMPLETO_BT8.indd 取扱説明書 詳細版 Sigma 4-15C Manual Motorola D401 Copyright © All rights reserved.
Failed to retrieve file