navigationGo.pngQuick Navigation
allprojects32.pngAll projects
hardware32.pngHardware
links32.pngLinks

favoriteStar32.pngTop projects
Alan numitron clock
Clapclap 2313/1386
SNES Pi Webserver
USB Volume/USB toys
Smokey amp
Laser cutter
WordClock
ardReveil v3
SNES Arcade cabinet
Game boy projects
cameleon
Home Presence Detector

github32.pngGitHub
AlanFromJapan

navigationMail.pngContact me

alanfjmail.png
3flags.pngWho's Alan?


Akizukidenshi
Elec-lab
Rand Nerd Tut
EEVblog
SpritesMods
AvrFreaks
Gameboy Dev
FLOZz' blog
Switch-science
Sparkfun
Suzusho
Datasheet Lib
Reddit Elec
Ermicro
Carnet du maker (fr)

Atmel assembler

Last update: Thu Jun 5 22:25:40 2025
kalshagar - Atmel assembler

Things to know

Project and AVR Studio

  • Assembler files are .S files
  • You can mix .c ans .S files in the programe, no problem
  • Your .c files gets interpreted as pseudo assembler file in the .??? file of your solution. Nice to see what your code becomes and where is the error coming from.

ASM : jmp, call, and flow control

  • The rjmp/jmp, rcall/call, ... is that the r-version work for "close" addresses and the non-r version for the long jumps, and are not implmented on small uC (like tiny2313)
    • Simple trick : code everything with a rjmp and rcall, the compiler will tell you if you need to use the long-range version.
  • jmp just change the Stack Pointer, call is a subroutine call that and you return to previous location%201 using ret

Registers

  • Affect a register to a variable (uint8_t) with register volatile uint8_t variable01 asm("r2");
    • Reserved to r2 .. r7
  • r0 is always free temp variable
  • r1 should be always 0, so reset after use (clr r1) or just avoid
  • r18-r27, r30-r31 are used when mixing C and ASM so save them before
  • r2-r17, r28-r29 are not used for callign C so just mind your ASM and push/pop if needed
  • Detailed registers explanation : http://www.gnu.org/savannah-checkouts/non-gnu/avr-libc/user-manual/FAQ.html#faq_reg_usage

Playing with memory

Read and Write in SRAM

The key commands are LD... and ST..., with variants if you use the address register X or Y.

Links

General AVR ASM tutorials


Mixing C and ASM

All content on this site is shared under the MIT licence (do what u want, don't sue me, hat tip appreciated)
electrogeek.tokyo ~ Formerly known as Kalshagar.wikispaces.com and electrogeek.cc (AlanFromJapan [2009 - 2025])