Compare commits
8 Commits
v1.8
...
f737d1e695
| Author | SHA1 | Date | |
|---|---|---|---|
| f737d1e695 | |||
| 02b2ed46c7 | |||
| e4aac05b9a | |||
| ddb9853ac4 | |||
| e45028b65d | |||
| e28ad4de5a | |||
| 890f884cce | |||
| 9dc7f61ed7 |
10
README.md
10
README.md
@@ -10,7 +10,7 @@ There are 3 format types :
|
|||||||
- "int" : 32 bits integers are written. Exemple : `10878976`
|
- "int" : 32 bits integers are written. Exemple : `10878976`
|
||||||
- "binint" : bits are written. Exemple : `00000000 10100110 00000000 00000000`
|
- "binint" : bits are written. Exemple : `00000000 10100110 00000000 00000000`
|
||||||
- "bin" : the file is written in pure binary
|
- "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
|
## Exemple
|
||||||
|
|
||||||
@@ -57,9 +57,11 @@ Produces
|
|||||||
11011000 10100000 00000000 00000000
|
11011000 10100000 00000000 00000000
|
||||||
11100000 10100000 00000000 00001111
|
11100000 10100000 00000000 00001111
|
||||||
11101000 00000000 00000000 00001000
|
11101000 00000000 00000000 00001000
|
||||||
11110000 00000000 00000000 00000000
|
11111000 00000000 00000000 00000000
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Other examples are located in the `examples` folder
|
||||||
|
|
||||||
## Releases
|
## Releases
|
||||||
|
|
||||||
Pre-compiled binaries are available in the [Release](https://git.ale-pri.com/Persson-dev/Assembleur/releases) section.
|
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
|
You can also add the binary to your path using
|
||||||
```bash
|
```bash
|
||||||
xmake install
|
xmake install
|
||||||
|
```
|
||||||
|
or copy the binary in the `bin` folder after
|
||||||
|
```
|
||||||
|
xmake install -o .
|
||||||
```
|
```
|
||||||
30
examples/facto.asm
Normal file
30
examples/facto.asm
Normal 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
37
examples/fibo.asm
Normal 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
|
||||||
@@ -28,7 +28,7 @@ enum TypeSautControle {
|
|||||||
Jsup,
|
Jsup,
|
||||||
Jinf,
|
Jinf,
|
||||||
Call,
|
Call,
|
||||||
Ret,
|
Ret = 7,
|
||||||
};
|
};
|
||||||
|
|
||||||
static std::map<std::string, Instruction> INSTRUCTION_KEYS = {
|
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) {
|
} catch (std::exception& e) {
|
||||||
throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + e.what());
|
throw std::invalid_argument(" [Line " + std::to_string(a_RealLine) + "] " + e.what() + "\n" + a_Str);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "IO.h"
|
#include "IO.h"
|
||||||
|
|
||||||
#define ASSEMBLEUR_VERSION "1.8"
|
#define ASSEMBLEUR_VERSION "1.9"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user