ASEM-51 is a great tool. It's the only free MCS-51 assembler which both runs on Linux and supports macros.
However it lacks some features that are commonly found in modern toolchains:
I first asked the ASEM-51 author W.W. Heinz if he could give me the ASEM-51 source code in order I can add these features. He refused. So I decided to write two external tools which implement the features I need on top of ASEM-51.
Both tools are written in C, each contain only one file and does not use any external library. I believe this will help anyone who wants to compile them on non Linux platforms. I used GCC, few changes may be necessary to compile with other compilers. I did not use lex/yacc in order to make the code easy to port, as a result the parse rules are not easy to understand.
You are free to modify and use the tools as you want. I hope my comments in the code will help.
There are no license or distribution rules.
I don't guarantee any help or maintainance.
Obviously there is no warranty.
It would be nice to send me fixes if you find some of numerous bugs I certainly missed.
The tool asem_alloc.c checks the memory allocation rules (my own rules).
ASEM-51 defines five segments : DSEG, CSEG, BSEG, ISEG, XSEG
These rules are checked in the StoreDataByte() function. You can modify it if yours are different.
The tool reads from stdin a listing file produced by ASEM-51 and writes
on stdout a report of the memory usage and allocation errors.
There are no online options.
Usage: asem_alloc < inputfile > outputfile
The tool asempp.c
is a pre-processor (like CPP for C/C++) which implements user-defined
segments. The original code is instrumented to implement the user segments
with help of SEG/ORG statements and labels. The output file is a concatenation
of all input 'included' files. It can be assembled by ASEM-51 and possibly
checked with ASEM_ALLOC.
Unfortunately the original line numbers are lost, ASEM-51 does not implement CPP-like 'pragmas' to overide filenames and line numbers.
The instrumented code checks user segment boundaries. Expressions can be used inside ASEMPP statements, they are copied as is into the output file. The pre-processor does not perform any expression evaluation, everything is passed to ASEM-51.
I tried to follow the ASEM-51 parse rules such as case insensitive names. The ASEM51INC environment variable is also supported.
USAGE: asempp inputfile outputfile
SEG segment_name IN xSEG AT first_addr, last_addr define a segment named
allocated in the ASEM-51 segment xSEG with defined absolute address boundaries. SEG segment_name switch to an already defined segment
xSEG denotes one of DSEG, CSEG, BSEG, ISEG, XSEG
ORG command can be used in the user segments, even if I don't see why someone would do that.
The allocation rule inside every segment is the same as in built-in ASEM-51 ones: the allocation counter is incremented in a linear way. An error is thrown if allocation exceeds the segment's boundaries.
User segments can overlap. If you are not happy with that you can add the required checks to the AddNewUserSegment() function. I use asem_alloc to check all that.
User segments does not prevent ASEM-51 from allocating built-in segments inside the user defined ones. To avoid these problems the entire built-in segments should be covered by user defined not overlapping segments. As used defined segments check their boundaries they will never overlap.