I'm learning assembler language. When I started reading about stack, I tried to write code that adds two numbers and debug it. But when try to call function "add" I get
Program received signal SIGSEGV, Segmentation fault.
The main problem is that the program gives this error without even entering the ADD function. That is, the program, even without executing the call add command, terminates urgently.
here is the code:
global _start
section .text
_start:
call main
add:
push ebp
mov ebp, esp
sub esp, 4
mov eax, [ebp + 8]
mov ebx, [ebp + 12]
add eax, ebx
mov [ebp - 4], eax
ret
main:
push ebp
mov ebp, esp
sub esp, 12
mov [ebp - 8], dword 2
mov [ebp - 12], dword 40
call add
ret
here is the debugging process