This assembler is designed to address some of the syntactic quirks of conventional assembler for vintage architectures. This project sprung from my desire for truly local labels and a consistent label syntax, but evolved into an educational tool, used to further my knowledge of low level programming.
This assembler follows a very uniform syntax akin to that of other assemblers.
[label:] [mnemonic [arguments]] [;comment]
GASMIC also supports various different instruction syntaxes. Namely, GASMIC aims to support Motorola, AT&T, and Intel syntaxes, and provides a pseudo instruction to select the correct syntax.
LDA,
MOVEAX)
[and
].
[and
].
%. (Example: %eax, %A)
(and
).
GASMIC supports arithmetic arguments. Calculations can be performed on a mix of integer constants and symbols. Evaluation follows the order of precedence as given in the following table. (higher in table means higher precedence).
Operation | Operator |
---|---|
Brackets | ( ) |
Multiplication | * |
Division | / |
Addition | + |
Subtraction | - |
Bitwise XOR | ^ |
Bitwise AND | & |
Bitwise OR | | |
Integer constants can be expressed in either base 10 or base 16, with plans to support base 2 and base 8.
Base | Prefix |
---|---|
10 | No prefix |
16 | 0x OR $ |
8 | [Tentative] @ |
2 | [Tentative] 0b or % |
Symbols can be global and local. A global symbol is an alphanumeric string ending with a colon. This string will then have the value of the current address unless it is immediately followed by the equ pseudo instruction.
Local labels can be specified by prefixing a label with a period (.). This label can then be referenced within the scope of the previous global label using the period notation, and can be reached from the global scope by prefixing the preiod notaion with the last global symbol.
Example
.ORG 0xC000 print: LDX data.str .loop: LDA ,X+ BEQ .end STA 0x8000 ; example serial data output BRA .loop .end: RTS data: .str: db 'Hello World', 10, 0
GASMIC supports several pseudo instructions to control metadata about the application. These instructions should be prefixed with a ., but to maintain compatibility, it is not required.
The list of available pseudo instructions and their purpose is described in the table below.
Pseudo Instruction | Description | Examples |
---|---|---|
ARCH |
Set the architecture this application is targetting.
Overrides the command line -mparameter. This pseudo instruction must come before any code. |
.ARCH 6309 .ARCH z80 |
DB | Designate Byte. Assigns the following bytes in memory to the values passed as arguments. When a string is provided, sets the bytes to the ascii values of the characters. No escape characters are currently supported. numbers and strings can be mixed and matched. |
.DB 0, 3, 2 .DB 'Hello' .DB 'Hello World', 10, 0 |
DW | Designate Word, Like DB, saves every number as a 16-bit word in the endianness of the selected architecture.. Strings are saved the same as if they were passed to DB. |
.DW 0x1234 |
DD | Designate Double-word. Like DW, but for 32-bit double-words. |
.DD 0x12345678 |
DQ | Designate Quad-word. Like DWand DD, but for 64-bit quad-words. |
.DQ 0x1122334455667788 |
RESB | Reserve Bytes. Reserves n bytes. | .RESB 3 ; reserve 3 bytes |
RESW | Reserve Words. Reserve n words, n * 2 bytes. | .RESW 5 ; reserve 5 words, 10 bytes |
RESD | Reserve Double-words. Reserve n double-words, n * 4 bytes. | .RESD 2 ; reserve 2 double-words, 8 bytes |
RESQ | Reserve Quad-words. Reserve n quad-words, n * 8 bytes. | .RESQ 1 ; reserve 1 quad-word, 8 bytes |
EQU | Equate a label with an expression. The label will then have the value of the expression. |
l1: .EQU 0x12 l2: .EQU l1 + 3 l3: .EQU 0xAA | 0x55 |
INCLUDE | Include the file at the path provided as a string argument and assemble it as though it was inline. | .INCLUDE "path/to/file.inc" |
INSERT | Inserts the raw bytes of the file at the path given as the string argument into the output file. | .INSERT "/path/to/some/file.jpg" |
ORG | Origin of the program. The address where the program is intended to be loaded to. | .ORG 0x1234 ; all addresses will be relative to this point |