feat: beta compiling to fasm (codegen) + hello world example let's goooo
This commit is contained in:
39
test.asm
39
test.asm
@ -1,16 +1,39 @@
|
||||
format ELF64
|
||||
|
||||
section ".text" executable
|
||||
|
||||
public main
|
||||
section '.text' executable
|
||||
|
||||
extrn 'putchar' as __putchar
|
||||
putchar = PLT __putchar
|
||||
|
||||
public main
|
||||
|
||||
main:
|
||||
mov rdi, 69
|
||||
; create stack frame
|
||||
push rbp
|
||||
mov rbp, rsp
|
||||
sub rsp, 8 ; space for locals: a (4 bytes), b (4 bytes)
|
||||
|
||||
; t0 = LOAD_CONST 34
|
||||
mov dword [rbp-4], 34 ; STORE "a", t0
|
||||
|
||||
; t1 = LOAD_CONST 35
|
||||
mov dword [rbp-8], 35 ; STORE "b", t1
|
||||
|
||||
; t2 = LOAD "a"
|
||||
mov eax, [rbp-4]
|
||||
|
||||
; t3 = LOAD "b"
|
||||
mov ecx, [rbp-8]
|
||||
|
||||
; t4 = ADD t2, t3
|
||||
add eax, ecx ; eax = t4
|
||||
|
||||
; PARAM t4 → first arg in EDI
|
||||
mov edi, eax
|
||||
|
||||
; t5 = CALL putchar
|
||||
call putchar
|
||||
mov rdi, 10
|
||||
call putchar
|
||||
mov rax, 0
|
||||
ret
|
||||
|
||||
; function return (SysV: rax contains return value from putchar)
|
||||
leave
|
||||
ret
|
||||
Reference in New Issue
Block a user