assembly - Changes value use in all functions (NASM) -
i have problem accumulator eax. in main function don't true value. in set, put eax 1. accumulator 8. set function change value in set function. how can use changes in functions?
function: mov edx, [esp +4] cmp edx, 3 je set ret set: mov eax,1 ret main: pushad mov eax,0 mov, ebx,2 loop: add ebx,1 call function push eax push ; string db... call printf ; print number 8 add esp,8 cmp ebx, 4 jne loop popad ret
you not passing arguments function
, presumably comparison false , eax
remains unchanged. first time around should zero, on it's return value printf
may 8
. want pass ebx
argument function
, either preserve eax
through printf
or 0 explicitly in function
. example:
main: pushad mov eax,0 mov ebx,2 loop: add ebx,1 push ebx ; pass argument call function add esp, 4 ; free argument push eax ; save eax push eax push ; string db... call printf ; print number 8 add esp,8 pop eax ; restore eax cmp ebx, 4 jne loop popad ret
ps: learn use debugger find own mistakes.
here other version function
returns 0
or 1
:
function: mov edx, [esp +4] cmp edx, 3 je set mov eax, 0 ret set: mov eax,1 ret main: pushad mov ebx,2 loop: add ebx,1 push ebx ; pass argument call function add esp, 4 ; free argument push eax push ; string db... call printf ; print number 8 add esp,8 cmp ebx, 4 jne loop popad ret
Comments
Post a Comment