Let me explain it briefly :).
I approach the argument 10, by using EBP register with ebx register because of the stack structure of which is containing EBP(base register), return address, # of parameter, parameter 1, parameter 2... since I don't use a local register. I could see the parameter was appropriately input as I could print it using call print_string. But, since < while: > code line, it seems like the string 10 doesn't seem to be read for the commend line does nothing when it comes to it. I would gently ask where to start with the code. thanks for reading.
Input : ./atoi 10
Result : 10
%include "asm_io.inc"
segment .data
segment .bss
input resw 1
segment .text
global main
main:
enter 0,0
pusha
mov ebx, [ebp+12]
mov eax, [ebx+4]
; call print_string
dump_stack 1,2,4
mov ebx, 0
mov ecx, 10
while:
cmp al, 0x0a
je print
sub eax, 0x30
mov [input], eax
mov eax, ebx
mul ecx
add eax, [input]
mov ebx, eax
jmp while
print:
mov eax, ebx
call print_int
call print_nl
popa
mov eax, 0
leave
ret
eaxis a pointer. You need to 1) dereference and 2) increment it. Also make sure you use the correct operand sizes (a char is 1 byte).%eaxis at&t syntax and even there it doesn't dereference. I even missedinput, that's defined as word which is doubly wrong. Yeahresbwould be better but then of course you can't store 32 bits into it. Not that I understand why you need that at all.