This commit is contained in:
julianb0 2019-05-29 18:26:28 +02:00
parent 29ef2b35b5
commit f6012cee97
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
5 changed files with 63 additions and 16 deletions

View File

@ -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)

View File

@ -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

View File

@ -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;
}

View File

@ -115,6 +115,9 @@ test m m
jmp r
jmp i
loop r
loop i
jz r
jz i
jnz r

View File

@ -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;