summaryrefslogtreecommitdiff
path: root/nqdasm.c
diff options
context:
space:
mode:
Diffstat (limited to 'nqdasm.c')
-rw-r--r--nqdasm.c37
1 files changed, 21 insertions, 16 deletions
diff --git a/nqdasm.c b/nqdasm.c
index 0ecc5b1..3245570 100644
--- a/nqdasm.c
+++ b/nqdasm.c
@@ -39,6 +39,26 @@ static void print_operand(FILE *out, unsigned bits, const struct operand *op)
}
}
+static void disassemble(FILE *in, FILE *out)
+{
+ unsigned bits;
+ while (fscanf(in, " %x\n", &bits) > 0) {
+ const struct mnemonic *m = match_instruction(bits);
+ if (!m) {
+ fprintf(out, "\t.word 0x%04x\n", bits);
+ continue;
+ }
+
+ fprintf(out, "\t%s", m->mnem);
+ for (int i = 0; i < 3 && m->operands[i].type; i++) {
+ if (i) fprintf(out, ", ");
+ else fprintf(out, "%*s", 8 - (int)strlen(m->mnem), "");
+ print_operand(out, bits, m->operands + i);
+ }
+ fprintf(out, "\n");
+ }
+}
+
static void usage(const char *progname)
{
printf("usage: %s [-o output] [input]\n", progname);
@@ -88,22 +108,7 @@ int main(int argc, char **argv)
return 1;
}
- unsigned bits;
- while (fscanf(in, " %x\n", &bits) > 0) {
- const struct mnemonic *m = match_instruction(bits);
- if (!m) {
- fprintf(out, "\t.word 0x%04x\n", bits);
- continue;
- }
-
- fprintf(out, "\t%s", m->mnem);
- for (int i = 0; i < 3 && m->operands[i].type; i++) {
- if (i) fprintf(out, ", ");
- else fprintf(out, "%*s", 8 - (int)strlen(m->mnem), "");
- print_operand(out, bits, m->operands + i);
- }
- fprintf(out, "\n");
- }
+ disassemble(in, out);
fclose(in);
fclose(out);