increment values from stdin





Hello,



I try to write a newbie program which reads a number from stdin, increment

it, and write it back to stdout. Ok, it works, but only from 0 to 8. When

I read 9 from stdin, I get a colon after the increment. I understand why

this happens, but how is this to solve? Is there a simple way to count up

to 65535 (32bit) and convert it back to a string to write it back to

stdout?

I'm using nasm with Intel on Linux and here is my program:



segment .data

prompt1 db "Enter a number: ", 0

len equ $-prompt1



segment .bss

input1 resb 2 ; First I though of allocating 2 bytes will help, but no

difference to 1 byte



segment .text

global _start



_start:

mov eax, 4 ; write system call

mov ebx, 1 ; stdout (=1)

mov ecx, prompt1

mov edx, len

int 0x80 ; syscall



mov eax, 3 ; read system call

mov ebx, 0 ; stdin(0)

mov ecx, input1

mov edx, 10 ; input length in byte

int 0x80



mov eax, [input1] ; move value of input1

sub eax, '0'

inc eax

add eax, '0'

mov [input1], eax ; copy into byte



mov eax, 4

mov ebx, 1

mov ecx, input1

mov edx, len

int 0x80



mov eax, 1 ; kernel exit

mov ebx, 0

int 0x80







Thanks for helping,

Markus

.



Relevant Pages