1
AVR202: 16-Bit Arithmetics
Features
•Easily Expandable to 32-Bit or Any
Word Length
•Code Density and Speed Matches 1 6-Bit
Controllers
•Runable Example Program
Introduction
This application note lists program
exampl es for ar ithmetic oper ation o n 16-
bit values. A listing of all implementa-
tions with key performance specifica-
tions is given in Table 1.
16 + 16-Bit Register
Addition
This operation is done as follows:
1. Add low bytes.
2. Add with carry high bytes.
By adding more Add with Carry instruc-
tions, numbers of
n
-byte width ca n be
added using
n
instru ctions.
16-Bit Register + 16-Bit
Immediate Addition
As the AVR has no add immediate or
add immediate with carry, the subtract
immediate and subtract immediate with
carry instructions are used. The opera-
tion is done as follows:
1. Subtract immediate low byte of
negated number from register low
byte.
2. Subtract immediate with carry high
byte of negated number from regis-
ter high byte.
By a dding mo re Add with Carr y inst ruc-
tions, numbers of
n
-byte width can be
added using
n
instructions.
16 – 16-Bit Register
Subtraction
This operation is done as follows:
1. Subtract low bytes.
2. Subtract with carry high bytes.
By adding more Subtract with Carry
instructions, numbers of
n
-byte width
can be subtracted using
n
instructions.
Table 1. Performance Figures Summary
Application Code Size
(Words) Execution Time
(Cycles)
Add two 16-bit register variables 2 2
Add 16-bit immediate to 16-bit register variable 2 2
Subtract two 16-bit register variables 2 2
Subtract 16-bit immediate from 16-bit r eg. variable 2 2
Compare two 16-bit register variables 2 2
Compare 16-bit immediate to 16-bit reg. variable 3 3
Negate a 16-bit register variable 4 4
8-Bit
MCU with
Downloadable
Flash
Application
Note
AVR202
0937A-A–8/97