From 49f510d2d60129526832bfcd9c0f4049962bc80e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benedikt=20B=C3=B6hm?= Date: Mon, 18 May 2009 20:53:42 +0200 Subject: move stuff around and create initial source structure --- src/emu/asm.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 src/emu/asm.c (limited to 'src/emu/asm.c') diff --git a/src/emu/asm.c b/src/emu/asm.c new file mode 100644 index 0000000..caca72a --- /dev/null +++ b/src/emu/asm.c @@ -0,0 +1,33 @@ +#include +#include + +#include "cpu.h" +#include "log.h" +#include "opc.h" + +uint32_t compile(const char *line) +{ + char mnem[4]; + int32_t a = 0, b = 0, c = 0; + + /* 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); + + /* 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); + + if (sscanf(line, "%3s r%2d, %d", mnem, &b, &c) == 3) + return mnemonic2opc(mnem) | ((b & 0x1F) << 16) | (c & 0xFFFF); + + /* jump */ + if (sscanf(line, "%3s r%2d", mnem, &a) == 2) + return mnemonic2opc(mnem) | ((a & 0x1F) << 21); + + /* misc */ + if (sscanf(line, "%3s", mnem) == 1) + return mnemonic2opc(mnem); + + return 0xFFFFFFFF; +} -- cgit v1.2.3