summaryrefslogtreecommitdiff
path: root/nqasm.c
diff options
context:
space:
mode:
authorBobby Bingham <koorogi@koorogi.info>2017-01-14 14:44:18 -0600
committerBobby Bingham <koorogi@koorogi.info>2017-01-15 23:19:04 -0600
commit50e67fb3e640a9e6e1260ca984582c9a9b8d5375 (patch)
treed4d12ed5a5787e30e1062ced1edc6c7979afe77e /nqasm.c
parenta743db94541bebafff23c8a490dbce3f55d69712 (diff)
nqasm: Handle register and register indirect arguments
Diffstat (limited to 'nqasm.c')
-rw-r--r--nqasm.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/nqasm.c b/nqasm.c
index a42f8f4..ed49a48 100644
--- a/nqasm.c
+++ b/nqasm.c
@@ -1,3 +1,4 @@
+#include <stdint.h>
#include <stdio.h>
#include "mnemonics.h"
@@ -6,10 +7,18 @@
#include "lexer.h"
#include "parser.h"
-void add_instruction(const struct instruction *i)
+void add_instruction(const struct instruction *inst)
{
- const struct mnemonic *m = &mnemonics[i->mnem];
- printf("%04x\n", m->bits);
+ const struct mnemonic *mnem = &mnemonics[inst->mnem];
+ uint16_t bits = mnem->bits;
+
+ const struct operand *ops = mnem->operands;
+ const struct argument *args = inst->args.args;
+ for (int i = 0; i < 3 && ops[i].type; i++) {
+ bits |= args[i].value << ops[i].shift;
+ }
+
+ printf("%04x\n", bits);
}
int main(int argc, char **argv)