clean up runtime

This commit is contained in:
nub31
2025-06-10 22:22:49 +02:00
parent 9f48f2cd9b
commit 299e06a03e
6 changed files with 40 additions and 50 deletions

View File

@@ -2,9 +2,10 @@
.extern main .extern main
.section .text .section .text
.globl _start .global _start
_start: _start:
mov rdi, rsp mov rdi, rsp
# main([]^string): i64
call main call main
mov rdi, rax mov rdi, rax
mov rax, 60 mov rax, 60

View File

@@ -1,24 +1,20 @@
.intel_syntax noprefix .intel_syntax noprefix
.section .text .section .text
# Memory copy function # func nub_memcpy(destination: ^u8, source: ^u8, count: u64): ^u8
# Arguments: rdi = destination, rsi = source, rdx = count .global nub_memcpy
# Returns: rdi (original destination pointer)
.globl nub_memcpy
nub_memcpy: nub_memcpy:
push rdi # Save original destination for return value push rdi
mov rcx, rdx # Load count into counter register mov rcx, rdx
# Handle zero count case
test rcx, rcx test rcx, rcx
jz .done jz memcpy_done
# Simple byte-by-byte copy (no overlap handling) memcpy_loop:
.loop: mov al, BYTE PTR [rsi]
mov al, BYTE PTR [rsi] # Load byte from source mov BYTE PTR [rdi], al
mov BYTE PTR [rdi], al # Store byte to destination inc rsi
inc rsi # Move to next source byte inc rdi
inc rdi # Move to next destination byte dec rcx
dec rcx # Decrement counter jnz memcpy_loop
jnz .loop # Continue if counter not zero memcpy_done:
.done: pop rax
pop rax # Return original destination pointer
ret ret

View File

@@ -1,22 +1,19 @@
.intel_syntax noprefix .intel_syntax noprefix
.section .text .section .text
# Memory set function # func nub_memset(destination: ^u8, value: i8, count: u64): ^u8
# Arguments: rdi = destination pointer, rsi = value (byte), rdx = count .global nub_memset
# Returns: rdi (original destination pointer)
.globl nub_memset
nub_memset: nub_memset:
push rdi # Save original destination for return value push rdi
mov rcx, rdx # Load count into counter register mov rcx, rdx
mov al, sil # Move byte value to al (lower 8 bits of rsi) mov al, sil
# Handle zero count case
test rcx, rcx test rcx, rcx
jz .done jz memset_done
.loop: memset_loop:
mov BYTE PTR [rdi], al # Store byte at current position mov BYTE PTR [rdi], al
inc rdi # Move to next byte inc rdi
dec rcx # Decrement counter dec rcx
jnz .loop # Continue if counter not zero jnz memset_loop
.done: memset_done:
pop rax # Return original destination pointer pop rax
ret ret

View File

@@ -1,10 +1,8 @@
.intel_syntax noprefix .intel_syntax noprefix
.section .text .section .text
# Panic function with message # func nub_panic(message: ^u8, message_length: u64): void
# Arguments: rdi = message (*char), rsi = message length (long) .global nub_panic
# Remarks: exits the program
.globl nub_panic
nub_panic: nub_panic:
mov rdx, rsi mov rdx, rsi
mov rsi, rdi mov rsi, rdi

View File

@@ -1,24 +1,22 @@
.intel_syntax noprefix .intel_syntax noprefix
.section .text .section .text
# String comparison function null-terminated strings # func nub_strcmp(lhs: ^u8, rhs: ^u8): bool
# Arguments: rdi = lhs (*char), rsi = rhs (*char) .global nub_strcmp
# Returns: 1 if equal, else 0
.globl nub_strcmp
nub_strcmp: nub_strcmp:
xor rdx, rdx xor rdx, rdx
.loop: strcmp_loop:
mov al, BYTE PTR [rsi + rdx] mov al, BYTE PTR [rsi + rdx]
mov bl, BYTE PTR [rdi + rdx] mov bl, BYTE PTR [rdi + rdx]
inc rdx inc rdx
cmp al, bl cmp al, bl
jne .not_equal jne strcmp_not_equal
cmp al, 0 cmp al, 0
je .equal je strcmp_equal
jmp .loop jmp strcmp_loop
.not_equal: strcmp_not_equal:
mov rax, 0 mov rax, 0
ret ret
.equal: strcmp_equal:
mov rax, 1 mov rax, 1
ret ret

View File

@@ -1,5 +1,5 @@
.intel_syntax noprefix .intel_syntax noprefix
.globl core_syscall .global core_syscall
.section .text .section .text
core_syscall: core_syscall: