diff options
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) |