diff options
author | Benedikt Böhm <bb@xnull.de> | 2009-07-04 10:49:19 +0200 |
---|---|---|
committer | Benedikt Böhm <bb@xnull.de> | 2009-07-04 10:49:19 +0200 |
commit | 6165e2dde32a8f425e54d4f061146b366d5a2e0a (patch) | |
tree | 857b1884e30c5b38ac8c915e37b8ee0bd52d712e /src/emu/asm.c | |
parent | 11545b9e323084482673b8732b89711ae7e19928 (diff) | |
download | swppy-6165e2dde32a8f425e54d4f061146b366d5a2e0a.tar.gz swppy-6165e2dde32a8f425e54d4f061146b366d5a2e0a.tar.xz swppy-6165e2dde32a8f425e54d4f061146b366d5a2e0a.zip |
adapt emulator for generator changes:
- new instructions (push, pop, call, ret)
- new pseudo-registers (bp, sp, rv)
- new binary format
- dynamic register file size
- removed obsolete instructions
Diffstat (limited to '')
-rw-r--r-- | src/emu/asm.c | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/src/emu/asm.c b/src/emu/asm.c index caca72a..8e39202 100644 --- a/src/emu/asm.c +++ b/src/emu/asm.c @@ -5,28 +5,49 @@ #include "log.h" #include "opc.h" +#define REGa(x) (((x) & 0x1F) << 21) +#define REGb(x) (((x) & 0x1F) << 16) +#define REGc(x) (((x) & 0x1F) << 11) +#define IMMc(x) ((x) & 0xFFFF) + uint32_t compile(const char *line) { - char mnem[4]; + char mnem[5]; int32_t a = 0, b = 0, c = 0; + static size_t regs = 0; + + /* register file size */ + if (sscanf(line, ".REGS %d", &a) == 1) { + regs = a; + return a; + } + + /* ADD, SUB, MUL, DIV, MOD, AND, OR */ + if (sscanf(line, "%s r%d, r%d, r%d", mnem, &a, &b, &c) == 4) + return mnemonic2opc(mnem) | REGa(a) | REGb(b) | REGc(c); + + /* LW, SW */ + if (sscanf(line, "%s r%d, r%d, %d", mnem, &a, &b, &c) == 4) + return mnemonic2opc(mnem) | REGa(a) | REGb(b) | IMMc(c); - /* arithmetic & logic */ - if (sscanf(line, "%3s r%2d, r%2d, r%2d", mnem, &a, &b, &c) == 4) - return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | ((c & 0x1F) << 11); + /* CMP */ + if (sscanf(line, "%s r%d, r%d", mnem, &a, &b) == 3) + return mnemonic2opc(mnem) | REGa(a) | REGb(b); - /* load/store & branch */ - if (sscanf(line, "%3s r%2d, r%2d, %d", mnem, &a, &b, &c) == 4) - return mnemonic2opc(mnem) | ((a & 0x1F) << 21) | ((b & 0x1F) << 16) | (c & 0xFFFF); + /* MOV, BEZ */ + if (sscanf(line, "%s r%2d, %d", mnem, &a, &c) == 3) + return mnemonic2opc(mnem) | REGa(a) | IMMc(c); - if (sscanf(line, "%3s r%2d, %d", mnem, &b, &c) == 3) - return mnemonic2opc(mnem) | ((b & 0x1F) << 16) | (c & 0xFFFF); + /* EQ, NE, LT, LE, GE, GT, PUSH, POP */ + if (sscanf(line, "%s r%d", mnem, &a) == 2) + return mnemonic2opc(mnem) | REGa(a); - /* jump */ - if (sscanf(line, "%3s r%2d", mnem, &a) == 2) - return mnemonic2opc(mnem) | ((a & 0x1F) << 21); + /* JMP, CALL */ + if (sscanf(line, "%s %d", mnem, &c) == 2) + return mnemonic2opc(mnem) | IMMc(c); - /* misc */ - if (sscanf(line, "%3s", mnem) == 1) + /* RET, SYS */ + if (sscanf(line, "%s", mnem) == 1) return mnemonic2opc(mnem); return 0xFFFFFFFF; |