NASM에서 매개변수 넣어 함수 호출할 때 오류가 나네요.
      글쓴이: hiluciano / 작성시간: 토, 2014/06/07 - 9:57오전    
  
  section .data
	message: db "Hello, World!", 0Dh, 0Ah, 00h
section .text
	extern _printf
	global _main
_main:
	push message
	call _printf
	add esp, 4
	; myprint(0);에 해당
	mov eax, 0
	push eax
	call _myprint ; 이 부분에서 자꾸 "작동이 중지되었습니다"라는 오류창이 뜹니다.
	add esp, 4
	xor eax, eax
	ret
; void myprint(int foo);
_myprint:
	pop eax
	push message
	call _printf
	add esp, 4
	xor eax, eax
	ret
위 소스의 어디가 잘못된 것인가요? printf 호출시에는 아무 문제가 없던데 함수를 직접 정의해서 호출하려니까 오류가 나네요.
Forums: 


함수를 call 하면서 리턴 주소를
함수를 call 하면서 리턴 주소를 push합니다.
때문에 함수 부분에서의 pop eax 가 먼저 push된 eax가 아닌 리턴 주소를 pop하게 되어 프로그램이 얽혀 버리죠.
댓글 달기