diff --git a/as/k-as.py b/as/k-as.py index b286956..df844f4 100755 --- a/as/k-as.py +++ b/as/k-as.py @@ -323,7 +323,6 @@ pconds = { } def get_cond_mask(cond, line): - mask = 0 if cond[0] == 'n': @@ -393,6 +392,13 @@ def parse_instr(line): # Word 2 (rep|cond|ft1|ft2) w2 = 0 + if '.' in instr: + w2 |= get_cond_mask(instr.split('.', 1)[1], line) + instr = instr.split('.', 1)[0] + + else: + instr = instr + if instr == "rep": if params == None: print("Missing instruction after rep prefix: {}".format(line)) @@ -400,15 +406,14 @@ def parse_instr(line): sys.exit(1) w2 |= 0x8000 # 16th bit - instr, params = params.split(' ', 1) - - if '.' in instr: - w2 |= get_cond_mask(instr.split('.', 1)[1], line) - instr_name = instr.split('.', 1)[0] - else: - instr_name = instr + if len(params.split(' ', 1)) == 2: + instr, params = params.split(' ', 1) + else: + instr = params.split(' ', 1)[0] + params = None + instr_name = instr instr_args = '' if params == None or len(params) == 0: diff --git a/ka/dos.k b/ka/dos.k index 372b477..2672518 100644 --- a/ka/dos.k +++ b/ka/dos.k @@ -15,6 +15,12 @@ _start: stop jmp .1 +; +; Essential definitions +; +CHAR_MAX := 0x7F +INT_MAX := 0x7FFF + ; ; Include librairies ; diff --git a/ka/main.k b/ka/main.k index 2e70a9f..120d35c 100644 --- a/ka/main.k +++ b/ka/main.k @@ -5,6 +5,26 @@ ; Main function ; main: + cld + mov rcx, 11 + mov rax, 33 + mov rdi, .buf + mov rsi, .buf + rep stosb + + mov rbx, rdi + sub rbx, rsi + + mov ax0, .buf + mov ax1, 12 + call print_n + + ret + +.str1 = "Hello World!\n" +.buf = [32] + +movzx_test: enter 1 mov q[rsp], 0xFABC1234CCCCDDDD diff --git a/vm/TODO b/vm/TODO deleted file mode 100644 index cdb7efb..0000000 --- a/vm/TODO +++ /dev/null @@ -1,9 +0,0 @@ -TODO - -sal, sar -imul, idiv - -Flags for shl, shr, mul, div - -Useful: https://www.felixcloutier.com/x86 - diff --git a/vm/in/string.c b/vm/in/string.c index 06fce6a..363105f 100644 --- a/vm/in/string.c +++ b/vm/in/string.c @@ -31,7 +31,7 @@ void stos_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len) else { reg = RDI; - val = R(rax); + val = rax; } writemem(ctx, val, R(reg), len); @@ -45,6 +45,24 @@ IMPL_START_0(stosb) } IMPL_END; +IMPL_START_0(stosw) +{ + stos_impl(ctx, p1, p2, 2); +} +IMPL_END; + +IMPL_START_0(stosl) +{ + stos_impl(ctx, p1, p2, 4); +} +IMPL_END; + +IMPL_START_0(stosq) +{ + stos_impl(ctx, p1, p2, 8); +} +IMPL_END; + //----------------------------------------------------------------------------// void lods_impl(ctx_t *ctx, acc_t *p1, acc_t *p2, uint len) @@ -75,6 +93,24 @@ IMPL_START_0(lodsb) } IMPL_END; +IMPL_START_0(lodsw) +{ + lods_impl(ctx, p1, p2, 2); +} +IMPL_END; + +IMPL_START_0(lodsl) +{ + lods_impl(ctx, p1, p2, 4); +} +IMPL_END; + +IMPL_START_0(lodsq) +{ + lods_impl(ctx, p1, p2, 8); +} +IMPL_END; + //----------------------------------------------------------------------------// IMPL_START_0(scasb) diff --git a/vm/pc/decd.c b/vm/pc/decd.c index 4bb48cb..c918693 100644 --- a/vm/pc/decd.c +++ b/vm/pc/decd.c @@ -345,16 +345,21 @@ do_rep: } } - if (rep && rcx > 0) + if (rep) { // RCX remains untouched when condition fails if (!eval_cond(ctx, cond)) return; + if (rcx > 0) + rcx--; + + if (rcx == 0) + return; + // Show that we're REP'ing dump_instr(ctx, in, p1, p2, lock, rep, cond, pc); - rcx--; goto do_rep; } }