Skip to content

Commit 3e3f75e

Browse files
committed
readme
1 parent 8811054 commit 3e3f75e

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

readme.md

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Garter Assembler
2+
3+
`gasm` is the intermediate language and assembly language
4+
of the [`garter`](https://github.com/topics/garter) compiler toolchain.
5+
The `gasm` assembly syntax is intended to be platform-agnostic wherever possible.
6+
7+
## Usage
8+
9+
the Garter Assembler takes in `*.gasm` files and generates
10+
`*.gyb` [object files](https://github.com/Modula-dev/gyb).
11+
12+
## Implementation
13+
14+
Lexical analysis breaks apart the source files
15+
into tokens: `keywords`, `labels`/`addresses`, `constants`,
16+
et cetera. Then the parser iterates over the list of tokens
17+
and essentially "interprets" them --
18+
instructions will either change the assembler's internal state,
19+
or be translated and treated as emitter commands.
20+
21+
## How does Object Emission Work?
22+
23+
When the assembler first starts,
24+
it initializes an empty object with
25+
a clean-slate symbol table.
26+
Any time we encounter symbol definitions,
27+
we push those to our symbol table.
28+
29+
Later, somewhere in our `*.gasm` file,
30+
we might see a block of code that looks like
31+
```asm
32+
section executable
33+
move rax, rax
34+
```
35+
`section executable` is a directive that
36+
changes what section the emitter is currently
37+
sending data into,
38+
then the instruction `move rax, rax`
39+
will be converted into data and put
40+
into the selected section.
41+
42+
# GASM Assembly
43+
44+
`gasm` is heavily influenced by x86 Intel Assembly,
45+
FlatAssembler, BASIC, and Python, and looks something like:
46+
```asm
47+
section writeable
48+
hello
49+
u8 "Hello, World" 0
50+
section executable
51+
immediate ar hello
52+
immediate br 12
53+
syscall write stdout ar br
54+
immediate 0
55+
syscall exit ar
56+
```
57+
58+
For tutorials, see the `garter` website.
59+
For a guide on writing Garter Assembly,
60+
see the `garter` specification doc.

0 commit comments

Comments
 (0)