This commit is contained in:
julianb0 2019-05-30 21:46:00 +02:00
parent c986ec2b22
commit ea6ec1f01e
No known key found for this signature in database
GPG Key ID: DDF8325C95299A62
8 changed files with 64 additions and 28 deletions

View File

@ -20,7 +20,7 @@ test: kas out/a.out
@out/k.exe out/a.out > out/stdout.txt @out/k.exe out/a.out > out/stdout.txt
@echo "output:" @echo "output:"
@echo ">>>>>>>>" @echo ">>>>>>>>"
@cat out/stdout.txt @cat -v out/stdout.txt
@echo @echo
@echo "<<<<<<<<" @echo "<<<<<<<<"
@echo @echo

View File

@ -156,11 +156,20 @@ def parse():
if len(line) == 0: if len(line) == 0:
continue continue
quote = False
for i in range(len(line)): for i in range(len(line)):
if line[i] in '#;@!/': if line[i] in "'\"":
quote = not quote
if line[i] in '#;@!/' and not quote:
line = line[:i].rstrip() line = line[:i].rstrip()
break break
if quote:
print("Unterminated string in line: {}".format(line))
leave()
sys.exit(1)
if len(line) == 0: if len(line) == 0:
continue continue

View File

@ -7,22 +7,28 @@
main: main:
enter enter
mov ax0, .buf
call print
prn 10
mov ax0, .msg mov ax0, .msg
call print call print
mov ax0, .buf mov ax0, .buf
mov ax1, .msg mov ax1, .msg
call strrev mov ax2, 5
call strnzcpy
prn 10 prn 10
mov ax0, .buf mov ax0, .buf
call print mov ax1, 10
call print_n
leave leave
ret ret
.msg = "Hello World :)" .msg = "HelloWorld :)"
.buf = "!!!!!!!!!!!!!!!!!!!!!" .buf = "!!!!!!!!!!!!!"
; ;
; Exit function ; Exit function

View File

@ -16,6 +16,7 @@ print:
.1: .1:
test b[ax0], b[ax0] test b[ax0], b[ax0]
cjmpz .2 cjmpz .2
prn b[ax0] prn b[ax0]
inc ax0 inc ax0
loop .1 loop .1

View File

@ -5,26 +5,54 @@
; void strcpy(char *, const char *) ; void strcpy(char *, const char *)
; ;
strcpy: strcpy:
mov b[ax0], b[ax1]
test b[ax1], b[ax1] test b[ax1], b[ax1]
cmovz b[ax0], 0
cretz cretz
.1: inc ax0
test b[ax1], b[ax1] inc ax1
cmovz b[ax0], 0 jmp strcpy
cretz
ret
; ;
; void strncpy(char *, const char *, int) ; void strncpy(char *, const char *, int)
; ;
strncpy: strncpy:
mov rcx, ax2
jcxz .2
dec rcx
.1:
mov b[ax0], b[ax1]
test b[ax1], b[ax1]
cretz
inc ax0
inc ax1
loop .1
.2:
ret ret
; ;
; void strnzcpy(char *, const char *, int) ; void strnzcpy(char *, const char *, int)
; ;
strnzcpy: strnzcpy:
ret mov rcx, ax2
jcxz .2
dec rcx
.1:
mov b[ax0], b[ax1]
test b[ax1], b[ax1]
cretz
inc ax0
inc ax1
loop .1
.2:
mov b[ax0], 0
ret

View File

@ -21,7 +21,7 @@ strlen:
strnlen: strnlen:
xor rax, rax xor rax, rax
mov rcx, ax1 mov rcx, ax1
;jcxz .2 jcxz .2
dec rcx dec rcx
.1: .1:
@ -32,4 +32,5 @@ strnlen:
inc ax0 inc ax0
loop .1 loop .1
.2:
ret ret

View File

@ -22,13 +22,14 @@ IMPL_START_1(prn)
log("prn warning: large access size\n"); log("prn warning: large access size\n");
} }
/*
if (!(v1 >= ' ' && v1 < 128) && v1 != '\t' && v1 != '\n') { if (!(v1 >= ' ' && v1 < 128) && v1 != '\t' && v1 != '\n') {
log("prn on invalid character: %ld\n", v1); log("prn on invalid character: %ld\n", v1);
return;
} }
*/
else { putchar((int)v1);
putchar((int)v1);
}
} }
IMPL_END; IMPL_END;

View File

@ -95,22 +95,12 @@ void writemem8(ctx_t *ctx, ulong val, ulong addr)
ushort v = ctx->mp[real]; ushort v = ctx->mp[real];
if (!(addr % 2)) { if (!(addr % 2)) {
ctx->mp[real] = ((v & 0xFF00) << 8) | (val & 0xFF);
}
else {
ctx->mp[real] = (v & 0xFF) | (((val & 0xFF) << 8));
}
/*
if (addr % 2) {
ctx->mp[real] = (v & 0xFF00) | (val & 0xFF); ctx->mp[real] = (v & 0xFF00) | (val & 0xFF);
} }
else { else {
ctx->mp[real] = (v & 0xFF) | (((val & 0xFF) << 8)); ctx->mp[real] = (v & 0xFF) | (((val & 0xFF) << 8));
} }
*/
} }
void writemem16(ctx_t *ctx, ulong val, ulong addr) void writemem16(ctx_t *ctx, ulong val, ulong addr)