Docsity

AVR Assembler User Guide: Instructions and Directives, Study notes of Electrical and Electronics Engineering

Toggle sidebar
bg1
Development Tools User Guide 4-1
Section 4
AVR
Assembler User Guide
4.1 Introduction 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
AVR
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.
Rev. 1022A-A–01/98
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a

Partial preview of the text

Download AVR Assembler User Guide: Instructions and Directives and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Development Tools User Guide 4-

Section 4

AVR Assembler User Guide

4.1 Introduction Welcome to the AtmelAVR 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 AtmelAVR 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 anAVR 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 theAVR family of microcontrollers is only briefly described, refer to theAVR 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 AtmelAVR Assembler.

Rev. 1022A-A–01/

4-2 Development Tools User Guide

4.2 Assembler Quick

Start Tutorial

This tutorial assumes that theAVR Assembler and all program files that come with it are properly installed on your computer. Please refer to the installation instructions

4.2.1 Getting Started Start theAVR Assembler. By selecting “File → Open” from the menu or by clicking 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.

4.2.2 Assembling Your First File

Once you have had a look at the program, select Assemble from the menu. A 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 → 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:

4-4 Development Tools User Guide

4.3 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 input 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 var1=100 ; Set var1 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.

Development Tools User Guide 4-

4.4 Instruction

mnemonics

The Assembler accepts mnemonic instructions from the instruction set. A summary of the instruction set mnemonics and their parameters is given here. For a detailed description of the Instruction set, refer to theAVR Data Book.

Note: 1. Not available in base-line microcontrollers

Mnemonics Operands Description Operation Flags #ClockNote

ARITHMETIC AND LOGIC INSTRUCTIONS ADD Rd, Rr Add without Carry Rd ← Rd + Rr Z,C,N,V,H 1 ADC Rd, Rr Add with Carry Rd ← 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 Subtract Immediate Rd ← Rd - K Z,C,N,V,H 1 SBC Rd, Rr Subtract with Carry Rd ← 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 • Rr Z,N,V 1 ANDI Rd, K Logical AND with Immediate Rd ← Rd • K Z,N,V 1 OR Rd, Rr Logical OR Rd ← Rd v Rr Z,N,V 1 ORI Rd, K Logical OR with Immediate Rd ← Rd v K Z,N,V 1 EOR Rd, Rr Exclusive OR Rd ← Rd ⊕ Rr Z,N,V 1 COM Rd One's Complement Rd ← $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 ← Rd • ($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 • Rd Z,N,V 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, R0 ← Rd × Rr C 2 (1)

Mnemonics Operands Description Operation Flags #ClockNote

4-8 Development Tools User Guide Mnemonics Operands Description Operation Flags #ClockNote

  • RJMP k Relative Jump PC ← PC + k + 1 None BRANCH INSTRUCTIONS
  • IJMP Indirect Jump to (Z) PC ← Z None
  • JMP k Jump PC ← k None
  • RCALL k Relative Call Subroutine PC ← PC + k + 1 None
  • ICALL Indirect Call to (Z) PC ← Z None
  • CALL k Call Subroutine PC ← k None
  • RET Subroutine Return PC ← STACK None
  • RETI Interrupt Return PC ← STACK I
  • CPSE Rd,Rr Compare, Skip if Equal if (Rd = Rr) PC ← PC + 2 or 3 None 1 / 2 /
  • CP Rd,Rr Compare Rd - Rr Z,C,N,V,H
  • CPC Rd,Rr Compare with Carry Rd - Rr - C Z,C,N,V,H
  • CPI Rd,K Compare with Immediate Rd - K Z,C,N,V,H
  • SBRC Rr, b Skip if Bit in Register Cleared if (Rr(b)=0) PC ← PC + 2 or 3 None 1 / 2 /
  • SBRS Rr, b Skip if Bit in Register Set if (Rr(b)=1) PC ← PC + 2 or 3 None 1 / 2 /
  • SBIC P, b Skip if Bit in I/O Register Cleared if(I/O(P,b)=0) PC ← PC + 2 or 3 None 1 / 2 /
  • SBIS P, b Skip if Bit in I/O Register Set if(I/O(P,b)=1) PC ← PC + 2 or 3 None 1 / 2 /
  • BRBS s, k Branch if Status Flag Set if (SREG(s) = 1) then PC ← PC+k + 1 None 1 /
  • BRBC s, k Branch if Status Flag Cleared if (SREG(s) = 0) then PC ← PC+k + 1 None 1 /
  • BREQ k Branch if Equal if (Z = 1) then PC ← PC + k + 1 None 1 /
  • BRNE k Branch if Not Equal if (Z = 0) then PC ← PC + k + 1 None 1 /
  • BRCS k Branch if Carry Set if (C = 1) then PC ← PC + k + 1 None 1 /
  • BRCC k Branch if Carry Cleared if (C = 0) then PC ← PC + k + 1 None 1 /
  • BRSH k Branch if Same or Higher if (C = 0) then PC ← PC + k + 1 None 1 /
  • BRLO k Branch if Lower if (C = 1) then PC ← PC + k + 1 None 1 /
  • BRMI k Branch if Minus if (N = 1) then PC ← PC + k + 1 None 1 /
  • BRPL k Branch if Plus if (N = 0) then PC ← PC + k + 1 None 1 /
  • BRGE k Branch if Greater or Equal, Signed if (N ⊕ V= 0) then PC ← PC+ k + 1 None 1 /
  • BRLT k Branch if Less Than, Signed if (N ⊕ V= 1) then PC ← PC + k + 1 None 1 /
  • BRHS k Branch if Half Carry Flag Set if (H = 1) then PC ← PC + k + 1 None 1 /
  • BRHC k Branch if Half Carry Flag Cleared if (H = 0) then PC ← PC + k + 1 None 1 /
  • BRTS k Branch if T Flag Set if (T = 1) then PC ← PC + k + 1 None 1 /
  • BRTC k Branch if T Flag Cleared if (T = 0) then PC ← PC + k + 1 None 1 /
  • BRVS k Branch if Overflow Flag is Set if (V = 1) then PC ← PC + k + 1 None 1 /
  • BRVC k Branch if Overflow Flag is Cleared if (V = 0) then PC ← PC + k + 1 None 1 /
  • BRIE k Branch if Interrupt Enabled if (I = 1) then PC ← PC + k + 1 None 1 /
  • BRID k Branch if Interrupt Disabled if (I = 0) then PC ← PC + k + 1 None 1 /
  • Development Tools User Guide 4-
  • MOV Rd, Rr Copy Register Rd ← Rr None DATA TRANSFER INSTRUCTIONS
  • LDI Rd, K Load Immediate Rd ← K None
  • LDS Rd, k Load Direct from SRAM Rd ← (k) None
  • LD Rd, X Load Indirect Rd ← (X) None
  • LD Rd, X+ Load Indirect and Post-Increment Rd ← (X), X ← X + 1 None
  • LD Rd, -X Load Indirect and Pre-Decrement X ← X - 1, Rd ← (X) None
  • LD Rd, Y Load Indirect Rd ← (Y) None
  • LD Rd, Y+ Load Indirect and Post-Increment Rd ← (Y), Y ← Y + 1 None
  • LD Rd, -Y Load Indirect and Pre-Decrement Y ← Y - 1, Rd ← (Y) None
  • LDD Rd,Y+q Load Indirect with Displacement Rd ← (Y + q) None
  • LD Rd, Z Load Indirect Rd ← (Z) None
  • LD Rd, Z+ Load Indirect and Post-Increment Rd ← (Z), Z ← Z+1 None
  • LD Rd, -Z Load Indirect and Pre-Decrement Z ← Z - 1, Rd ← (Z) None
  • LDD Rd, Z+q Load Indirect with Displacement Rd ← (Z + q) None
  • STS k, Rr Store Direct to SRAM (k) ← Rr None
  • ST X, Rr Store Indirect (X) ← Rr None
  • ST X+, Rr Store Indirect and Post-Increment (X) ← Rr, X ← X + 1 None
  • ST -X, Rr Store Indirect and Pre-Decrement X ← X - 1, (X) ← Rr None
  • ST Y, Rr Store Indirect (Y) ← Rr None
  • ST Y+, Rr Store Indirect and Post-Increment (Y) ← Rr, Y ← Y + 1 None
  • ST -Y, Rr Store Indirect and Pre-Decrement Y ← Y - 1, (Y) ← Rr None
  • STD Y+q,Rr Store Indirect with Displacement (Y + q) ← Rr None
  • ST Z, Rr Store Indirect (Z) ← Rr None
  • ST Z+, Rr Store Indirect and Post-Increment (Z)← Rr, Z ← Z + 1 None
  • ST -Z, Rr Store Indirect and Pre-Decrement Z ← Z - 1, (Z) ← Rr None
  • STD Z+q,Rr Store Indirect with Displacement (Z + q)← Rr None
  • LPM Load Program Memory R0 ← (Z) None
  • IN Rd, P In Port Rd ← P None
  • OUT P, Rr Out Port P ← Rr None
  • PUSH Rr Push Register on Stack STACK ← Rr None
  • POP Rd Pop Register from Stack Rd ← STACK None
  • LSL Rd Logical Shift Left Rd(n+1) ← Rd(n),Rd(0) ← 0,C ← Rd(7) Z,C,N,V,H BIT AND BIT-TEST INSTRUCTIONS
  • LSR Rd Logical Shift Right Rd(n) ← Rd(n+1),Rd(7) ← 0,C ← Rd(0) Z,C,N,V
  • ROL Rd Rotate Left Through Carry Rd(0) ← C,Rd(n+1) ← Rd(n),C ← Rd(7) Z,C,N,V,H
  • ROR Rd Rotate Right Through Carry Rd(7) ← C,Rd(n) ← Rd(n+1),C ← Rd(0) Z,C,N,V
  • ASR Rd Arithmetic Shift Right Rd(n) ← Rd(n+1), n=0..6 Z,C,N,V
  • SWAP Rd Swap Nibbles Rd(3..0) ↔ Rd(7..4) None
  • BSET s Flag Set SREG(s) ← 1 SREG(s)
  • BCLR s Flag Clear SREG(s) ← 0 SREG(s)
  • SBI P, b Set Bit in I/O Register I/O(P, b) ← 1 None
  • CBI P, b Clear Bit in I/O Register I/O(P, b) ← 0 None
  • BST Rr, b Bit Store from Register to T T ← Rr(b) T
  • BLD Rd, b Bit load from T to Register Rd(b) ← T None
  • SEC Set Carry C ← 1 C
  • CLC Clear Carry C ← 0 C
  • SEN Set Negative Flag N ← 1 N
  • CLN Clear Negative Flag N ← 0 N
  • SEZ Set Zero Flag Z ← 1 Z
  • CLZ Clear Zero Flag Z ← 0 Z
  • SEI Global Interrupt Enable I ← 1 I
  • CLI Global Interrupt Disable I ← 0 I
  • SES Set Signed Test Flag S ← 1 S
  • CLS Clear Signed Test Flag S ← 0 S
  • SEV Set Two's Complement Overflow V ← 1 V
  • CLV Clear Two's Complement Overflow V ← 0 V
  • SET Set T in SREG T ← 1 T
  • CLT Clear T in SREG T ← 0 T
  • SEH Set Half Carry Flag in SREG H ← 1 H
  • CLH Clear Half Carry Flag in SREG H ← 0 H
  • NOP No Operation None
  • SLEEP Sleep None
  • WDR Watchdog Reset None

4-10 Development Tools User Guide

4.5.1 BYTE - Reserve bytes to a variable

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 var1: .BYTE 1 ; reserve 1 byte to var table: .BYTE tab_size ; reserve tab_size bytes .CSEG ldi r30,low(var1) ; Load Z register low ldi r31,high(var1) ; Load Z register high ld r1,Z ; Load VAR1 into register 1

4.5.2 CSEG - Code Segment

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 segment const: .DW 2 ; Write 0x0002 in prog.mem. mov r1,r0 ; Do something

Development Tools User Guide 4-

4.5.3 DB-Define constant byte(s) in program memory or E 2 PROM memory

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, 0xaa .ESEG eeconst:.DB 0xff

4.5.4 DEF - Set a symbolic name on a register

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=R .DEF ior=R .CSEG ldi temp,0xf0 ; Load 0xf0 into temp register in ior,0x3f ; Read SREG into ior register eor temp,ior ; Exclusive or temp and ior

Development Tools User Guide 4-

4.5.7 DW-Define constant word(s) in program memory or E 2 PROM memory

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 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, .ESEG eevar: .DW 0xffff

4.5.8 ENDMACRO - End macro

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

4.5.9 EQU - Set a symbol equal to an expression

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 = 0x .EQU porta = io_offset + 2 .CSEG ; Start code segment clr r2 ; Clear register 2 out porta,r2 ; Write to Port A

4-14 Development Tools User Guide

4.5.10 ESEG - EEPROM

Segment

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 their 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 .ESEG eevar: .DW 0xff0f ; Initialize one word in ; EEPROM .CSEG ; Start code segment const: .DW 2 ; Write 0x0002 in prog.mem. mov r1,r0 ; Do something

4.5.11 EXIT - Exit this file 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: .EXIT

Example: .EXIT ; Exit this file

4.5.12 INCLUDE - Include another 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

4-16 Development Tools User Guide

4.5.16 NOLIST - Turn listfile generation off

The NOLIST directive tells the Assembler to turn listfile generation off. The Assembler 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 files will not .INCLUDE “const.def” ; be shown in the listfile .LIST ; Reenable listfile generation

4.5.17 ORG - Set program origin

The ORG directive sets the location counter to an absolute value. The value to set is 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 0xfeff ; Initialize one word .CSEG .ORG 0x10 ; Set Program Counter to hex ; 10 mov r0,r1 ; Do something

Development Tools User Guide 4-

4.5.18 SET - Set a symbol equal to an expression

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 = 0x .SET porta = io_offset + 2 .CSEG ; Start code segment clr r2 ; Clear register 2 out porta,r2 ; Write to Port A

4.6 Expressions The Assembler incorporates expressions. Expressions can consist of operands, opera-

tors and functions. All expressions are internally 32 bits.

4.6.1 Operands The following operands can be used:

n User defined labels which are given the value of the location counter at the place they appear. n User defined variables defined by the SET directive n User defined constants defined by the EQU directive n Integer constants: constants can be given in several formats, including a) Decimal (default): 10, 255 b) Hexadecimal (two notations): 0x0a, $0a, 0xff, $ff c) Binary: 0b00001010, 0b n PC - the current value of the Program memory location counter

4.6.2 Functions The following functions are defined:

n LOW(expression) returns the low byte of an expression n HIGH(expression) returns the second byte of an expression n BYTE2(expression) is the same function as HIGH n BYTE3(expression) returns the third byte of an expression n BYTE4(expression) returns the fourth byte of an expression n LWRD(expression) returns bits 0-15 of an expression n HWRD(expression) returns bits 16-31 of an expression n PAGE(expression) returns bits 16-21 of an expression n EXP2(expression) returns 2^expression n LOG2(expression) returns the integer part of log2(expression)

4.6.3 Operators 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.

Development Tools User Guide 4-

4.6.3.9 Shift right Symbol: >>

Description: Binary operator which returns the left expression shifted right a number of times given by the right expression. Precedence: 11 Example: ldi r17,c1>>c2 ;Load r17 with c1 shifted ;right c2 times

4.6.3.10 Less than Symbol: <

Description: Binary operator which returns 1 if the signed expression to the left is Less than the signed expression to the right, 0 otherwise Precedence: 10 Example: ori r18,bitmask*(c1<c2)+1 ;Or r18 with ;an expression

4.6.3.11 Less or Equal Symbol: <=

Description: 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 Precedence: 10 Example: ori r18,bitmask*(c1<=c2)+1 ;Or r18 with ;an expression

4.6.3.12 Greater than Symbol: >

Description: Binary operator which returns 1 if the signed expression to the left is Greater than the signed expression to the right, 0 otherwise Precedence: 10 Example: ori r18,bitmask*(c1>c2)+1 ;Or r18 with ;an expression

4.6.3.13 Greater or Equal Symbol: >=

Description: 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 Precedence: 10 Example: ori r18,bitmask*(c1>=c2)+1 ;Or r18 with ;an expression

4.6.3.14 Equal Symbol: ==

Description: Binary operator which returns 1 if the signed expression to the left is Equal to the signed expression to the right, 0 otherwise Precedence: 9 Example: andi r19,bitmask*(c1==c2)+1 ;And r19 with ;an expression

4-20 Development Tools User Guide

4.6.3.15 Not Equal Symbol: !=

Description: Binary operator which returns 1 if the signed expression to the left is Not Equal to the signed expression to the right, 0 otherwise Precedence: 9 Example: .SET flag=(c1!=c2) ;Set flag to 1 or 0

4.6.3.16 Bitwise And Symbol: &

Description: Binary operator which returns the bitwise And between two expressions Precedence: 8 Example: ldi r18,High(c1&c2) ;Load r18 with an expression

4.6.3.17 Bitwise Xor Symbol: ^

Description: Binary operator which returns the bitwise Exclusive Or between two expressions Precedence: 7 Example: ldi r18,Low(c1^c2) ;Load r18 with an expression

4.6.3.18 Bitwise Or Symbol: |

Description: Binary operator which returns the bitwise Or between two expressions Precedence: 6 Example: ldi r18,Low(c1|c2) ;Load r18 with an expression

4.6.3.19 Logical And Symbol: &&

Description: Binary operator which returns 1 if the expressions are both nonzero, 0 otherwise Precedence: 5 Example: ldi r18,Low(c1&&c2) ;Load r18 with an expression

4.6.3.20 Logical Or Symbol: ||

Description: Binary operator which returns 1 if one or both of the expressions are nonzero, 0 otherwise Precedence: 4 Example: ldi r18,Low(c1||c2) ;Load r18 with an expression