Summary of AVR assembly language
AVR stands for Advanced Virtual RISC, an 8-bit microcontroller using Harvard RISC architecture. It features 8-bit registers and executes most instructions in a single clock cycle. The article explains how to control digital I/O pins via Data Direction Registers (DDRn) to drive components like LEDs.
Parts used in the AVR Project:
- 8-bit AVR microcontroller
- 4 MHz X-tal (crystal oscillator)
- LED
- 330 ohm resistor
What is an AVR ?
First of all AVR stands for: Advanced Virtual RISC. The founders are Alf Egil Bogen Vegard Wollan RISC (also forms AVR). An AVR is a small microcontroller (chip, IC) which is switching digitally (controller) by means of so called i/o’s (input/output pins) The i/o’s do all the digital switching. The AVR’s used on this website are 8-bit AVR’s, meaning 1 byte (1 byte = 8 bits) width working registers, a register is a place in the AVR where you can store and manipulate bits, you can do this with the 118+ so called instructions.
The AVR is based on the Harvard RISC architecture which means that one instruction only takes about one clock-cyle, which again means if you put an X-tal of 4 MHz to the AVR, the processing speed is 4 MIPS (million instructions per second) Most instructions are only one clock-cycle (1/ck -> 1/4.000.000 sec), some are two clock-cycles (2/ck) The instructions are abbreviations of names, i.e ldi means: Load Immidiate, what means; load a value directly to a register, i.e.:
ldi temp, 0x0A
In this example, you load (put) the value 0x0A (hexadecimal value) into the register ‘temp’. 0x0A means A (= 10 decimal). What does this mean? You know the registers are 8 bit width, so if you really want to see how the value 0x0A sits in the register, you must convert is to binairy (the processor only operates with 1’s and 0’s), then you will see this: 00001010. So you already know the maximum value per register is 11111111 (255), with AVR assembly you write values like this: binairy = 0b00001010, decimal = 10, hexadecimal = 0x0A.
So how can I make a LED go on and off ?
An AVR has one or more so called PORTs, this is a register which is controlling the pins of the AVR, you can make a pin an input or an output, this is done with the Data Direction Registers DDRn (n is A, B, C or D, depends on which AVR using), suppose you want to make pin 11 of PORTD an output, do this:
sbi DDRD, led
If ‘led’ was 6 (PD6), pin 11 would become an output (because you did Set the 6th bit in the DDRD register) Now you made this i/o as an output. The next thing to do is, make the pin high and low with a certain speed, by connecting a LED + serie resistor (330 ohm) on the pin, you can see what really happens. Connect like this:
For more detail: AVR assembly language
- What does AVR stand for?
AVR stands for Advanced Virtual RISC. - How fast is the processing speed with a 4 MHz X-tal?
The processing speed is 4 MIPS (million instructions per second). - What is the width of the working registers in these AVRs?
The working registers are 8 bits wide. - How many clock cycles do most instructions take?
Most instructions only take one clock-cycle. - What does the instruction ldi mean?
ldi means Load Immediate, which loads a value directly to a register. - How do you make a pin an output on an AVR?
You set the corresponding bit in the Data Direction Register DDRn. - What component is needed to see what happens when a pin goes high or low?
An LED connected with a series resistor is needed.

