Witam, chciałem się dowiedzieć czemu mój kod nie działa kiedy próbuję użyć stosu.
Kod wypisuje "zerowy" argument programu (odpowiednik argv[0] z C), a długość tego argumentu sprawdza "funkcją".
Kod bez użycia stosu:
format elf executable
entry _start
segment readable executable
strlen:
mov ebx,0
strlen_loop:
cmp byte [eax+ebx],0
je strlen_end
inc ebx
jmp strlen_loop
strlen_end:
inc ebx
ret
_start:
mov eax,[esp+4]
call strlen
mov eax,4
mov ecx,[esp+4]
mov edx,ebx
mov ebx,0
int 80h
mov eax,1
mov ebx,0
int 80h
Kod z użyciem stosu:
format elf executable
entry _start
segment readable executable
strlen:
mov ebx,0
strlen_loop:
cmp byte [eax+ebx],0
je strlen_end
inc ebx
jmp strlen_loop
strlen_end:
inc ebx
ret
_start:
mov eax,[esp+4]
call strlen
push ebx
mov eax,4
mov ebx,0
mov ecx,[esp+4]
pop edx
int 80h
mov eax,1
mov ebx,0
int 80h
Bez użycia stosu program normalnie wypisuje swoją nazwę, niestety w drugim przypadku po prostu się wyłącza.
Czy ktoś mógłby mi wyjaśnić co robię źlę w drugim przypadku?