feat: beta compiling to fasm (codegen) + hello world example let's goooo
This commit is contained in:
35
hello.asm
Normal file
35
hello.asm
Normal 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
|
||||
Reference in New Issue
Block a user