aboutsummaryrefslogtreecommitdiff
path: root/liblang.asm
diff options
context:
space:
mode:
Diffstat (limited to 'liblang.asm')
-rw-r--r--liblang.asm22
1 files changed, 20 insertions, 2 deletions
diff --git a/liblang.asm b/liblang.asm
index 52a68cc..3ae345d 100644
--- a/liblang.asm
+++ b/liblang.asm
@@ -4,7 +4,7 @@ SYS_READ equ 0x2000003 ;fd, buf, len
SYS_WRITE equ 0x2000004 ;fd, buf, len
SYS_MMAP equ 0x20000C5 ;addr, len, prot, flags, fd, offset
-global start, putc, putint, getc, _builtin_malloc
+global start, putc, putint, getc, exit, _builtin_malloc, _builtin_outofbounds
default rel
extern main
@@ -109,6 +109,12 @@ getc:
mov rax, -1
jmp .finish
+exit:
+ mov rdi, [rsp+8]
+ mov eax, SYS_EXIT
+ syscall
+ jmp $
+
_builtin_malloc:
push rdi
push rsi
@@ -136,6 +142,18 @@ _builtin_malloc:
pop rdi
ret
+_builtin_outofbounds:
+ mov edi, 2
+ lea rsi, [outofbounds_msg]
+ mov rdx, outofbounds_msg.len
+ mov eax, SYS_WRITE
+ syscall
+ mov edi, 255
+ mov eax, SYS_EXIT
+ syscall
+ jmp $
+
section .data
-db 0 ; for dyld
+outofbounds_msg: db "Runtime Error: Out-of-bounds array access detected", 10
+.len: equ $ - outofbounds_msg