This repository has been archived on 2025-10-24. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nub-lang-archive-2/src/CLI/Runtime/entry.s
nub31 6d3c241368 ...
2025-06-15 00:50:31 +02:00

62 lines
1.6 KiB
ArmAsm

.intel_syntax noprefix
.equ SYS_EXIT, 60
.text
.globl _start
_start:
mov rdi, [rsp] # rdi = argc
# Calculate the size of the array
mov rax, rdi # Start with argc
shl rax, 3 # Multiply argc by 8
add rax, 8 # Add space for the array size
# Allocate array size on the stack (aligned to 16 bytes)
add rax, 15
and rax, -16
sub rsp, rax
# Store number of elements at the start of the array
mov [rsp], rdi
mov rcx, rdi # rcx = loop counter
lea rsi, [rsp + rax + 8] # rsi = argv[0]
lea rdi, [rsp + 8] # rdi = destination_array[0]
convert_loop:
test rcx, rcx
jz done_converting
# Convert current cstring using nub_cstring_to_string
push rcx # Save loop counter
push rsi # Save argv[i]
push rdi # Save destination_array[i]
mov rdi, [rsi] # Load current argv[i] (cstring)
call nub_cstring_to_string
pop rdi # Restore destination pointer
pop rsi # Restore argv pointer
pop rcx # Restore loop counter
test rax, rax
jz conversion_failed
# Store converted string pointer in our array
mov [rdi], rax # Store converted string pointer
add rdi, 8 # Move to next destination_array entry
add rsi, 8 # Move to next argv entry
dec rcx # Decrement counter
jmp convert_loop
done_converting:
mov rdi, rsp
call main
mov rdi, rax
mov rax, SYS_EXIT
syscall
conversion_failed:
call nub_panic