diff options
author | Bobby Bingham <koorogi@koorogi.info> | 2017-01-14 14:44:18 -0600 |
---|---|---|
committer | Bobby Bingham <koorogi@koorogi.info> | 2017-01-15 23:19:04 -0600 |
commit | 50e67fb3e640a9e6e1260ca984582c9a9b8d5375 (patch) | |
tree | d4d12ed5a5787e30e1062ced1edc6c7979afe77e /nqasm.c | |
parent | a743db94541bebafff23c8a490dbce3f55d69712 (diff) |
nqasm: Handle register and register indirect arguments
Diffstat (limited to 'nqasm.c')
-rw-r--r-- | nqasm.c | 15 |
1 files changed, 12 insertions, 3 deletions
@@ -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) |