vAVRdisasm - Atmel AVR Disassembler
Note: This project will soon be replaced by ucdisasm.
git clone git://github.com/vsergeev/vAVRdisasm.git
Latest source: vavrdisasm-master zip
Arch Linux AUR Package: http://aur.archlinux.org/packages.php?ID=46699
Please feel free to report any issues at github or by email at vsergeev at gmail.
- Release 3.0 - 02/01/2013
- Complete rewrite of vAVRdisasm to an opcode->disasm->format stream architecture.
- Added decoding support for malformed input that might have single bytes on EOF or address boundaries.
- Added binary file support with
- Added comprehensive fuzzing and avr-objdump comparison test (see crazy_test.py or
- Modified default disassembly output to include original opcodes alongside disassembled instructions.
- Release 2.0 - 09/24/2011
- Changed address operand formatting for LDS, STS, JMP, and CALL instructions from byte addreses to word addresses, to make vAVRdisasm’s output compatible with AVR assemblers.
- Fixed signed relative branch/jump decoding: jumps in the reverse direction are now correctly decoded.
- Thanks to Graham Carnell for the above two fixes!
- Upgraded license from GPLv2 to GPLv3.
- Release 1.9 - 04/03/2011
- CRITICAL FIX: Fixed S-Record reading bug that was ignoring valid data records.
- Added output file support by
- Added standard input support with the “-“ file argument, meaning the disassembler now supports piped input.
- Improved Atmel Generic / Intel HEX8 / Motorola S-Record auto-detection by first character rather than file extension.
- Thanks to Thomas for all four of the above fixes and suggestions!
- Added printing of original opcode data alongside disassembly with
- Release 1.8 - 01/26/2011
- Fixed address decoding for LDS, STS, JMP, and CALL instructions. Reversed the modification from release 1.7.
- Added support for XCH, LAS, LAC, LAT instructions, bringing the disassembler up to date with AVR Instruction Set revision 0856I - 07/10.
- Release 1.7 - 05/27/2010
- Fixed address decoding for LDS, STS, JMP, and CALL instructions. Previously, vAVRdisasm was printing the disassembled address operands as twice the value they should have been for these instructions.
- Release 1.6 - 02/04/2010
- Fixed the number-of-operands field for the SPM instruction. This bug was causing vAVRdisasm to crash as it was attempting to format a non-existing operand during disassembly.
- Updated the README.
- Release 1.5 - 08/25/2009
- Renamed source files to make more sense and for better organization of code.
- Added support for DES, SPM #2, LDS (16-bit), and STS (16-bit) instructions, bringing the disassembler to support the AVR instruction set up to revision 0856H - 04/09.
- Release 1.4 - 06/27/2009
- Fixed handling of newlines (sometimes found at the end of program files) so an “invalid record” error doesn’t appear when a newline is read.
- CRITICAL FIX: Fixed reading and disassembly of odd byte length records in Intel HEX8 and Motorola S-Record files. Special thanks to Ahmed for discovery and patch!
- Release 1.3 - 01/08/2009
- Fixed a few small bugs/typos for cleaner compilation.
- CRITICAL FIX: Corrected the absolute address calculation, used in instructions like absolute jump.
- Release 1.2 - 01/06/2007
- Added formatting of data constants in different bases (hexadecimal, binary, decimal).
- Fixed a small bug/typo: first operand of “out” instruction is actually an I/O register.
- Release 1.0 - 01/03/2007
- Initial release.
vAVRdisasm is an 8-bit Atmel AVR firmware disassembler. This single-pass disassembler can read Atmel Generic, Intel HEX8, and Motorola S-Record formatted files containing valid AVR program binaries.
It supports all 142 8-bit AVR instructions as defined by the Atmel AVR Instruction Set revision 0856I-AVR-07/10.
vAVRdisasm features a handful of formatting options, including:
- Printing the instruction address alongside disassembly, enabled by default
- Printing the destination address of relative branch/jump/call instructions as comments alongside disassembly, enabled by default
- Printing the original opcode data alongside disassembly, enabled by default
- Ghetto Address Labels (see “Ghetto Address Labels” section)
- Formatting data constants in different bases (hexadecimal, binary, decimal)
- .DW data word directive for data not recognized as an instruction during disassembly
- Piped input and output
vAVRdisasm should work on most *nix platforms, including a Cygwin or MinGW environment. vAVRdisasm was written by Vanya A. Sergeev, and tested with the GNU C Compiler on Linux. Feel free to send any ideas or suggestions to vsergeev at gmail dot com.
vAVRdisasm is released under the GNU General Public License Version 3.
You should have received a copy of the GNU General Public License along with this program; see the file "COPYING". If not, see <http://www.gnu.org/licenses/>.
in the vAVRdisasm project directory should compile vAVRdisasm on most *nix systems, including a Cygwin or MinGW environment. The Makefile is configured to use GCC to compile vAVRdisasm.
vAVRdisasm should have no problem being compiled with “gmake”.
Usage: ./vavrdisasm <option(s)> <file> Disassembles AVR program file <file>. Use - for standard input. vAVRdisasm version 3.0 - 02/01/2013. Written by Vanya A. Sergeev - <firstname.lastname@example.org>. Additional Options: -o, --out-file <file> Write to file instead of standard output. -t, --file-type <type> Specify file type of the program file. -l, --address-label <prefix> Create ghetto address labels with the specified label prefix. --data-base-hex Represent data constants in hexadecimal (default). --data-base-bin Represent data constants in binary. --data-base-dec Represent data constants in decimal. --no-addresses Do not display address alongside disassembly. --no-opcodes Do not display original opcode alongside disassembly. --no-destination-comments Do not display destination address comments of relative branch/jump/call instructions. -h, --help Display this usage/help. -v, --version Display the program's version. Supported file types: Atmel Generic generic Intel HEX8 ihex Motorola S-Record srec Raw Binary binary
For most purposes:
$ vavrdisasm <AVR program file>
$ vavrdisasm sampleprogram.hex
- for standard input.
vAVRdisasm will auto-recognize Atmel Generic, Intel HEX8, and Motorola S-Record files. However, the
--file-type option can be used to explicitly select the file format, and to specify a raw binary input file.
$ vavrdisasm -t binary sampleprogram
The file type argument for this option can be “generic”, “ihex”, “srecord”, or “binary”, for Atmel Generic, Intel HEX8, Motorola S-Record, and raw binary files, respectively.
--out-file «output file»
Specify an output file for writing instead of the standard output. The output file
- is also synonymous for standard output.
vAVRdisasm will default to formatting data constants in hexadecimal. However, data constants can be represented in a different base with one of the following options:
By default, vAVRdisasm will print the instruction addresses alongside disassembly, the original opcodes alongside disassembly,and destination comments for relative branch, jump, and call instructions. These formatting options can be disabled with the
See the Ghetto Address Labels section.
--help option will print a brief usage summary, including program options and supported file types.
--version option will print the program’s version.
If you encounter any bugs or problems, please submit an issue on GitHub or notify the author by email, vsergeev at gmail dot com.
Ghetto Address Labels
vAVRdisasm supports a unique formatting feature: Ghetto Address Labels, which few, if not any, single-pass disassemblers implement.
--address-label option and a supplied prefix, vAVRdisasm will print a label containing the non-numerical supplied prefix and the address of the disassembled instruction at every instruction. Also, all relative branch, jump, and call instructions will be formatted to jump to their designated address label.
This feature enables direct re-assembly of the vAVRdisasm’s disassembly. This can be especially useful for quick modification to the AVR program assembly code without having to manually format the disassembly or adjust the relative branch, jump, and call distances with every modification to the disassembly.
--address-label option overrides the default printing of the addresses alongside disassembly.
$ vavrdisasm -l “A_” sampleprogram.hex
vAVRdisasm’s disassembly will include address labels that will look like this: A_0000:
For sample disassembly outputs by vAVRdisasm, see the Sample Disassembly Outputs section.
- vAVRdisasm does not display alternate versions of the same encoded instruction. This means that the “cbr” instruction will never be displayed in the disassembly, because the “andi” instruction precedes it in priority.
These features do not affect the accuracy of the disassembler’s output, and may be supported in future versions of vAVRdisasm.
vAVRdisasm uses libGIS, a free Atmel Generic, Intel HEX, and Motorola S-Record Parser library to parse formatted files containing AVR program binaries. libGIS is available for free under both MIT and Public Domain licenses here. libGIS is compiled into vAVRdisasm—it does not need to be obtained separately.
Sample Disassembly Outputs
These output samples, produced by vAVRdisasm, are a disassembly of the program from the “Notice’s Guide to AVR Development” article in the Atmel Applications Journal.
$ vavrdisasm sampleprogram.hex 0: c0 00 rjmp .+0 ; 0x2 2: ef 0f ser R16 4: bb 07 out $17, R16 6: bb 08 out $18, R16 8: 95 0a dec R16 a: cf fd rjmp .-6 ; 0x6
$ vavrdisasm --no-opcodes sampleprogram.hex 0: rjmp .+0 ; 0x2 2: ser R16 4: out $17, R16 6: out $18, R16 8: dec R16 a: rjmp .-6 ; 0x6
$ vavrdisasm --no-destination-comments sampleprogram.hex 0: c0 00 rjmp .+0 2: ef 0f ser R16 4: bb 07 out $17, R16 6: bb 08 out $18, R16 8: 95 0a dec R16 a: cf fd rjmp .-6
$ vavrdisasm --no-addresses sampleprogram.hex c0 00 rjmp .+0 ; 0x2 ef 0f ser R16 bb 07 out $17, R16 bb 08 out $18, R16 95 0a dec R16 cf fd rjmp .-6 ; 0x6
$ vavrdisasm -l "A_" sampleprogram.hex .org 0x0000 A_0000: rjmp A_0002 ; 0x2 A_0002: ser R16 A_0004: out $17, R16 A_0006: out $18, R16 A_0008: dec R16 A_000a: rjmp A_0006 ; 0x6
The above program sample was modified slightly to illustrate vAVRdisasm’s ability to represent data constants in different bases:
$ vavrdisasm --data-base-bin sampleprogram2.hex 0: c0 00 rjmp .+0 ; 0x2 2: ef 0f ser R16 4: bb 07 out $17, R16 6: ea 0f ldi R16, 0b10101111 8: bb 08 out $18, R16 a: 95 0a dec R16 c: cf fd rjmp .-6 ; 0x8