Assemble the microprocessor program asmfile and produce output file codefile in Intel HEX or Motorola S Code format. A program listing and a symbol table are also produced on the standard output. The current version of crasm can assemble programs for the 6800, 6801, 6803, 6502, 65C02, and Z80 processors. The full list is printed when you invoke crasm without arguments.
Each line of the assembly program should follow one of the following templates, where the brackets delimit optional parts.
Comments are introduced by a semicolon (;) and extend to the end of the line. Labels are identifiers containing up to 36 alphanumeric characters (including period and underscore). Labels cannot start with a digit. The format of the mnemonics and operands field depends on the selected micro-processor. A few mnemonics are valid for all processors and are used to give directives to the assembled. These are known as "pseudo-mnemonics".
Labels are identifiers representing
- an absolute address,
- a relative address (position independent code),
- a register,
- a list of registers,
- a specific bit at a specific address,
- or a mnemonic.
Most labels are composed of at most 36 alphanumeric characters, periods (.) or underscores (_). Labels cannot start with a digit. They are case insensitive.
Labels starting with a period (.) are local labels whose scope is either limited to the macro in which they are defined, or to the code segment delimited by the pseudo-mnemonics CODE or DUMMY.
The predefined "star" label (*) represents the current program counter, that is to say, the address where the next assembly code instruction will be encoded. Other predefined labels include all pseudo-mnemonics, micro-processor specific mnemonics and register names.
The assembled recognizes numerical constants expressed in decimal, hexadecimal, octal, binary, or ascii.
Type | Format | Examples |
decimal | dddd | 1234, 675, 12, 1, but not 0.12. |
hexadecimal | $dddd | $fd12, $2AC, $0. |
ddddH | 03H, 2da7H, 0FC84H, but not FC84H. | |
0Xdddd | 0x03, 0x2AC, 0Xfc84. | |
octal | ddddQ | 377Q, 012412Q. |
binary | %dddd | %01110110, %1100. |
ddddB | 01110110B, 1100B. | |
0Bdddd | 0b1100 | |
ascii | 'cccc' | 'a', 'AB', '"', '\n', '\''. |
"cccc" | "a", "AB", "'", "\n", "\"". |
Like labels, expressions can represent an absolute address (abs), a relative address for position independent code (rel), a register (reg), or a list of registers (reglist), or a reference to a specific bit at a specific address (bspec).
The following operators are recognized on expressions.
Syntax | Result | Description |
abs{abs} | bspec | bit reference, e.g. pia{3} |
ADDR(abs) | abs | address from a bit reference |
BIT(abs) | abs | bit number from a bit reference |
- abs | abs | two's complement |
~ abs | abs | one's complement |
abs << abs | abs | left shift |
abs >> abs | abs | right shift |
abs | abs | abs | bitwise or |
abs & abs | abs | bitwise and |
abs ^ abs | abs | bitwise xor |
abs * abs | abs | multiplication |
abs * abs | abs | division |
abs + abs | abs | addition |
rel + abs | rel | addition |
abs - abs | abs | subtraction |
rel - abs | rel | subtraction |
rel - rel | rel | subtraction |
reg - reg | reglist | register range |
reglist \ reg | reglist | register list construction |
The table lists operators in order of decreasing precedence. Parenthesis can be used to avoid ambiguities. A warning is generated when an entire expression is surrounded with parenthesis and can be confused with a micro-processor addressing mode.
Examples:
The last example causes a warning because the parenthesis were not necessary and might suggest a micro-processor addressing mode.
All arithmetic expressions are evaluated on 32 bits. Arithmetic operations overflow silently. The arithmetic values are then truncated to the size implied by the micro-processor mnemonic. This truncation might cause a warning message.
Examples: all the following instructions
cause a warning
However expression
overflows silently.
The following pseudo-mnemonics are always recognized.
Here is a small 6502 program:
cpu 6502 cout = $fded ; display a character * = $300 ; assemble at $300 code pstring ldy #0 .1 lda message,y beq .2 jsr cout iny .2 bne .1 rts message asc "This is the message " code
Assembling this program gives the following listing:
Crasm LYB 1.3: page 1 1 2 cpu 6502 FDED 3 cout = $fded ; display a character 0300 4 * = $300 ; assemble at $300 5 code 0300 A000 6 pstring ldy #0 0302 B90E03 7 .1 lda message,y 0305 E004 8 beq .2 0307 20EDFD 9 jsr cout 030A C8 10 iny 030B D0F5 11 .2 bne .1 030D 60 12 rts 030E 54686973206973 0315 20746865206D65 031C 737361676500 13 message asc "This is the message\0" 14 code 15 ERRORS: 0 WARNINGS: 0 Successful assembly... Last address 321 (801) Code length 44 (68) Crasm LYB 1.3: page 2 FDED Abs COUT ^030E Abs MESSAGE ?0300 Abs PSTRINGand the following S Code file:
S1130300A000B90E03E00420EDFDC8D0F5605468E8 S1130310697320697320746865206D657373616700 S1050320650072 S9030000FC
Leon Bottou, September 1987.