Witam,
Kod programu jest następujący:
section .text ; begin of the code section
global main ; ld needs that label
; constants for Linux@x86
%define sys_exit 1
%define sys_read 3
%define sys_write 4
%define stdin 0
%define stdout 1
; external libc functions
extern printf
; ************** ;
; main program ;
; ************** ;
main:
mov eax, 5 ; EAX = 5
call print_int ; print integer in EAX
call print_nl ; newline
mov eax, 0
ret ; main returns to OS
;
; end main program
;
; ******************** ;
; library procedures ;
; ******************** ;
print_nl: ; printf("\n")
; put registers on stack
push edx
push ecx
push ebx
push eax
push ebp ; set up stack frame
mov ebp, esp
mov eax, sys_write
mov ebx, stdout
mov ecx, char_nl
mov edx, 1 ; length of 0ah
int 80h ; syscall
mov esp, ebp ; takedown stack frame
pop ebp
pop eax
pop ebx
pop ecx
pop edx
ret ; return to previous block
;
; print_int: printf("%d", EAX)
;
print_int:
push ebp ; set up stack frame
mov ebp, esp
;
; do: printf("%d", EAX)
;
push eax ; value of int to printf
push dword str_int ; address of: "%d", 0
call printf ; call C function
add esp, 8 ; pop stack 2 times 4 bytes
mov esp, ebp ; takedown stack frame
pop ebp
ret ; return to previous block
section .bss ; uninitialized data section
section .data ; initialized data section
str_int db "%d", 0
char_nl db 0ah
Problem: Dane wyjściowe nie są prezentowane we właściwy sposób.
5margor@xeon:~/programowanie/projekty/5nasmlib>
Spodziewany efekt:
5
margor@xeon:~/programowanie/projekty/5nasmlib>
Czytam mój kod i nie widzę błędu. Wychodzi na to, że ret nie wraca tam, gdzie powinno. Będę wdzięczny za podpowiedź. Jak najlepiej debugować problemy tego typu?
Pozdrawiam,