feat: beta compiling to fasm (codegen) + hello world example let's goooo

This commit is contained in:
2025-11-30 22:04:35 +01:00
parent 22f745e8dc
commit 16cc06b788
14 changed files with 1141 additions and 135 deletions

35
hello.asm Normal file
View File

@ -0,0 +1,35 @@
format ELF64
section '.text' executable
extrn 'putchar' as __putchar
putchar = PLT __putchar
public main
main:
; allocate space for locals (a and b: 4 bytes each → 8 bytes total)
push rbp
mov rbp, rsp
sub rsp, 8
; local a = 34 → stored at [rbp - 4]
mov dword [rbp - 4], 34
; local b = 35 → stored at [rbp - 8]
mov dword [rbp - 8], 35
; compute a + b
mov eax, [rbp - 4]
add eax, [rbp - 8]
; call putchar(a + b)
; SysV: first integer arg → EDI
mov edi, eax
call putchar
; return 0 from main
mov eax, 0
leave
ret