diff --git a/as/k-as.py b/as/k-as.py index 642da44..92b32e2 100755 --- a/as/k-as.py +++ b/as/k-as.py @@ -283,7 +283,9 @@ def parse_instr(line): word = word[1:-1] if pref == None: - pref = "%q" + print("Missing access length modifier: {}".format(line)) + leave() + sys.exit(1) instr_name += "_m" instr_args += "{}".format(pref) diff --git a/as/testfile.asm b/as/testfile.asm index 187f3af..9f5de3b 100644 --- a/as/testfile.asm +++ b/as/testfile.asm @@ -3,33 +3,63 @@ hw = 'Hello World' +; +; Entry point +; main: ; This comment is successfully ignored mov rbp, 0x200000 mov rsp, rbp mov ax0, hw - mov ax1, hw_len call print + + mov ax0, hw + mov ax1, hw_len + call print_n stop +; +; Max amount of characters that print() will print +; +v_print_max := 0xFF + +; +; void print(char *) +; +; Print a string +; print: enter + mov rcx, v_print_max +.p1: + test b[ax0], b[ax0] + jz .p2 + prn b[ax0] + inc ax0 + loop .p1 + +.p2: + leave + ret + + +; +; void print_n(char *, int) +; +; Print exactly ax1 characters +; +print_n: + enter mov rcx, ax1 - rep call .pch1 + +.pn1: + prn b[ax0] + inc ax0 + loop .pn1 leave ret -.pch1: - test b[ax0], b[ax0] - jnz .pch2 - ret - -.pch2: - prn b[ax0] - inc ax0 - ret - diff --git a/pc/decd.c b/pc/decd.c index c7e1061..5641c8c 100644 --- a/pc/decd.c +++ b/pc/decd.c @@ -117,14 +117,17 @@ void disasm(ctx_t *ctx) } } +#ifdef _NEED_DISASM dumpinstr(ctx, rip, rep, c, &p1, &p2); +#else -#ifndef _NEED_DISASM - do_rep: i->func(ctx, &p1, &p2); + dumpinstr(ctx, rip, rep, c, &p1, &p2); + if (rep && ctx->r[RCX].val > 0) { + log("rcx::%lu\n", ctx->r[RCX].val); ctx->r[RCX].val--; goto do_rep; } diff --git a/pc/instrs/INSTRS b/pc/instrs/INSTRS index bc5a4f7..abe9a4b 100644 --- a/pc/instrs/INSTRS +++ b/pc/instrs/INSTRS @@ -115,6 +115,9 @@ test m m jmp r jmp i +loop r +loop i + jz r jz i jnz r diff --git a/pc/instrs/jumps.c b/pc/instrs/jumps.c index 1ca7b63..049c3ea 100644 --- a/pc/instrs/jumps.c +++ b/pc/instrs/jumps.c @@ -10,7 +10,16 @@ IMPL_START_1(jmp) { - ctx->r[RIP].val = v1; + JUMP(v1); +} +IMPL_END; + +IMPL_START_1(loop) +{ + if (ctx->r[RCX].val > 0) { + ctx->r[RCX].val--; + JUMP(v1); + } } IMPL_END;