14 Commits
v1.1 ... v1.5

Author SHA1 Message Date
9c8d79bf67 update to v1.5 2024-12-06 17:11:46 +01:00
95701058f1 fix Windows linking 2024-12-06 17:11:27 +01:00
c7f52d9ce8 update to v1.4 2024-12-06 17:06:04 +01:00
4bc49bb200 upper case test.asm 2024-12-06 17:03:21 +01:00
bd07de84f9 update README 2024-12-06 17:03:07 +01:00
fb4883b840 add unused byte for easier reading in cpu 2024-12-06 16:35:10 +01:00
0dd3e6d83f update to 1.3 2024-12-05 16:37:15 +01:00
35501025ff don't be case sensitive for instructions 2024-12-05 16:34:20 +01:00
cf1a4d00af update to 1.2 2024-12-05 16:23:20 +01:00
785fb7a8e7 update run instruction 2024-12-05 16:22:12 +01:00
a4abd128f5 update example 2024-12-05 16:20:17 +01:00
e6b13abc15 change mult to mul 2024-12-05 16:18:39 +01:00
d5cd5a5849 xmake: remove tutorial 2024-12-05 16:06:33 +01:00
eb6cde02a7 absolute jump 2024-11-26 17:14:22 +01:00
6 changed files with 80 additions and 130 deletions

View File

@@ -16,53 +16,58 @@ There are 3 format types :
```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
mult R1 R1 R3
ADD R1 R2 #1
SUB R1 R2 R3
AND R1 R2 #33
XOR R1 R2 R3
OR R1 R2 R3
SL R1 R2 R3
SR R1 R2 R3
MUL R1 R2 R3
io:
str R1 R2 R3
ld R1 R2 R3
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
JMP controle
JEQU R1 R2 io
JNEQ R1 R2 sauts
JSUP R1 R2 operations
JINF R1 R2 controle
controle:
call io
ret
CALL io
RET
```
Produces
```
00000000 10100110 00000000 00000000
00010100 10100000 00000000 01000101
00100000 10100110 00000000 00000000
00000100 10100000 00000000 00000001
00010000 10100110 00000000 00000000
00100100 10100000 00000000 00100001
01000000 10100110 00000000 00000000
00110000 10100110 00000000 00000000
01010000 10100110 00000000 00000000
01100000 10100110 00000000 00000000
01110000 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 00001101
11000001 01000000 00000000 00000001
11010100 00000000 00000000 00000111
01000000 10100110 00000000 00000000
01010000 10100110 00000000 00000000
11000000 00000000 00000000 00010000
11010000 10100000 00000000 00001001
11100000 10100000 00000000 00001011
11110000 10100000 00000000 00000001
11000000 10100000 00000000 00010000
11010000 00000000 00000000 00001001
11100000 00000000 00000000 00000000
```
## Releases
Pre-compiled binaries are available in the [Release](https://git.ale-pri.com/Persson-dev/Assembleur/releases) section.
## Build
You should have [xmake](https://xmake.io) installed
If you wish to compile yourself, you must have [xmake](https://xmake.io) installed.
Instructions on how to install (and you should) [here](https://xmake.io/#/guide/installation)
```bash
xmake
@@ -71,5 +76,20 @@ xmake
## Run
```bash
xmake run
xmake run Assembleur [args]
```
Example :
```bash
xmake run Assembleur test.asm -o memory
```
Parses the file `test.asm` and writes the output into the file `memory`
## Install
You can also add the binary to your path using
```bash
xmake install
```

View File

@@ -1,5 +1,6 @@
#include "Assembleur.h"
#include <algorithm>
#include <map>
#include <sstream>
#include <stdexcept>
@@ -12,7 +13,7 @@ enum TypeArithmetique {
Xor,
Sl,
Sr,
Mult,
Mul,
};
enum TypeMemoire {
@@ -38,7 +39,7 @@ static std::map<std::string, Instruction> INSTRUCTION_KEYS = {
{"xor", {Arithmetique, Xor}},
{"sl", {Arithmetique, Sl}},
{"sr", {Arithmetique, Sr}},
{"mult", {Arithmetique, Mult}},
{"mul", {Arithmetique, Mul}},
{"str", {Memoire, Str}},
{"ld", {Memoire, Ld}},
{"jmp", {SautControle, Jump}},
@@ -79,17 +80,11 @@ std::uint32_t Assembleur::ParseOperationImmediate(
}
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction, const std::string& a_Label) {
std::int32_t jump = ParseLabel(a_Label) - a_Instruction.m_Line;
if (jump < 0)
jump = std::abs(jump) & 0x7FFFFFF | 0x4000000;
return IToInt(a_Instruction) | jump;
return IToInt(a_Instruction) | ParseLabel(a_Label) & 0x3FFFFFF;
}
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;
if (jump < 0)
jump = std::abs(jump) & 0xFFFFF | 0x100000;
return IToInt(a_Instruction) | a_R1 << 24 | a_R2 << 21 | jump;
return IToInt(a_Instruction) | a_R1 << 23 | a_R2 << 20 | ParseLabel(a_Label) & 0xFFFFF;
}
std::uint32_t Assembleur::ParseJump(Instruction a_Instruction) {
@@ -97,7 +92,7 @@ std::uint32_t Assembleur::ParseJump(Instruction a_Instruction) {
}
std::uint32_t Assembleur::ParseIO(Instruction a_Instruction, std::uint32_t a_R1, std::uint32_t a_R2, std::uint32_t a_R3) {
return IToInt(a_Instruction) | a_R1 << 24 | a_R2 << 21 | a_R3 << 18;
return IToInt(a_Instruction) | a_R1 << 23 | a_R2 << 20 | a_R3 << 17;
}
@@ -128,13 +123,15 @@ std::uint32_t Assembleur::ParseInstruction(const std::string& a_Str, std::uint32
std::string ins;
ss >> ins;
// to lower case
std::transform(ins.begin(), ins.end(), ins.begin(), [](unsigned char c) { return std::tolower(c); });
auto it = INSTRUCTION_KEYS.find(ins);
if (it == INSTRUCTION_KEYS.end()) {
throw std::invalid_argument("[Line " + std::to_string(a_RealLine) + "] " + "Instruction \"" + ins + "\" not found !");
}
Instruction instruction = it->second;
instruction.m_Line = a_Line;
try {
switch (instruction.m_Instruction) {

View File

@@ -13,7 +13,6 @@ enum TypeInstruction : std::uint8_t {
struct Instruction {
TypeInstruction m_Instruction;
std::uint8_t m_SubInstruction;
std::uint32_t m_Line;
};
class Assembleur {

View File

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

View File

@@ -1,21 +1,21 @@
operations:
add R1 R2 R3
sub R1 R2 #69
and R1 R2 R3
xor R1 R2 R3
or R1 R2 R3
sl R1 R2 R3
sr R1 R2 R3
mult R1 R2 R3
ADD R1 R2 #1
SUB R1 R2 R3
AND R1 R2 #33
XOR R1 R2 R3
OR R1 R2 R3
SL R1 R2 R3
SR R1 R2 R3
MUL R1 R2 R3
io:
str R1 R2 R3
ld R1 R2 R3
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
JMP controle
JEQU R1 R2 io
JNEQ R1 R2 sauts
JSUP R1 R2 operations
JINF R1 R2 controle
controle:
call io
ret
CALL io
RET

View File

@@ -10,72 +10,6 @@ target("Assembleur")
set_rundir(".")
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
--
if is_os("windows") then
add_ldflags("-static", "-static-libstdc++")
end