assembly - Assembler stuck in sys_read loop -
i've written piece of code takes number in ascii characters prompt, converts decimal number , stores in 'dnumber'. conversion has been checked , goes well. goes wrong @ prompt. seems stuck in infinite loop while asking user ascii character number. want program stop asking input when user presses enter, termination value never seems reached though think i've set way.
i've asked 2 related questions on forum lately , showed don't understand system calls properly. i've read documentation on 'http://www.tutorialspoint.com/assembly_programming', 'http://cs.lmu.edu/~ray/notes/nasmtutorial/' , of 'http://www.x86-64.org/documentation/abi.pdf' , apparently i'm still not getting it. can show me light.
here compiler info:
nasm -f elf64 convinput.asm ld -s -o convinput convinput.o
here prompt:
$ ./convinput enter number , press enter: 123 123 123
as can see i've pressed enter twice, prompt still asks input.
here code:
section .text global _start _start: mov eax, 4 mov ebx, 1 mov edx, lenmsg1 mov ecx, msg1 int 80h xor eax, eax xor ebx, ebx xor edx, edx mov esi, data call input mov esi, data movzx ecx, byte [dignum] xor ebx,ebx ; clear ebx call string_to_int mov dword [dnumber], eax mov eax, 1 mov ebx, 0 int 80h input: mov eax, 3 mov ebx, 0 mov ecx, esi mov edx, 1 int 80h inc byte [dignum] cmp byte [esi], 13 inc esi jne input ret string_to_int: xor ebx,ebx movzx eax, byte [esi] inc esi sub al,'0' ; convert ascii number4 mov ebx, 10 mul ebx add ebx,eax ; ebx = ebx*10 + eax dec byte [dignum] cmp byte [dignum], 0 jne string_to_int mov eax,ebx ret section .bss dignum resb 1 data resb 1000 dnumber resd 1 section .data msg1 db 'enter number , press enter: ', 10, 0 lenmsg1 equ $ -msg1 ; esi = pointer string convert ; ecx = number of digits in string (must > 0) ; output: ; eax = integer valu
judging values put eax using 32-bit syscall table, on linux different 64-bit one.
you can see syscalls (and arguments) called running program under strace.
Comments
Post a Comment