clean up runtime
This commit is contained in:
@@ -2,9 +2,10 @@
|
||||
.extern main
|
||||
.section .text
|
||||
|
||||
.globl _start
|
||||
.global _start
|
||||
_start:
|
||||
mov rdi, rsp
|
||||
# main([]^string): i64
|
||||
call main
|
||||
mov rdi, rax
|
||||
mov rax, 60
|
||||
|
||||
@@ -1,24 +1,20 @@
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# Memory copy function
|
||||
# Arguments: rdi = destination, rsi = source, rdx = count
|
||||
# Returns: rdi (original destination pointer)
|
||||
.globl nub_memcpy
|
||||
# func nub_memcpy(destination: ^u8, source: ^u8, count: u64): ^u8
|
||||
.global nub_memcpy
|
||||
nub_memcpy:
|
||||
push rdi # Save original destination for return value
|
||||
mov rcx, rdx # Load count into counter register
|
||||
# Handle zero count case
|
||||
push rdi
|
||||
mov rcx, rdx
|
||||
test rcx, rcx
|
||||
jz .done
|
||||
# Simple byte-by-byte copy (no overlap handling)
|
||||
.loop:
|
||||
mov al, BYTE PTR [rsi] # Load byte from source
|
||||
mov BYTE PTR [rdi], al # Store byte to destination
|
||||
inc rsi # Move to next source byte
|
||||
inc rdi # Move to next destination byte
|
||||
dec rcx # Decrement counter
|
||||
jnz .loop # Continue if counter not zero
|
||||
.done:
|
||||
pop rax # Return original destination pointer
|
||||
jz memcpy_done
|
||||
memcpy_loop:
|
||||
mov al, BYTE PTR [rsi]
|
||||
mov BYTE PTR [rdi], al
|
||||
inc rsi
|
||||
inc rdi
|
||||
dec rcx
|
||||
jnz memcpy_loop
|
||||
memcpy_done:
|
||||
pop rax
|
||||
ret
|
||||
|
||||
@@ -1,22 +1,19 @@
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# Memory set function
|
||||
# Arguments: rdi = destination pointer, rsi = value (byte), rdx = count
|
||||
# Returns: rdi (original destination pointer)
|
||||
.globl nub_memset
|
||||
# func nub_memset(destination: ^u8, value: i8, count: u64): ^u8
|
||||
.global nub_memset
|
||||
nub_memset:
|
||||
push rdi # Save original destination for return value
|
||||
mov rcx, rdx # Load count into counter register
|
||||
mov al, sil # Move byte value to al (lower 8 bits of rsi)
|
||||
# Handle zero count case
|
||||
push rdi
|
||||
mov rcx, rdx
|
||||
mov al, sil
|
||||
test rcx, rcx
|
||||
jz .done
|
||||
.loop:
|
||||
mov BYTE PTR [rdi], al # Store byte at current position
|
||||
inc rdi # Move to next byte
|
||||
dec rcx # Decrement counter
|
||||
jnz .loop # Continue if counter not zero
|
||||
.done:
|
||||
pop rax # Return original destination pointer
|
||||
jz memset_done
|
||||
memset_loop:
|
||||
mov BYTE PTR [rdi], al
|
||||
inc rdi
|
||||
dec rcx
|
||||
jnz memset_loop
|
||||
memset_done:
|
||||
pop rax
|
||||
ret
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# Panic function with message
|
||||
# Arguments: rdi = message (*char), rsi = message length (long)
|
||||
# Remarks: exits the program
|
||||
.globl nub_panic
|
||||
# func nub_panic(message: ^u8, message_length: u64): void
|
||||
.global nub_panic
|
||||
nub_panic:
|
||||
mov rdx, rsi
|
||||
mov rsi, rdi
|
||||
|
||||
@@ -1,24 +1,22 @@
|
||||
.intel_syntax noprefix
|
||||
.section .text
|
||||
|
||||
# String comparison function null-terminated strings
|
||||
# Arguments: rdi = lhs (*char), rsi = rhs (*char)
|
||||
# Returns: 1 if equal, else 0
|
||||
.globl nub_strcmp
|
||||
# func nub_strcmp(lhs: ^u8, rhs: ^u8): bool
|
||||
.global nub_strcmp
|
||||
nub_strcmp:
|
||||
xor rdx, rdx
|
||||
.loop:
|
||||
strcmp_loop:
|
||||
mov al, BYTE PTR [rsi + rdx]
|
||||
mov bl, BYTE PTR [rdi + rdx]
|
||||
inc rdx
|
||||
cmp al, bl
|
||||
jne .not_equal
|
||||
jne strcmp_not_equal
|
||||
cmp al, 0
|
||||
je .equal
|
||||
jmp .loop
|
||||
.not_equal:
|
||||
je strcmp_equal
|
||||
jmp strcmp_loop
|
||||
strcmp_not_equal:
|
||||
mov rax, 0
|
||||
ret
|
||||
.equal:
|
||||
strcmp_equal:
|
||||
mov rax, 1
|
||||
ret
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
.intel_syntax noprefix
|
||||
.globl core_syscall
|
||||
.global core_syscall
|
||||
.section .text
|
||||
|
||||
core_syscall:
|
||||
|
||||
Reference in New Issue
Block a user