ArticleslgStudy

science

Atmel AVR instruction set

Atmel AVR instruction set is a science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Atmel AVR instruction set rather than just read about it. In short: The Atmel AVR instruction set is the machine language for the Atmel AVR, a modified Harvard architecture 8-bit RISC single chip microcontroller which was developed by Atmel in 1996. Atmel was acquired by Microchip Technology in 2016.

Key takeaways

  • Atmel AVR instruction set belongs to science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Atmel AVR instruction set to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Atmel AVR instruction set from memory before moving on to harder problems.

Reference excerpt

The Atmel AVR instruction set is the machine language for the Atmel AVR, a modified Harvard architecture 8-bit RISC single chip microcontroller which was developed by Atmel in 1996. Atmel was acquired by Microchip Technology in 2016. The AVR was one of the first microcontroller families to use on-chip flash memory for program storage.

Processor registers

There are 32 general-purpose 8-bit registers, R0–R31. All arithmetic and logic operations operate on those registers; only load and store instructions access RAM. A limited number of instructions operate on 16-bit register pairs. The lower-numbered register of the pair holds the least significant bits and must be even-numbered. The last three register pairs are used as pointer registers for memory addressing. They are known as X (R27:R26), Y (R29:R28) and Z (R31:R30). Postincrement and predecrement addressing modes are supported on all three. Y and Z also support a six-bit positive displacement. Instructions which allow an immediate value are limited to registers R16–R31 (8-bit operations) or to register pairs R25:R24–R31:R30 (16-bit operations ADIW and SBIW). Some variants of the MUL operation are limited to eight registers, R16 through R23.

Special purpose registers In addition to these 32 general-purpose registers, the CPU has a few special-purpose registers:

PC: 16- or 22-bit program counter SP: 8- or 16-bit stack pointer SREG: 8-bit status register RAMPX, RAMPY, RAMPZ, RAMPD and EIND: 8-bit segment registers that are prepended to 16-bit addresses in order to form 24-bit addresses; only available in parts with large address spaces.

Status register The status register bits, each of which can be tested with conditional branch instructions, are:

C Carry flag. Set or cleared as appropriate by most arithmetic operations; also used by shift and rotate instructions. Z Zero flag. Set when an arithmetic result is zero, and cleared when it is non-zero. N Negative flag. Set to a copy of the most significant bit of an arithmetic result. V Overflow flag. Set in case of two's complement overflow. S Sign flag. Unique to AVR, this is always N⊕V, and shows the true sign of a comparison. H Half-carry flag. An internal half-byte carry from arithmetic operations. Used to support BCD arithmetic. T Bit copy. Special bit load and bit store instructions use this bit. I Interrupt flag. Set when interrupts are enabled. There are two special cases which exist to facilitate multi-byte arithmetic:

The INC and DEC instructions do not modify the carry flag, so they may be used to loop over arbitrary-precision arithmetic operands. The CPC, SBC and SBCI (compare/subtract with carry) instructions do not set the Z flag when the result is zero, but only clear it if the result is non-zero. For fixed precision multi-byte comparisons, implemented with an unrolled CP; CPC; CPC; CPC sequence, this produces a zero flag which is set only if the entire difference is zero.

Addressing The following address spaces are available:

The general purpose registers are addressed by their numbers (0–31), although the full 5-bit number is not stored in instructions that can only operate on a subset of those registers. I/O registers have a dedicated 6-bit address space, the lower half of which is bit-addressable; some parts have I/O registers outside this address space, which are called "extended I/O" and are only accessible as memory-mapped I/O in the data address space. The data address space maps the 32 general-purpose registers, all the I/O registers (including those also accessible through the I/O address space), and the RAM; it can be addressed either directly or indirectly through the X, Y and Z pointer registers, prepended if necessary by RAMPX, RAMPY and RAMPZ respectively. Program memory (flash) has a separate address space, addressed as 16-bit words for the purpose of fetching instructions For the purpose of fetching constant data, program memory is addressed bytewise through the Z pointer register, prepended if necessary by RAMPZ. The EEPROM is memory-mapped in some devices; in others, it is not directly addressable and is instead accessed through address, data and control I/O registers. The general purpose registers, the status register and some I/O registers are bit-addressable, with bit 0 being the least significant and bit 7 the most significant. The first 64 I/O registers are accessible through both the I/O and the data address space. They have therefore two different addresses. These are usually written as "0x00 (0x20)" through "0x3F (0x5F)", where the first item is the I/O address and the second, in parentheses, the data address. The special-purpose CPU registers, with the exception of PC, can be accessed as I/O registers. Some registers (RAMPX, RAMPY) may not be present on machines with less than 64 KiB of addressable memory.

A typical ATmega memory map may look like:

where RAMEND is the last RAM address. In parts lacking extended I/O the RAM would start at 0x0060.

Instruction timing Arithmetic operations work on registers R0–R31 but not directly on RAM and take one clock cycle, except for multiplication and word-wide addition (ADIW and SBIW) which take two cycles. RAM and I/O space can be accessed only by copying to or from registers. Indirect access (including optional postincrement, predecrement or constant displacement) is possible through registers X, Y, and Z. All accesses to RAM takes two clock cycles. Moving between registers and I/O is one cycle. Moving eight or sixteen bit data between registers or constant to register is also one cycle. Reading program memory (LPM) takes three cycles.

Instruction list Instructions are one 16-bit long word, save for those including a 16-bit or 22-bit address, which take two words. There are two types of conditional branches: jumps to address and skips. Conditional branches (BRxx) can test an ALU flag and jump to specified address. Skips (SBxx) test an arbitrary bit in a register or I/O and skip the next instruction if the test was true. In the following:

… excerpt ends here. Continue reading the full article.

Worked examples

Example 1 — a first encounter with Atmel AVR instruction set

Start with the simplest possible case. Write down what Atmel AVR instruction set claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Atmel AVR instruction set before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Atmel AVR instruction set ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Atmel AVR instruction set

In research
Atmel AVR instruction set appears in science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Atmel AVR instruction set in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Atmel AVR instruction set is common in secondary-school and first-year university syllabi. It links to neighbouring topics Atmel microcontrollers, Instruction set architectures, so understanding it makes those chapters shorter.
In everyday life
Look for Atmel AVR instruction set outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Atmel AVR instruction set” →

How to study Atmel AVR instruction set in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Atmel AVR instruction set means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Atmel AVR instruction set out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Atmel AVR instruction set in simple terms?

The Atmel AVR instruction set is the machine language for the Atmel AVR, a modified Harvard architecture 8-bit RISC single chip microcontroller which was developed by Atmel in 1996. Atmel was acquired by Microchip Technology in 2016.

Why does Atmel AVR instruction set matter?

Because it connects several science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Atmel AVR instruction set?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Atmel AVR instruction set.

Tags

  • Atmel microcontrollers
  • Instruction set architectures

Keep exploring