8 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
e45028b65d update version to v1.9 2024-12-21 10:46:35 +01:00
e28ad4de5a better error catching 2024-12-17 21:34:19 +01:00
890f884cce update README 2024-12-14 18:03:54 +01:00
9dc7f61ed7 ret vaut 7 faut croire 2024-12-14 17:13:48 +01:00
5 changed files with 79 additions and 6 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
@@ -57,9 +57,11 @@ Produces
11011000 10100000 00000000 00000000
11100000 10100000 00000000 00001111
11101000 00000000 00000000 00001000
11110000 00000000 00000000 00000000
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

View File

@@ -28,7 +28,7 @@ enum TypeSautControle {
Jsup,
Jinf,
Call,
Ret,
Ret = 7,
};
static std::map<std::string, Instruction> INSTRUCTION_KEYS = {
@@ -205,8 +205,8 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
}
}
} catch (std::invalid_argument& e) {
throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + e.what());
} catch (std::exception& e) {
throw std::invalid_argument(" [Line " + std::to_string(a_RealLine) + "] " + e.what() + "\n" + a_Str);
}
return 0;

View File

@@ -3,7 +3,7 @@
#include "IO.h"
#define ASSEMBLEUR_VERSION "1.8"
#define ASSEMBLEUR_VERSION "1.9"
int main(int argc, char** argv) {