SYS_EXIT equ 0x2000001 ;code SYS_FORK equ 0x2000002 ;-- 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, exit, _builtin_malloc, _builtin_outofbounds default rel extern main section .text start: call main mov rdi, rax mov eax, SYS_EXIT syscall jmp $ putc: push rax push rdi push rsi push rdx push rcx push r11 mov eax, SYS_WRITE mov edi, 1 lea rsi, [rsp+56] mov edx, edi syscall pop r11 pop rcx pop rdx pop rsi pop rdi pop rax ret putint: push rdi push rsi push rax push rbx push rcx push rdx push r11 mov rax, [rsp+64] mov ebx, 18 test rax, rax jz .numzero mov ecx, 10 .strlp: xor edx, edx div rcx add dl, '0' dec rbx mov [rsp+rbx], dl test rax, rax jnz .strlp jmp .strdone .numzero: dec rbx mov byte [rsp+rbx], '0' jmp .strdone .strdone: mov eax, SYS_WRITE mov edi, 1 lea rsi, [rsp+rbx] mov edx, 18 sub rdx, rbx syscall pop r11 pop rdx pop rcx pop rbx pop rax pop rsi pop rdi ret getc: push rdi push rsi push rdx push rcx push r11 mov eax, SYS_READ xor edi, edi mov rsi, rsp mov edx, 1 syscall cmp rax, 1 jne .fail mov rax, [rsp] .finish: pop r11 pop rcx pop rdx pop rsi pop rdi ret .fail: mov rax, -1 jmp .finish exit: mov rdi, [rsp+8] mov eax, SYS_EXIT syscall jmp $ _builtin_malloc: push rdi push rsi push rdx push r8 push r9 push r10 push r11 push rcx xor edi, edi mov rsi, [rsp+72] mov edx, 0x03 mov r10d, 0x1001 mov r8d, -1 xor r9d, r9d mov eax, SYS_MMAP syscall pop rcx pop r11 pop r10 pop r9 pop r8 pop rdx pop rsi 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 outofbounds_msg: db "Runtime Error: Out-of-bounds array access detected", 10 .len: equ $ - outofbounds_msg