ATmega Python Package

Author: David Boddie
Date: 2012-03-16
Version: 0.1.0

Note: This text is marked up using reStructuredText formatting. It should be readable in a text editor but can be processed to produce versions of this document in other formats.


The ATmega series of CPUs are a family of microcontrollers produced by Atmel with the AVR architecture. These 8-bit CPUs are used in the Arduino open source electronics prototyping platform.

The ATmega Package

A Python package is provided that provides facilities for assembling and disassembling code that can be run on CPUs in the ATmega series. Code is assembled as a sequence of opcodes that can be serialised as program listings or written out in Intel HEX format.

  • The definitions module contains classes that describe features of the CPUs and helper classes for instruction validation and assembly.
  • The instructions module contains classes that define the opcodes in the AVR instruction set, as well as classes for instruction parsing, validation and lookup.
  • The assembler module provides a class with a convenient interface for assembly of sequences of instructions and creation of HEX files.
  • The disassembler module provides a class with a convenient interface for disassembly of binary data containing opcodes and HEX files.


The tool depends on the pySerial module.


To install the package alongside other packages and modules in your Python installation, unpack the contents of the archive. At the command line, enter the directory containing the script and install it by typing the following:

python install

You may need to become the root user or administrator to do this.


Currently, the following tools are provided in the Tools directory.

  • reads HEX files and displays listings of their contents.
  • is used to send files to an Arduino board attached via a USB cable.
  • is a helper module that is used by the tool to reset the Arduino after a new program has been uploaded to it.


The Tests directory contains simple test programs used at various times to manually verify assembler output.


The Examples directory contains example programs that demonstrate the use of the modules in the package.


The contents of this package are licensed under the GNU General Public License (version 3 or later):

ATmega, a Python package for assembling and disassembling ATmega code.
Copyright (C) 2012 David Boddie <>

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <>.