Compare commits
3 Commits
v1.0
...
6fcc51f2ca
| Author | SHA1 | Date | |
|---|---|---|---|
| 6fcc51f2ca | |||
| 777adffdea | |||
| 7c72155fea |
72
README.md
Normal file
72
README.md
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
# Assembleur
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
```bash
|
||||||
|
./Assembleur [--help] [--version] [--output file] [--format type] file
|
||||||
|
```
|
||||||
|
|
||||||
|
There are 3 format types :
|
||||||
|
- "int" : 32 bits integers are written. Exemple : `10878976`
|
||||||
|
- "binint" (default) : bits are written. Exemple : `00000000 10100110 00000000 00000000`
|
||||||
|
- "bin" : the file is written in pure binary
|
||||||
|
|
||||||
|
## Exemple
|
||||||
|
|
||||||
|
```assembly
|
||||||
|
operations:
|
||||||
|
add R1 R2 R3
|
||||||
|
sub R1 R2 #69
|
||||||
|
and R0 R6 R3
|
||||||
|
xor R1 R2 R3
|
||||||
|
or R1 R7 R3
|
||||||
|
sl R5 R2 #10
|
||||||
|
sr R1 R2 R3
|
||||||
|
io:
|
||||||
|
str R1 R2 R3
|
||||||
|
ld R1 R2 R3
|
||||||
|
sauts:
|
||||||
|
jmp controle
|
||||||
|
jequ R1 R2 io
|
||||||
|
jneq R1 R2 sauts
|
||||||
|
jsup R1 R2 operations
|
||||||
|
jinf R1 R2 controle
|
||||||
|
controle:
|
||||||
|
call io
|
||||||
|
ret
|
||||||
|
```
|
||||||
|
|
||||||
|
Produces
|
||||||
|
|
||||||
|
```
|
||||||
|
00000000 10100110 00000000 00000000
|
||||||
|
00010100 10100000 00000000 01000101
|
||||||
|
00100000 10100110 00000000 00000000
|
||||||
|
01000000 10100110 00000000 00000000
|
||||||
|
00110000 10100110 00000000 00000000
|
||||||
|
01010000 10100110 00000000 00000000
|
||||||
|
01100000 10100110 00000000 00000000
|
||||||
|
01000001 01001100 00000000 00000000
|
||||||
|
01010001 01001100 00000000 00000000
|
||||||
|
11000000 00000000 00000000 00000101
|
||||||
|
11010001 01010000 00000000 00000011
|
||||||
|
11100001 01010000 00000000 00000010
|
||||||
|
11110001 01010000 00000000 00001100
|
||||||
|
11000001 01000000 00000000 00000001
|
||||||
|
11010100 00000000 00000000 00000111
|
||||||
|
11100000 00000000 00000000 00000000
|
||||||
|
```
|
||||||
|
|
||||||
|
## Build
|
||||||
|
|
||||||
|
You should have [xmake](https://xmake.io) installed
|
||||||
|
|
||||||
|
```bash
|
||||||
|
xmake
|
||||||
|
```
|
||||||
|
|
||||||
|
## Run
|
||||||
|
|
||||||
|
```bash
|
||||||
|
xmake run
|
||||||
|
```
|
||||||
@@ -53,7 +53,7 @@ std::uint32_t Assembleur::ParseLabel(const std::string& a_Label) {
|
|||||||
auto it = m_Labels.find(a_Label);
|
auto it = m_Labels.find(a_Label);
|
||||||
|
|
||||||
if (it == m_Labels.end()) {
|
if (it == m_Labels.end()) {
|
||||||
throw std::runtime_error("Label " + a_Label + " not found !");
|
throw std::invalid_argument("Label " + a_Label + " not found !");
|
||||||
}
|
}
|
||||||
|
|
||||||
return it->second;
|
return it->second;
|
||||||
@@ -105,8 +105,11 @@ std::uint32_t Assembleur::ParseIO(Instruction a_Instruction, std::uint32_t a_R1,
|
|||||||
|
|
||||||
static std::uint32_t ParseRegistry(const std::string& a_Str) {
|
static std::uint32_t ParseRegistry(const std::string& a_Str) {
|
||||||
if (a_Str.at(0) != 'R')
|
if (a_Str.at(0) != 'R')
|
||||||
throw std::runtime_error("Registry " + a_Str + " not found !");
|
throw std::invalid_argument("Registry " + a_Str + " not found !");
|
||||||
return std::stoi(a_Str.substr(1));
|
std::uint32_t registry = std::stoi(a_Str.substr(1));
|
||||||
|
if (registry > 7)
|
||||||
|
throw std::invalid_argument("You can only have up to 8 registries !");
|
||||||
|
return registry;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool IsConstant(const std::string& a_Str) {
|
static bool IsConstant(const std::string& a_Str) {
|
||||||
@@ -115,7 +118,7 @@ static bool IsConstant(const std::string& a_Str) {
|
|||||||
|
|
||||||
static std::uint32_t ParseConstant(const std::string& a_Str) {
|
static std::uint32_t ParseConstant(const std::string& a_Str) {
|
||||||
if (a_Str.at(0) != '#')
|
if (a_Str.at(0) != '#')
|
||||||
throw std::runtime_error("Registry " + a_Str + " not found !");
|
throw std::invalid_argument("Registry " + a_Str + " not found !");
|
||||||
return std::stoi(a_Str.substr(1));
|
return std::stoi(a_Str.substr(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +129,7 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
|
|||||||
|
|
||||||
auto it = INSTRUCTION_KEYS.find(ins);
|
auto it = INSTRUCTION_KEYS.find(ins);
|
||||||
if (it == INSTRUCTION_KEYS.end()) {
|
if (it == INSTRUCTION_KEYS.end()) {
|
||||||
throw std::runtime_error("[Line " + std::to_string(a_RealLine) + "] " + "Instruction \"" + ins + "\" not found !");
|
throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + "Instruction \"" + ins + "\" not found !");
|
||||||
}
|
}
|
||||||
|
|
||||||
Instruction instruction = it->second;
|
Instruction instruction = it->second;
|
||||||
@@ -174,8 +177,8 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (std::runtime_error& e) {
|
} catch (std::invalid_argument& e) {
|
||||||
throw std::runtime_error("[Line " + std::to_string(a_RealLine) + "] " + e.what());
|
throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user