Feb 95 Challenge
Volume Number: 11
Issue Number: 2
Column Tag: Programmer’s Challenge
Programmer’s Challenge
By Mike Scanlin, Mountain View, CA
Note: Source code files accompanying article are located on MacTech CD-ROM or
source code disks.
Symbolize
This month’s challenge was anonymously suggested. The goal is to make the output of a
non-symbolic disassembler into a symbolic disassembly. The output file of the
non-symbolic disassembler looks like this:
0006CDDE RTS
0006CDE0 LINK A6,#$0000
0006CDE4 MOVE.L A4,-(A7)
0006CDE6 JSR 0006CE12
etc.
The symbol file you are given looks like this (and, yes, the real file I use for testing
will have the LowMem and HiMem values in it so that you’ll be able to find a symbol
for any address):
00000000 LowMem
0006CDDE Foo
0006CDE0 MyFunction
0006CE12 MyOtherFunction
FFFFFFFF HiMem
Your job is to take every 8 byte hex value in the input disassembly and look it up in
the symbol file and then substitute the symbol (and offset) for the value. If you ran
your routine on the above fragment then the output would be this:
[Foo ] RTS
[MyFunction ] LINK A6,#$0000
[MyFunction+4 ] MOVE.L A4,-(A7)
[MyFunction+6 ] JSR MyOtherFunction
The prototype of the function you write is:
void
Symbolize(inputFile, symbolFile, outputFile, symLength)
FILE *inputFile;
FILE *symbolFile;
FILE *outputFile;
unsigned short symLength;
InputFile is a standard C input stream containing the non-symbolic disassembly
(as ASCII text). SymbolFile is a standard C input stream containing addresses (as ASCII
text, not binary) and symbols (sorted by address, lowest to highest). The first symbol
is for address 00000000 and the last symbol is for address FFFFFFFF, as shown in the
example above. OutputFile is a standard C output stream that you send the symbolized
disassembly to (also ASCII text). There is no need to fopen or fclose any of these
streams (my test bench program will do it for you).
SymLength is the number of characters between the ‘[‘ and ‘]’ in the outputFile
(which will range from 12 to 32). All expressions of the form +
from symbol in base 10> should be exactly symLength characters long. Pad with spaces
on the right if it’s shorter and remove characters from the right side of symbolName if
it’s longer (always have the complete offset, unless it’s zero). SymLength is 13 in the
example above.
The largest symbolFile you’ll receive is 512K and the largest inputFile you’ll
receive is 50K. You can assume that you’ll have enough space for the outputFile. Before
returning, your routine should dispose of any memory it might allocate.
Unlike some previous Challenges where you were allowed to write an untimed
Initialize routine, there is no Initialize routine this month. The time it takes you to
parse the symbolFile will be included in your overall time. The average inputFile will
be 20K and contain 800 addresses to look up. The average symbolTable will contain
2000 symbols.
E-mail me if you have any questions. Have fun.
Two Months Ago Winner
Congratulations to Challenge Champion Bob Boonstra (Westford, MA) for earning
his sixth win in the Rubik’s Cube Challenge. This is a special month for Bob because he
has decided to retire from Programming Challenges and become the first person to