From 50e67fb3e640a9e6e1260ca984582c9a9b8d5375 Mon Sep 17 00:00:00 2001 From: Bobby Bingham Date: Sat, 14 Jan 2017 14:44:18 -0600 Subject: nqasm: Handle register and register indirect arguments --- nqasm.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'nqasm.c') diff --git a/nqasm.c b/nqasm.c index a42f8f4..ed49a48 100644 --- a/nqasm.c +++ b/nqasm.c @@ -1,3 +1,4 @@ +#include #include #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) -- cgit v1.2.3