summaryrefslogtreecommitdiff
path: root/nqasm.c
diff options
context:
space:
mode:
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)