#include <stdio.h>
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(3, 5);
printf("Result: %d\n", result);
return 0;
}
section .data
fmt db "Result: %d", 10, 0
section .text
global main
main:
; Call add function
mov edi, 3
mov esi, 5
call add
; Prepare arguments for printf
mov eax, 0 ; Format specifier for %d
mov edi, fmt ; Format string
mov esi, eax ; Result of add function
; Call printf
mov eax, 0 ; System call number for sys_write
mov ebx, 1 ; File descriptor 1 is stdout
mov ecx, esp ; Address of the format string
int 0x80 ; Call kernel
; Exit the program
mov eax, 1 ; System call number for sys_exit
xor ebx, ebx ; Exit code 0
int 0x80 ; Call kernel
; Function to add two integers
add:
; Function prologue
push ebp
mov ebp, esp
; Add the two parameters
mov eax, [ebp + 8] ; First parameter
add eax, [ebp + 12] ; Second parameter
; Function epilogue
pop ebp
ret