1
0
mirror of https://gitlab.os-k.eu/os-k-team/kvisc.git synced 2023-08-25 14:05:46 +02:00
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
@echo "output:"
@echo ">>>>>>>>"
@cat out/stdout.txt
@cat -v out/stdout.txt
@echo
@echo "<<<<<<<<"
@echo

View File

@ -156,11 +156,20 @@ def parse():
if len(line) == 0:
continue
quote = False
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()
break
if quote:
print("Unterminated string in line: {}".format(line))
leave()
sys.exit(1)
if len(line) == 0:
continue

View File

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

View File

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

View File

@ -5,26 +5,54 @@
; void strcpy(char *, const char *)
;
strcpy:
mov b[ax0], b[ax1]
test b[ax1], b[ax1]
cmovz b[ax0], 0
cretz
.1:
test b[ax1], b[ax1]
cmovz b[ax0], 0
cretz
ret
inc ax0
inc ax1
jmp strcpy
;
; void strncpy(char *, const char *, int)
;
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
;
; void strnzcpy(char *, const char *, int)
;
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:
xor rax, rax
mov rcx, ax1
;jcxz .2
jcxz .2
dec rcx
.1:
@ -32,4 +32,5 @@ strnlen:
inc ax0
loop .1
.2:
ret

View File

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

View File

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