Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cf1a4d00af | |||
| 785fb7a8e7 | |||
| a4abd128f5 | |||
| e6b13abc15 | |||
| d5cd5a5849 | |||
| eb6cde02a7 |
34
README.md
34
README.md
@@ -16,14 +16,14 @@ There are 3 format types :
|
|||||||
|
|
||||||
```assembly
|
```assembly
|
||||||
operations:
|
operations:
|
||||||
add R1 R2 R3
|
add R1 R2 #1
|
||||||
sub R1 R2 #69
|
sub R1 R2 R3
|
||||||
and R0 R6 R3
|
and R1 R2 #33
|
||||||
xor R1 R2 R3
|
xor R1 R2 R3
|
||||||
or R1 R7 R3
|
or R1 R2 R3
|
||||||
sl R5 R2 #10
|
sl R1 R2 R3
|
||||||
sr R1 R2 R3
|
sr R1 R2 R3
|
||||||
mult R1 R1 R3
|
mul R1 R2 R3
|
||||||
io:
|
io:
|
||||||
str R1 R2 R3
|
str R1 R2 R3
|
||||||
ld R1 R2 R3
|
ld R1 R2 R3
|
||||||
@@ -41,9 +41,9 @@ controle:
|
|||||||
Produces
|
Produces
|
||||||
|
|
||||||
```
|
```
|
||||||
00000000 10100110 00000000 00000000
|
00000100 10100000 00000000 00000001
|
||||||
00010100 10100000 00000000 01000101
|
00010000 10100110 00000000 00000000
|
||||||
00100000 10100110 00000000 00000000
|
00100100 10100000 00000000 00100001
|
||||||
01000000 10100110 00000000 00000000
|
01000000 10100110 00000000 00000000
|
||||||
00110000 10100110 00000000 00000000
|
00110000 10100110 00000000 00000000
|
||||||
01010000 10100110 00000000 00000000
|
01010000 10100110 00000000 00000000
|
||||||
@@ -51,12 +51,12 @@ Produces
|
|||||||
01110000 10100110 00000000 00000000
|
01110000 10100110 00000000 00000000
|
||||||
01000001 01001100 00000000 00000000
|
01000001 01001100 00000000 00000000
|
||||||
01010001 01001100 00000000 00000000
|
01010001 01001100 00000000 00000000
|
||||||
11000000 00000000 00000000 00000101
|
11000000 00000000 00000000 00010000
|
||||||
11010001 01010000 00000000 00000011
|
11010001 01000000 00000000 00001001
|
||||||
11100001 01010000 00000000 00000010
|
11100001 01000000 00000000 00001011
|
||||||
11110001 01010000 00000000 00001101
|
11110001 01000000 00000000 00000001
|
||||||
11000001 01000000 00000000 00000001
|
11000001 01000000 00000000 00010000
|
||||||
11010100 00000000 00000000 00000111
|
11010000 00000000 00000000 00001001
|
||||||
11100000 00000000 00000000 00000000
|
11100000 00000000 00000000 00000000
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -71,5 +71,5 @@ xmake
|
|||||||
## Run
|
## Run
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
xmake run
|
xmake run Assembleur [args]
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ enum TypeArithmetique {
|
|||||||
Xor,
|
Xor,
|
||||||
Sl,
|
Sl,
|
||||||
Sr,
|
Sr,
|
||||||
Mult,
|
Mul,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum TypeMemoire {
|
enum TypeMemoire {
|
||||||
@@ -38,7 +38,7 @@ static std::map<std::string, Instruction> INSTRUCTION_KEYS = {
|
|||||||
{"xor", {Arithmetique, Xor}},
|
{"xor", {Arithmetique, Xor}},
|
||||||
{"sl", {Arithmetique, Sl}},
|
{"sl", {Arithmetique, Sl}},
|
||||||
{"sr", {Arithmetique, Sr}},
|
{"sr", {Arithmetique, Sr}},
|
||||||
{"mult", {Arithmetique, Mult}},
|
{"mul", {Arithmetique, Mul}},
|
||||||
{"str", {Memoire, Str}},
|
{"str", {Memoire, Str}},
|
||||||
{"ld", {Memoire, Ld}},
|
{"ld", {Memoire, Ld}},
|
||||||
{"jmp", {SautControle, Jump}},
|
{"jmp", {SautControle, Jump}},
|
||||||
@@ -79,17 +79,11 @@ std::uint32_t Assembleur::ParseOperationImmediate(
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction, const std::string& a_Label) {
|
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction, const std::string& a_Label) {
|
||||||
std::int32_t jump = ParseLabel(a_Label) - a_Instruction.m_Line;
|
return IToInt(a_Instruction) | ParseLabel(a_Label);
|
||||||
if (jump < 0)
|
|
||||||
jump = std::abs(jump) & 0x7FFFFFF | 0x4000000;
|
|
||||||
return IToInt(a_Instruction) | jump;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction, std::uint8_t a_R1, std::uint8_t a_R2, const std::string& a_Label) {
|
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction, std::uint8_t a_R1, std::uint8_t a_R2, const std::string& a_Label) {
|
||||||
std::int32_t jump = ParseLabel(a_Label) - a_Instruction.m_Line;
|
return IToInt(a_Instruction) | a_R1 << 24 | a_R2 << 21 | ParseLabel(a_Label);
|
||||||
if (jump < 0)
|
|
||||||
jump = std::abs(jump) & 0xFFFFF | 0x100000;
|
|
||||||
return IToInt(a_Instruction) | a_R1 << 24 | a_R2 << 21 | jump;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction) {
|
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction) {
|
||||||
@@ -134,7 +128,6 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
|
|||||||
}
|
}
|
||||||
|
|
||||||
Instruction instruction = it->second;
|
Instruction instruction = it->second;
|
||||||
instruction.m_Line = a_Line;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (instruction.m_Instruction) {
|
switch (instruction.m_Instruction) {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ enum TypeInstruction : std::uint8_t {
|
|||||||
struct Instruction {
|
struct Instruction {
|
||||||
TypeInstruction m_Instruction;
|
TypeInstruction m_Instruction;
|
||||||
std::uint8_t m_SubInstruction;
|
std::uint8_t m_SubInstruction;
|
||||||
std::uint32_t m_Line;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Assembleur {
|
class Assembleur {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "IO.h"
|
#include "IO.h"
|
||||||
|
|
||||||
#define ASSEMBLEUR_VERSION "1.1"
|
#define ASSEMBLEUR_VERSION "1.2"
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
|
|
||||||
|
|||||||
10
test.asm
10
test.asm
@@ -1,12 +1,12 @@
|
|||||||
operations:
|
operations:
|
||||||
add R1 R2 R3
|
add R1 R2 #1
|
||||||
sub R1 R2 #69
|
sub R1 R2 R3
|
||||||
and R1 R2 R3
|
and R1 R2 #33
|
||||||
xor R1 R2 R3
|
xor R1 R2 R3
|
||||||
or R1 R2 R3
|
or R1 R2 R3
|
||||||
sl R1 R2 R3
|
sl R1 R2 R3
|
||||||
sr R1 R2 R3
|
sr R1 R2 R3
|
||||||
mult R1 R2 R3
|
mul R1 R2 R3
|
||||||
io:
|
io:
|
||||||
str R1 R2 R3
|
str R1 R2 R3
|
||||||
ld R1 R2 R3
|
ld R1 R2 R3
|
||||||
@@ -18,4 +18,4 @@ sauts:
|
|||||||
jinf R1 R2 controle
|
jinf R1 R2 controle
|
||||||
controle:
|
controle:
|
||||||
call io
|
call io
|
||||||
ret
|
ret
|
||||||
|
|||||||
70
xmake.lua
70
xmake.lua
@@ -9,73 +9,3 @@ target("Assembleur")
|
|||||||
add_files("src/*.cpp")
|
add_files("src/*.cpp")
|
||||||
set_rundir(".")
|
set_rundir(".")
|
||||||
add_packages("argparse")
|
add_packages("argparse")
|
||||||
|
|
||||||
--
|
|
||||||
-- If you want to known more usage about xmake, please see https://xmake.io
|
|
||||||
--
|
|
||||||
-- ## FAQ
|
|
||||||
--
|
|
||||||
-- You can enter the project directory firstly before building project.
|
|
||||||
--
|
|
||||||
-- $ cd projectdir
|
|
||||||
--
|
|
||||||
-- 1. How to build project?
|
|
||||||
--
|
|
||||||
-- $ xmake
|
|
||||||
--
|
|
||||||
-- 2. How to configure project?
|
|
||||||
--
|
|
||||||
-- $ xmake f -p [macosx|linux|iphoneos ..] -a [x86_64|i386|arm64 ..] -m [debug|release]
|
|
||||||
--
|
|
||||||
-- 3. Where is the build output directory?
|
|
||||||
--
|
|
||||||
-- The default output directory is `./build` and you can configure the output directory.
|
|
||||||
--
|
|
||||||
-- $ xmake f -o outputdir
|
|
||||||
-- $ xmake
|
|
||||||
--
|
|
||||||
-- 4. How to run and debug target after building project?
|
|
||||||
--
|
|
||||||
-- $ xmake run [targetname]
|
|
||||||
-- $ xmake run -d [targetname]
|
|
||||||
--
|
|
||||||
-- 5. How to install target to the system directory or other output directory?
|
|
||||||
--
|
|
||||||
-- $ xmake install
|
|
||||||
-- $ xmake install -o installdir
|
|
||||||
--
|
|
||||||
-- 6. Add some frequently-used compilation flags in xmake.lua
|
|
||||||
--
|
|
||||||
-- @code
|
|
||||||
-- -- add debug and release modes
|
|
||||||
-- add_rules("mode.debug", "mode.release")
|
|
||||||
--
|
|
||||||
-- -- add macro definition
|
|
||||||
-- add_defines("NDEBUG", "_GNU_SOURCE=1")
|
|
||||||
--
|
|
||||||
-- -- set warning all as error
|
|
||||||
-- set_warnings("all", "error")
|
|
||||||
--
|
|
||||||
-- -- set language: c99, c++11
|
|
||||||
-- set_languages("c99", "c++11")
|
|
||||||
--
|
|
||||||
-- -- set optimization: none, faster, fastest, smallest
|
|
||||||
-- set_optimize("fastest")
|
|
||||||
--
|
|
||||||
-- -- add include search directories
|
|
||||||
-- add_includedirs("/usr/include", "/usr/local/include")
|
|
||||||
--
|
|
||||||
-- -- add link libraries and search directories
|
|
||||||
-- add_links("tbox")
|
|
||||||
-- add_linkdirs("/usr/local/lib", "/usr/lib")
|
|
||||||
--
|
|
||||||
-- -- add system link libraries
|
|
||||||
-- add_syslinks("z", "pthread")
|
|
||||||
--
|
|
||||||
-- -- add compilation and link flags
|
|
||||||
-- add_cxflags("-stdnolib", "-fno-strict-aliasing")
|
|
||||||
-- add_ldflags("-L/usr/local/lib", "-lpthread", {force = true})
|
|
||||||
--
|
|
||||||
-- @endcode
|
|
||||||
--
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user