4 Commits

Author SHA1 Message Date
f737d1e695 examples 2024-12-22 14:08:57 +01:00
02b2ed46c7 add fibo example 2024-12-22 11:47:16 +01:00
e4aac05b9a update README 2024-12-21 11:00:57 +01:00
ddb9853ac4 add facto example 2024-12-21 10:55:33 +01:00
3 changed files with 74 additions and 1 deletions

View File

@@ -10,7 +10,7 @@ There are 3 format types :
- "int" : 32 bits integers are written. Exemple : `10878976`
- "binint" : bits are written. Exemple : `00000000 10100110 00000000 00000000`
- "bin" : the file is written in pure binary
- "logisim" (default) : the file is written in binary for use in LogiSim
- "logisim" (default) : the file is written in hexa for use in LogiSim
## Exemple
@@ -60,6 +60,8 @@ Produces
11111000 00000000 00000000 00000000
```
Other examples are located in the `examples` folder
## Releases
Pre-compiled binaries are available in the [Release](https://git.ale-pri.com/Persson-dev/Assembleur/releases) section.
@@ -92,4 +94,8 @@ Parses the file `test.asm` and writes the output into the file `memory`
You can also add the binary to your path using
```bash
xmake install
```
or copy the binary in the `bin` folder after
```
xmake install -o .
```

30
examples/facto.asm Normal file
View File

@@ -0,0 +1,30 @@
XOR R0 R0 R0
ADD R0 R0 #5 # n = 5
XOR R6 R6 R6
XOR R7 R7 R7
ADD R7 R7 #35 # SP = 40
STR R0 R7 # on empile n
CALL facto # on appelle facto dessus
JMP fin # on saute à la fin du programme
facto:
LD R1 R7 # on dépile n
JEQU R1 R6 ff # si n = 0, on retourne 1
SUB R2 R1 #1 # sinon, R2 prend n -1
ADD R7 R7 #1 # on incrémente le SP
STR R2 R7 # on empile n - 1
CALL facto # on appelle facto
LD R3 R7 # on dépile le résultat
SUB R7 R7 #1 # on décrémente le SP
LD R4 R7 # on dépile n
MUL R1 R3 R4 # on multiplie n avec facto(n-1)
STR R1 R7 # on empile facto(n)
RET # on retourne
ff:
XOR R3 R3 R3
ADD R3 R3 #1 # R3 = 1
STR R3 R7 # on empile facto(0) = 1
RET # on retourne
fin:
LD R1 R7 # on met le resultat final dans R1
stop:
JMP stop # boucle infinie de fin

37
examples/fibo.asm Normal file
View File

@@ -0,0 +1,37 @@
XOR R0 R0 R0
ADD R0 R0 #7 # n = 7
XOR R1 R1 R1
ADD R1 R1 #1 # constante à 1
XOR R7 R7 R7
ADD R7 R7 #40 # SP = 40
STR R0 R7 # on empile n
CALL fibo # on appelle fibo dessus
JMP fin # on saute à la fin du programme
fibo:
LD R2 R7 # on dépile n
JSUP R2 R1 suite # si n <= 1, on retourne n (donc on ne fait rien)
RET
suite:
SUB R2 R2 #1
STR R2 R7 # on empile n - 1
ADD R7 R7 #1
SUB R2 R2 #1
STR R2 R7 # on empile n - 2
CALL fibo
LD R2 R7 # on dépile fibo(n-2)
SUB R7 R7 #1
LD R3 R7 # on dépile n - 1
STR R2 R7 # on empile fibo(n-2)
ADD R7 R7 #1
STR R3 R7 # on empile n - 1
CALL fibo
LD R2 R7 # on dépile fibo(n-1)
SUB R7 R7 #1
LD R3 R7 # on dépile fibo(n-2)
ADD R2 R2 R3
STR R2 R7 # on empile fibo(n)
RET
fin:
LD R1 R7
stop:
JMP stop