NAME
macasm - assemble MAC1 assembly language into hexadecimal code
SYNOPSIS
mac.assem [source_file] [result_file]
DESCRIPTION
macasm is one of a set of software tools designed for the hardware described in Chapter 4 of Structured Computer Organization (SCO), 2nd Edition by Andrew S. Tanenbaum.
This is a two pass assembler. Pass one builds a symbol table and checks for syntax errors, especially nonalphanumeric characters. As each line is inspected and approved, it is written to a temporary file. However labels, comments, assignment statements and literals are not written. If there are any errors, writing to the temporary file is disabled and the second pass will not be initiated. Pass two takes the opcodes and operands from the temporary file and prints them out in hexadecimal to the output_file. If a source_file is not specified, mac.assem expects input from the standard input (the keyboard or a redirected file). If only one file is provided as an argument, it is assumed to be the source_file.
USAGE
The macroprogram may begin on any line of the macrocode, in any column, and there may be blank lines in the file. The same format and syntax as shown in Figure 4.11(b) of SCO should be followed. Valid instructions include those listed in Figure 4.14 and the new instructions defined by the instructor. The four fields must be separated by at least one tab or space. Instructions may be in either upper case or lower case or a mixture of both. Avoid inconsistent naming of labels and constants. For example `PusH' and 'pUSH' are identical, but staRT: . . . will not be matched by `JUMP START', the different `starts' correspond to different addresses!
Constants and literals are defined as follows:
maxchars: 30
/ There must be space between : and the value
/ Constants may be negative numbers (-32768 <= Constant <= 32767)
size = 20
/ There must be space both before and after =
/ 0 <= Literal <= 4095
Each field except the comment field (which begins with a `/' and ends with a newline) must be less than 30 characters long, and each line must be less than 255 characters long. If the assembler detects an error, it will indicate the line on which it occurred and what it was. Depending on the severity of the error, the assembler may abort, or finish the first pass, and then terminate.
Labels must be on the same line as the instruction and cannot be instruction names, unless at least one character is in upper case.
Note: a temporary file called macasm.tmp will be created and destroyed by the assembler during the assembly process. It contains the code after the first pass.
The assembler has macro capabilities. To use a macro it must declared before it is called. A macro may not be called from within another macro. There is no limit on how many macros can be defined.
To declare a macro:
startmacro
macroname
<code>
endmacro
To call a macro:
macro macroname
Addition and subtraction are available for the instructions with 12 bit addresses. They cannot, however, result in a negative number. The equation can use numbers and literals, and can not have any spaces in it. Examples of valid equations are:
loco a+b
addd +4-2
subd -4+e
EXAMPLE
INPUT:
/ This program assembles and executes; but it doesn't accomplish anything useful.
/ Programmer's numbers are interpreted as decimal, NOT hex values!
Q = 256 / this is a literal
ans = 1 / fields can start in any column
startmacro POP3 /this is a macro definition.
pop /this macro does 3 stack pops.
pop
pop
endmacro
jump main
pmul: desp ans
lodl Q / fields can begin anywhere!
addd neg
macro POP3 / call macro defined above
loco -ans+1 / add and subtract used in 12 bit instructions
halt
main: jump pmul
c20: 20 / constants can also be negative
neg: -4
OUTPUT:
6009
fe01
8100
200b
f600
f600
f600
7000
ffff
6001
0014
fffc
SEE ALSO
mic1asm
BUGS
Bugs should be mailed to the Internet address "amer@dewey.udel.edu".
AUTHORS
Shirley Peters, Brandon Einhorn - designed under the supervision of Professor Paul Amer for use in the University of Delaware's CIS 360: Computer Architecture classes.