0% found this document useful (0 votes)
27 views

Bladabuska Avr Programming Part I Assembly

This document provides an assembly cheat sheet for AVR microcontrollers. It introduces basic assembly syntax including labels, comments, integer and character constants, strings, operators, and assembler directives. The cheat sheet defines common elements like labels, comments denoted with semicolons, and line continuation with backslashes. It also covers data types like integers in various numeral systems, characters, and strings. Operators for arithmetic, bitwise logic, and relational operations are presented along with precedence. Assembler directives are explained which provide instructions for the assembler software. Built-in functions are also listed that can evaluate expressions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Bladabuska Avr Programming Part I Assembly

This document provides an assembly cheat sheet for AVR microcontrollers. It introduces basic assembly syntax including labels, comments, integer and character constants, strings, operators, and assembler directives. The cheat sheet defines common elements like labels, comments denoted with semicolons, and line continuation with backslashes. It also covers data types like integers in various numeral systems, characters, and strings. Operators for arithmetic, bitwise logic, and relational operations are presented along with precedence. Assembler directives are explained which provide instructions for the assembler software. Built-in functions are also listed that can evaluate expressions.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

AVR Programming - Part I: Assembly Cheat Sheet

by bladabuska via cheatography.com/173176/cs/37345/

The Assemby Basics (copy)

Introd​uction Character constants

This Cheat Sheet is part of the Bladab​​uska's AVR Cheat Sheet Character constants are characters or escape sequences enclosed
Collec​​tion. This cheat sheet shows the basic syntax of the Assembly in single quotes ('). They and can be used anywhere an integer
language for AVRs. All inform​​ation in this cheat sheet is related to expression is allowed.
the AVR Assembler v2.0 from Microchip Technology Incorp​​orated sequence name symbol number
(formerly Atmel Corpor​​at​ion). The Assembly language for AVR
\0 Null Character NUL 0x00
microc​ont​rollers is not case sensitive.
\a Alert Bell BEL 0x07
Note: If you use a different assembler software, you must adapt the
\b Backspace BS 0x08
inform​ation to your software.
\t Horizontal Tab HT 0x09

The Assemby Basics \n Line Feed "or LF 0x0A


newlin​e"
\v Vertical Tab VT 0x0B
Comment
\f Form Feed FF 0x0C
Everything between a semicolon (;) and the end of the line is a \r Carriage CR 0x0D
comment and is ignored by the Assembler software. Comments are Return
primarily used for code docume​​nt​a​tion, and to disable code sections
\\ Backslash \ 0x5C
for debugging purpose.
\xHH Hexade​cimal Where H is the digit in hexade​cimal
Number notation (0-9,A-F)
Line contin​uation
\000 Octal Number Where o is the digit in octal notation
A backslash character (\) placed at the end of a line is used to inform
(0-7)
the prepr​​oc​​essor and the Assembler that the command continues on
the next line.
String constant

Label Field A string7 is any number of characters enclosed in double quotes (")
taken literally, no escape sequences are recogn​​ized, and it is not
A label is a text identifier that starts with a letter (a-z or A-Z), a
NULL-t​​er​m​i​nated. Quoted strings may be concat​​e​nated according to
question mark (?) or an underscore character (_), followed by zero or
the ANSI C convention (space character) or with the backslash
more letters, numbers, dollar signs ($), question marks (?), or
character (line contin​​u​a​tion) to form long strings and multiple line-s​‐
underscore characters (_). Labels cannot contain spaces and must
panning strings.
end with a colon character (:).
7
Strings can only be used in conjun​​ction with the DB directive or
Integer constant with the MESSAG​E, W​ARN​ING​ or ERROR direct​ives.

Integer constants starts by a number or a radix specifier. If an integer


Operators
starts with a non-zero number character (1-9), than no radix is
specified and the integer is considered to be expressed in the An operator is a (single or multiple) charac​ter(s) that executes an
decimal number system. Integers in binary notation must start with "​​‐ operation in one or more operands. Unary operators takes only one
0​b​", in hexade​​cimal notation with "​​0​x​" and in octal notation with a operand, placed after the operator. Binary operators takes two
leading zero (0). No spaces are allowed inside the number, but operands and are placed between then. The ternary condit​​ional
underscore characters (_) can be placed inside the number to operator takes three operands. Operators can be grouped with
increase readab​​i​lity.. parant​hesis to receive maximum preced​ence.

By bladabuska Not published yet. Sponsored by CrosswordCheats.com


Last updated 27th February, 2023. Learn to solve cryptic crosswords!
Page 2 of 6. http://crosswordcheats.com

cheatography.com/bladabuska/
AVR Programming - Part I: Assembly Cheat Sheet
by bladabuska via cheatography.com/173176/cs/37345/

Operators (cont) Assembler directive

Operator Operation Precedence 3 Assembler directives starts with a dot (.). They are used to guide the
Arithmetic Operators Assembler software on how to understand or implement some part
of the code. Assembly directives can be used to define macros, code
+ Addition 12
segments, condit​​ional sections and symbols, to reserve memory
- Subtra​ction 12
space for data, and to implement debug features.7
- Unary minus 14 7
Refer to the Assembler Directives Table to a complete list of
4
% Modulo 13 available Assembler direct​ives.
* Multip​lic​ation 13
/ Division 13 Function

Bitwise Operators Functions are built-in macro functions that can be used to evaluate
code.
~ Bitwise NOT 14
LOW(ex​pre​ssion)
& Bitwise AND 8
Returns the low byte (bits 7-0) of an expres​sion.
| Bitwise OR 6
^ Bitwise XOR 7 HIGH(e​xpr​ession)

<< Shift Left 11 Returns the second byte (bits 15-8) of an expres​sion.

>> Shift Right 11 BYTE2(​exp​res​sion)

Logic Operators Returns the second byte (bits 15-8) of an expres​sion.

! Logical NOT 14 BYTE3(​exp​res​sion)


&& Logical AND 5 Returns the third byte (bits 23-16) of an expres​sion.
|| Logical OR 4 BYTE4(​exp​res​sion)
Relational Operators Returns the fourth byte (bits 31-24) of an expres​sion.
< Less than 10 LWRD(e​xpr​esion)
>= Less than or equal to 10 Returns the low word (bits 15-0) of an expres​sion.
> Greater than 10
HWRD(e​xpr​esion)
>= Greater than or equal to 10
Returns the second word (bits 31-16) of an expres​sion.
== Equal to
PAGE(e​xpr​ession)
!= Different from
Returns bits 21-16 of an expres​sion.
Ternary Condit​ional Operator
EXP2(e​xpr​ession)
?: Ternary Condit​ional5 3
Returns 2 to the power of expres​sion.
3
The higher the preced​ence, the higher the priority.
4 LOG2(e​xpr​ession)
This operator was introduced in AVR Assembler v2.0.
5
This operator was introduced in AVR Assembler v2.1. Returns the integer part of a log2(e​xpr​ess​ion).

INT(ex​pre​ssion)
Truncates a floating point expression to integer.

FRAC(e​xpr​ession)
Extracts fractional part of a floating point expres​sion.

By bladabuska Not published yet. Sponsored by CrosswordCheats.com


Last updated 27th February, 2023. Learn to solve cryptic crosswords!
Page 3 of 6. http://crosswordcheats.com

cheatography.com/bladabuska/
AVR Programming - Part I: Assembly Cheat Sheet
by bladabuska via cheatography.com/173176/cs/37345/

Function (cont) Assembler Directives Table (cont)

Q7(exp​res​sion) .DBLD <li​st>


Converts a fractional floating point expression to a form suitable Reserves a number of BYTES in PROGRAM or EEPROM
for the multip​lic​ation instru​ctions. (Sign + 7-bit fraction) memory.

Q15(ex​pre​ssion) .DWLD <li​st>


Converts a fractional floating point expression to a form suitable Reserves a number of WORDS (2 BYTES) in PROGRAM or
for the multip​lic​ation instru​ctions. (Sign + 15-bit fraction) EEPROM memory.

ABS(ex​pre​ssion) .DDLD <li​st>


Returns the absolute value of a constant expres​sion. Reserves a number of DOUBLE​-WORDS (4 BYTES) in
PROGRAM or EEPROM memory.
DEFINE​D(s​ymbol)
Returns 1 if symbol was previously defined (using .SET, .DEF, or .DQ LD <li​st>
.EQU direct​ives), 0 otherwise. Normally used in conjun​ction with Reserves a number of QUAD-WORDS (8 BYTES) in PROGRAM
.IF and .ELIF direct​ives. It does not require parent​heses around its or EEPROM memory.
argument.
User Defined Symbols
STRLEN​(st​ring) .EQU <sy​mbo​l>=​<ex​pre​ssi​on>
Returns the length of a string constant, in bytes. Assigns a user defined symbol to a value or expres​sion. A symbol
assigned to a value by the EQU directive is a constant and cannot
Assembler Directives Table be changed or redefined.
Source Segments .SET <sy​mbo​l>=​<ex​pre​ssi​on>
A
.CSEG Assigns a user defined symbol to a value or expres​sion. A symbol
Defines the start of a CODE segment. CODE segments have their assigned to a value by the SET directive can be changed or
own location counter (in words), starting at 0. redefined later in the program.

.DSEGA .DEF <sy​mbo​l>=​<re​gis​ter>

Defines the start of a DATA segment. DATA segments have their Assigns a user defined symbol to a register. A register can have
own location counter (in bytes), starting at the first address after several symbolic names attached to it. A symbol can be redefined
the I/O registers (0x60 or 0x100, depending on the number of later in the program.
periph​erals). .UNDEF <sy​mbo​l>
A
.ESEG Undefine a symbol previously defined with the DEF directive. This
Defines the start of an EEPROM segment. EEPROM segments provides a way to obtain a simple scoping of register defini​tions,
have their own location counter (in bytes), starting at 0. avoiding warnings about register reuse.

.ORG <ad​dre​ss> Macro Definition

Sets the location counter (of the segment were it was pĺaced) to .MACRO <na​me>
an absolute value. Defines the start of the macro. It takes the macro name as a
Reserve Memory Space parameter. A macro is marked with a + in the opcode field of the
listfile.
.BYTELC <nu​mbe​r>
.ENDMA​CRO​/.ENDM
Reserves a number of BYTES in SRAM or EEPROM memories.
The directive takes one parameter, which is the number of bytes Defines the end of a macro defini​tion. ENDM is a synonym to
to reserve. ENDMACRO directive.

By bladabuska Not published yet. Sponsored by CrosswordCheats.com


Last updated 27th February, 2023. Learn to solve cryptic crosswords!
Page 4 of 6. http://crosswordcheats.com

cheatography.com/bladabuska/
AVR Programming - Part I: Assembly Cheat Sheet
by bladabuska via cheatography.com/173176/cs/37345/

Assembler Directives Table (cont) Assembler Directives Table (cont)

File Management .ERRORI <st​rin​g>


.INCLUDE <fi​le> Outputs an error message string and halts the assemb​ling.
Tells the Assembler to start reading from a specified file. The Listfile Generation Control
Assembler then assembles the specified file until end of file (EOF)
.LIST
or an EXIT directive is encoun​tered.
Turn the listfile generation ON. The listfile is a combin​ation of
.EXIT assembly source code, addresses, and opcodes. Listfile
Tells the Assembler to stop assembling the file. If an EXIT generation is turned on by default.
directive appears in an included file, the Assembler continues
.NOLIST
from the line following the INCLUDE directive in the file containing
Turn listfile generation OFF.
the INCLUDE directive.
.LISTMAC
Condit​ional Assembly
Turn macro expansion on. It tells the Assembler that when a
.IFDEF <sy​mbo​l>
macro is called, the expansion of the macro is to be shown on the
If the symbol is defined, it will include code untill the corres​‐
listfile generated by the Assembler. The default is that only the
ponding ELSE directive.
macro-call with parameters is shown in the listfile.
.IFNDEF <sy​mbo​l>
Special Funcitons
If the symbol is not defined, it will include code untill the corres​‐
.CSEGSIZE = <va​lue>
ponding ELSE directive.
This directive is used to specify the size of the program memory
.IF <ex​pre​ssi​on> block at the SRAM memory. This directive can only be used with
If expression is evaluated different from 0, it will include code AT94K Series Field Progra​mmable System Level Integrated
untill the corres​ponding ELSE, ELIF or ENDIF directive. Circuit Devices.

.ELIF <ex​pre​ssi​on> .OVERLAPV


It will include code until the corres​ponding ENDIF (or the next This directive is for projects with special needs and should
ELIF at the same level), if the expression is true, and the initial IF normally not be used.
clause and its following ELIF clauses (if any) are also false.
.NOOVERLAPV
.ELSE This directive is for projects with special needs and should
It will include code until the corres​ponding ENDIF, if the initial IF normally not be used.
clause and its following ELIF clauses (if any) are also false. A
All segments of the same type will be concat​enated into one single
.ENDIF segment of that type when assembled.
C
Defines the end for the condit​ional IF, IFDEF, or IFNDEF direct​‐ Cannot be used inside CODE segments.
D
ives. Cannot be used inside DATA segments.
I
My be used in condit​ional assembly,
Assembler Program Output L
In order to be able to refer to the reserved location, the directive
I
.MESSAGE <st​rin​g>
should be preceded by a LABEL.
Output a message string. V
Introduced in AVR Assembler v2.1.
.WARNINGI <st​rin​g>
Outputs a warning string, but does not halt assemb​ling.

By bladabuska Not published yet. Sponsored by CrosswordCheats.com


Last updated 27th February, 2023. Learn to solve cryptic crosswords!
Page 5 of 6. http://crosswordcheats.com

cheatography.com/bladabuska/
AVR Programming - Part I: Assembly Cheat Sheet
by bladabuska via cheatography.com/173176/cs/37345/

Prepro​cessor Directives Prepro​cessor Directives (cont)

Prepro​cessor directives are lines whose first non-empty character is #elif <ex​pre​ssi​on>
a hash symbol (#). They are used to issue commands to the prepro​​‐ All the following lines until the corres​ponding #endif, #else, or #elif
c​e​ssor. are condit​ionally assembled if expression evaluates to true (not
Macro Definition equal to 0),and all previous #if or #elif expres​sions were
#define <na​me> [<v​alu​e>] evaluated to false. Any undefined symbols used in expression are
silently evaluated to 0.
Define a prepro​cessor object​-like macros that basically define a
constant. If value is not specified, it is set to 1. #else

#define <na​me(​[<a​rg>, <...>]​)> [<v​alu​e>] All the following lines until the corres​ponding #endif are condit​‐
ionally assembled if all previous #if or #elif expres​sions were
Define a prepro​cessor functi​on-like macros that do parameter
evaluated to false.
substi​tution. This macro must be called with the same number of
arguments it is defined with. The left parent​hesis must appear #endif
immedi​ately after name (no spaces between), otherwise it will be Terminates a condit​ional block initiated with an #if, #ifdef, or
interp​reted as part of the value of a object​-like macro. If value is #ifndef directive.
not specified, it is set to 1.
Prepro​cessor Program Output
#undef <na​me>
#message <st​rin​g>
Undefine macro name previously defined with a #define directive.
Outputs string to standard output, but does not affect assembler
If name is not previously defined, the .undef directive is silently
error or warning counters.
ignored.
#warning <st​rin​g>
Condit​ional Assembly
Outputs string to standard error, and increments the assembler
#ifdef <na​me>
warning counter.
All the following lines until the corres​ponding #endif, #else, or #elif
#error <st​rin​g>
are condit​ionally assembled if name is previously #defined.
Outputs string to standard error, increments the assembler error
Shorthand for #if defined (name).
counter, and prevents the program of being succes​sfully
#ifndef <na​me>
assembled.
All the following lines until the corres​ponding #endif, #else, or #elif
File Management
are condit​ionally assembled if name is not #defined. Shorthand
#include "​fil​e"
for #if !defined (name).
Include a file, searching in the current working directory first, then
#if <ex​pre​ssi​on>
searching in the built-in known place.
All the following lines until the corres​ponding #endif, #else, or #elif
#include <fi​le>
are condit​ionally assembled if expression evaluates to true (not
equal to 0). Any undefined symbols used in expression are Include a file, searching in the built-in known place only, unless
silently evaluated to 0. the current working directory is explicitly specified with a dot (.)
entry in the include path.

Empty Directive
#
Does nothing. The line is removed by the prepro​cessor.

Note: #pragma prepro​cessor directives will be treated in a separate


topic.

By bladabuska Not published yet. Sponsored by CrosswordCheats.com


Last updated 27th February, 2023. Learn to solve cryptic crosswords!
Page 6 of 6. http://crosswordcheats.com

cheatography.com/bladabuska/
AVR Programming - Part I: Assembly Cheat Sheet
by bladabuska via cheatography.com/173176/cs/37345/

Prepro​cessor Pre-de​fined Macros Prepro​cessor directive

__AVRA​SM_​VER​SION__ Any line whose first non-empty character is a hash symbol (#). It is
INTEGER. AVR Assembler version, encoded as (1000*​major + used to issue command to the prepro​​c​e​ssor, a software that runs
minor) before calling the Assembler program. 2,3,4
2
__CORE​_VE​RSION__ Refer to the Prepro​cessor Directives Table for a complete list of
available prepro​cessor direct​ives.
STRING. AVR core version. 3
Refer to the Prepro​cessor Pre-De​fined Macro Table for a complete
__CORE​_co​rev​ers​ion__ list of available prepro​cessor pre-de​fined macros.
4
INTEGER. AVR core version value of the coreve​rsion. For Refer to the Prepro​cessor Pragma Directives for a complete list of
example: __CORE​_V2__ available prepro​cessor pragma direct​ives.

__DATE__
STRING. Build date in the format "Jun 28 2004".

__TIME__
STRING. Build time in the format: "​HH:​MM:​SS".

__CENT​URY__
INTEGER. Build time century (tipically 20).

__YEAR__
INTEGER. Build time year, less century (0-99).

__MONTH__
INTEGER. Build time month (1-12).

__DAY__
INTEGER. Build time day (1-31).

__HOUR__
INTEGER. Build time hour (0-23).

__MINUTE__
INTEGER. Build time minute (0-59).

__SECOND__
INTEGER. Build time second (0-59).

__FILE__
STRING. Sorce file name.

__LINE__
INTEGER. Current line number in source file.

__PART​_NAME__
STRING. AVR part name.

__part​name__
INTEGER. AVR part name value of the partname For example:
__ATme​ga8__

By bladabuska Not published yet. Sponsored by CrosswordCheats.com


Last updated 27th February, 2023. Learn to solve cryptic crosswords!
Page 7 of 6. http://crosswordcheats.com

cheatography.com/bladabuska/

You might also like