Files
pl/test.asm

39 lines
725 B
NASM

format ELF64
section '.text' executable
extrn 'putchar' as __putchar
putchar = PLT __putchar
public main
main:
; 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
; function return (SysV: rax contains return value from putchar)
leave
ret