Skip to content

Commit 1881ad1

Browse files
committed
🔥 Publication of the first version of AsmX G3
0 parents  commit 1881ad1

File tree

97 files changed

+14742
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+14742
-0
lines changed

‎README.md‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# AsmX G3 Compiler
2+
3+
## Command Line Interface (CLI) Usage
4+
5+
### Usage
6+
7+
```
8+
asmx [file] [options]
9+
```
10+
11+
### Example
12+
13+
```
14+
asmx main.asmx
15+
asmx main
16+
asmx main --release --march x86_64 -o index
17+
```
18+
19+
### Options
20+
21+
| Option / Flag | Description |
22+
|-------------------------|--------------------------------------------------------------------|
23+
| `-h`, `--help` | Display this information |
24+
| `-v`, `--version` | Display the version number |
25+
| `--dumpversion` | Display the version of the compiler |
26+
| `--dumpmachine` | Display the compiler's target processor |
27+
| `--profiletime` | Enable the time profiler |
28+
| `--hinfo` | Hide confidential information |
29+
| `@file`, `--file file` | Specify the file for processing parameters |
30+
| `--llvm@version` | Display the LLVM version card |
31+
| `--llvm@dumpversion` | Display the LLVM version |
32+
| `--llvm@repository` | Display the LLVM repository |
33+
34+
### Compilation Options
35+
36+
| Option / Flag | Description |
37+
|-------------------------|--------------------------------------------------------------------|
38+
| `-r`, `--release` | Create an executable file |
39+
| `-o`, `--objname` | Set the output file name |
40+
| `-m`, `--march` | Specify the target CPU architecture (`x86_64`, `riscv`, `arm64`) |
41+
42+
### Commands
43+
44+
| Command | Description |
45+
|-------------------------|--------------------------------------------------------------------|
46+
| `--update` | Update AsmX compilation platform |
47+

‎examples/compile.asmx‎

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
@include libc;
2+
3+
@section rodata {
4+
message: str("Hello World!\n"),
5+
declare: str("This is declare section\n"),
6+
archlinux: str("\uf303 -> Arch Linux\n")
7+
}
8+
9+
@fn pub main {
10+
@mov $0, %rdi
11+
@add $10, %rdi
12+
@cmp $0, %rdi
13+
14+
@mov $1, %rax
15+
@mov $1, %rdi
16+
@mov &message, %rsi
17+
@mov $21, %rdx
18+
@syscall
19+
20+
@mov $1, %rax
21+
@mov $1, %rdi
22+
@mov &declare, %rsi
23+
@mov $24, %rdx
24+
@syscall
25+
26+
@mov $1, %rax
27+
@mov $1, %rdi
28+
@mov &archlinux, %rsi
29+
@mov $24, %rdx
30+
@syscall
31+
32+
@mov $60, %rax
33+
@mov $0, %rdi
34+
@syscall
35+
}

‎examples/cpuid.asmx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
@function main {
3+
@cpuid
4+
@push $eax
5+
@system 4
6+
}

‎examples/factorial.asmx‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
@label _factorial {
3+
@push "end of factorial";
4+
@system 4;
5+
@push "factorial (n): ";
6+
@system 3;
7+
@push $eax;
8+
@system 3;
9+
@system 1;
10+
}
11+
12+
@label factorial {
13+
@cmp $ecx, 1;
14+
@jle _factorial;
15+
@mul $eax, $ecx;
16+
@dec $ecx;
17+
@jmp factorial;
18+
}
19+
20+
@function main {
21+
@mov $ecx, 5;
22+
@mov $eax, 1;
23+
@goto factorial;
24+
}

‎examples/gpu.asmx‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
@function main {
3+
;; to go to the GPU mode
4+
@mode 1
5+
6+
;; set window x and y to 0
7+
@mov $wdx, 0
8+
@mov $wdy, 0
9+
10+
;; set window width and height
11+
@mov $wsw, 800
12+
@mov $wsh, 600
13+
14+
;; to go to the CPU mode (default mode)
15+
@mode 0
16+
}

‎examples/index.asmx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
@function main(int argc, char[] argv) {
3+
@push "Hello World!";
4+
@system 4;
5+
6+
@push "AsmX G2 is awesome!";
7+
@system 4;
8+
};

‎examples/math.asmx‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
@function main(int argc, char[] argv) {
3+
@add 285960729238, 285960729238;
4+
@push $eax;
5+
@system 4;
6+
7+
@push $edx;
8+
@system 4;
9+
}
10+

‎examples/memory.asmx‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
@function main(int argc, char[] argv) {
3+
@call malloc(210);
4+
5+
@call malloc(65532);
6+
@push $ax;
7+
@system 4;
8+
9+
@call free($ax);
10+
11+
@call sizeof($ax);
12+
@push $eax;
13+
@system 4;
14+
15+
@call sizeof(sizeof(uint8));
16+
@push $eax;
17+
@system 4;
18+
19+
@call calloc(10, sizeof(sizeof(uint16)));
20+
@push $ax;
21+
@system 4;
22+
23+
@call mem_free($ax);
24+
25+
@call sizeof($eax);
26+
@push $eax;
27+
@system 4;
28+
29+
@push "Great Success! 🔥";
30+
@system 4;
31+
};

‎examples/memory_read.asmx‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
@label _end {
3+
@system 1;
4+
}
5+
6+
@label memory_print {
7+
@cmp $imm0, 1
8+
@jle _end
9+
@push [$imm1]
10+
@system 4
11+
@dec $imm0
12+
@inc $imm1
13+
@jmp memory_print
14+
}
15+
16+
@function main {
17+
@store $mm0, uint16 [120] ;; $mm0 = [120, 0x00, 0x00, 0x00] $mmi0 = 0x01
18+
@store $mm0, uint16 [120] ;; $mm0 = [120, 120, 0x00, 0x00] $mmi0 = 0x02
19+
@store $mm0, uint16 [120] ;; $mm0 = [120, 120, 120, 0x00] $mmi0 = 0x03
20+
@store $mm0, uint16 [120] ;; $mm0 = [120, 120, 120, 120] $mmi0 = 0x04
21+
22+
@push $mm0
23+
@system 4 ;; output: $mm0 = [120, 120, 120, 120]
24+
25+
@mov $imm0, 50
26+
@mov $imm1, 0
27+
@goto memory_print;
28+
}

‎examples/mmx.asmx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
@function main {
3+
@store $mm0, uint16 [120] ;; $mm0 = [120, 0x00, 0x00, 0x00] $mmi0 = 0x01
4+
@store $mm0, uint16 [120] ;; $mm0 = [120, 120, 0x00, 0x00] $mmi0 = 0x02
5+
@store $mm0, uint16 [120] ;; $mm0 = [120, 120, 120, 0x00] $mmi0 = 0x03
6+
@store $mm0, uint16 [120] ;; $mm0 = [120, 120, 120, 120] $mmi0 = 0x04
7+
8+
@push $mm0
9+
@system 4 ;; output: $mm0 = [120, 120, 120, 120]
10+
11+
@push $mmi0
12+
@system 4
13+
14+
@mov $mmi0, 0
15+
@mov $ax, 14
16+
@load [$ax], $mm0
17+
@push [$ax]
18+
@system 4
19+
}
20+

0 commit comments

Comments
 (0)