Wednesday, March 26, 2008

ImageCraft and AS430 Library Formats for the MSP430

by Travis Goodspeed <travis at>
at the Extreme Measurement Communications Center
of the Oak Ridge National Laboratory

I've been playing with various MSP430 compilers lately in an attempt to add import macros to msp430static. GNU's objdump makes this trivially easy for mspgcc, but I haven't been so lucky with the other compilers. One exception is ImageCraft's compiler, whose library format is beautifully manageable. This short article will discuss that format, with sufficient depth that a decoder or encoder script may be written. I will also discuss another tool, the AS430 assembler, which uses a similar file format.

A free 4kb version is available at It works perfectly in Linux, just run `wine iccv7430_demo.exe', installing it to /opt/iccv7430/. Once installed, the IDE can be launched by `wine /opt/iccv7430/bin/icc430ide.exe'.

The following image shows the opening lines of libc.a, which is in a relocatable object format similar to that of the AS430 linker's.

You can find a description of the linking format, here.

The S-line tells us that the object's symbol name is _abs. The T-line contains the object code, "00 00 0e 93 03 34 3e e0 ff ff 1e 53 30 41". This R-line specifies no relocation.

The code, which begins at the third byte of the T-line, disassembles to the following in word-wise notation:
0x930E cmp #0, r14
0x3403 jge +8
0xE03E XOR #0xFFFF,r14
0x531E add #1, r14
0x4130 ret

Quite obviously, this inverts and adds 1 to r14 if its value is less than 0. In C,
int _abs(int x){
return -x;
return x;
It's worth noting that r14 can be inverted with a single word, 0xE33E, rather than the two used here by use of the constant generator. That is exactly what GCC does:
   0:   0f 93           cmp     #0,     r15     ;r3 As==00
2: 02 34 jge $+6 ;abs 0x8
4: 3f e3 inv r15 ;
6: 1f 53 inc r15 ;
8: 30 41 ret
Getting back to the format at hand, AS430 may be downloaded here. Go for the latter link, as it's direct and doesn't require that you run Simtel's win32 downloader application.

Once downloaded, Linux users should install by use of the following commands:
karen% sudo ln -s `pwd`/ASXMAK/LINUX/EXE/AS430 /usr/local/bin/as430
karen% sudo chmod +x ASXMAK/LINUX/EXE/*
Moving the T430.ASM example to T430.asm, calling "as430 -o T430" creates T430.rel, in the same relocatable object format used above. It's rather inconvenient that the tool is case-sensitive and windows-oriented, but it works well in Linux once you recognize its difficulty with case-sensitive filesystems.

Object division is different in ImageCraft. Note the ^M entries in the screenshot, which in emacs denote a CR. The entries only exist between the .begin/.end macros, suggesting that the file was produced with more than one tool. This makes sense: one tool is the archiver, while the other is the assembler. The archiver uses LF, as in Unix textfiles, while the assembler uses CRLF, as in DOS textfiles.

Just to be sure this would ship in production code, I used abs() in an example project and found the following in the output ihex:
'3EE0FFFF' is the little-endian equivalent of '0xE03E 0xFFFF' above.

Some other formats, all of them ASCII, deserve mention here. The first being the debug format, which is built into PROJECT.dbg by the IDE.
DIR z:\home\travis\tmp\icc\
FILE foo.c
FUNC main F052 fV
BLOCK 3 F052
LINE 3 F052
LINE 4 F052
LINE 6 F060
LINE 6 F062
LINE 6 F062
LINE 6 F064
FILE foo.s
LINE 16 F052
LINE 17 F056
LINE 18 F05A
LINE 19 F05C
LINE 22 F05E
LINE 25 F060
LINE 30 F062
LINE 33 F064
LINE 34 F066
LINE 38 F068
This is easy enough to read. FILE defines a source file, FUNC defines a function, BLOCK defines a region of code, DEFREG defines which register a variable is contained within, and LINE denotes the address to which a particular line has been compiled.

PROJECT.lst contains annotated machine code. describes memory areas and linking information.

PROJECT.mak is a makefile. Building from the command-line works perfectly with the proper environment variables, but without them the unregistered version will refuse to run outside of the IDE.
karen% wine /opt/iccv7430/bin/imakew.exe -f FOO.mak 
icc430 -c -IC:\icc\include\ -e -D__ICC_VERSION="V7.06A" -DF148 -l -g -Wf-hwmult -Wa-g z:\home\travis\tmp\icc\foo.c
icc430 -o FOO -LC:\icc\lib\ -g -blit:0xF000.0xFFDF -bdata:0x0200.0x0A00 -dram_end:0x0A00 -fintelhex -binfo:0x1000
Device 3% full.
I like the ASCII nature of the compiler's file formats, which makes them very easy to parse. For this reason, the compiler was the first after GCC to be supported in msp430static.

1 comment:

Blogger said...

If you want your ex-girlfriend or ex-boyfriend to come crawling back to you on their knees (no matter why you broke up) you must watch this video
right away...

(VIDEO) Text Your Ex Back?