embed large tables/data blocks in AVR assembler

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is a useful utility that reads a file (binary or otherwise) and produces a formatted output file ready to be included as an 'inc' file in your assembler source.

How to use....
==================================================

Usage: incbuilder sourcefile destfile label

This software is free. NO WARRANTY
use at your own risk

sourcefile can be binary, text, whatever...
If 'label' is omitted then a default label is created as the
source filename before the dot

If label is 'nolab' then no label for the table is created.

eg. The command line "incbuilder test.txt outfile.inc table_1" created a file
with the following contents....

; sourcefile "test.txt"
; processed on: Thu Feb 14 13:42:02 2013

table_1:
.db 0x41,0x52,0x56,0x20,0x72,0x6f,0x63,0x6b
.db 0x73,0x2c,0x20,0x41,0x72,0x64,0x75,0x69
.db 0x6e,0x6f,0x20,0x74,0x6f,0x6f,0x21,0x0a
.db 0x54,0x69,0x6d,0x65,0x20,0x66,0x6f,0x72
.db 0x20,0x61,0x20,0x63,0x69,0x64,0x65,0x72
.db 0x20,0x3a,0x29,0x0a

; Read 44 bytes from sourcefile "test.txt"
===========================================

This is useful for making include files for tables of data. Could be sine wave lookups, embedded web pages, font tables... etc etc

There seems to be no easy way to embed a binary file into assembler source but this gets round the problem.

Using AS6, I run it as part of the pre-build for my solution so that the created file is always up to date with any changes made to the sourcefile material.
I'm using it to embed web pages and other items.

Hope you find it useful.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think this is best located in the Academy forum, do you mind if I move it there?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

No problem. I was not sure where to put it.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The zip file seems to be corrupt, I can't open it.
I had to write a shell-script that do the same thing ;-)

#!/bin/sh

if [ $# -lt 1 ]
then
    echo 1>&2 "Usage: `basename $0` infile [label] [>outfile]"
    exit 1
fi

echo "; Sourcefile \"$1\""
echo "; Processed `date`\n"

if [ $# -ge 2 ]
then
    echo "$2:"
fi

od -v -w8 -t x1 -A n $1 | sed 's/ /,0x/g; s/^,/.db /'

echo "\n; Read `cat $1|wc -c` bytes from sourcefile \"$1\""
==============================================================
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

I had to write a shell-script that do the same thing

If you have vim installed (apt-get install vim presumably?) then you have xxd which can come pretty close to this without even needing a shell script ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes I know, I've used it for C-includes and for the first version of this script. But I had to post process the output to get the assembler style so I thought it was better to use "od" which I think is installed by default on all Unix/Linux systems.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I just downloaded it and ran it, worked fine for me so ?
Its my first ever C program (for a PC), I used MinGW. Could it need a DLL or library that is with MinGW?
I know little about C, just learning using the Arduino environment.
I normally write in assembler which is why I made this utility, so I can embed binary data into assembly files.

I uploaded a .tar file instead. perhaps it will work.

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The tar version was OK, and your program seems to do what it's supposed to do (tested with wine in Ubuntu).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's my od/sed-version as makefile rules instead of a shell-script. I think it works in Studio too if one uses a makefile (untested),

# create data.inc from binary file data.dat
data.inc: data.dat
	@echo "Creating $@ from $<"
	@echo "; Sourcefile \"$<\"" > $@
	@echo "; Processed `date`\n" >> $@
	@od -v -w8 -t x1 -A n $< | sed 's/ /,0x/g; s/^,/.db /' >> $@
	@echo "\n; Read `cat $<|wc -c` bytes from sourcefile \"$<\"" >> $@

Replace leading spaces with a tab to make make happy.

======================================================================
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What leading spaces? The output .db listing is tabbed.
The only spaces are in the comment lines.
\t.db\t0x??,0x?? etc...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I was talking about my makefile rules, they need to have leading tabs instead of spaces but the forum software insists on displaying each tab as four spaces.

Your program seems to work fine.