increment values from stdin
- From: Markus Pitha <spamtrap@xxxxxxxxxx>
- Date: Fri, 16 Mar 2007 00:02:04 +0100
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
.
- Follow-Ups:
- Re: increment values from stdin
- From: Spoon
- Re: increment values from stdin
- From: Frank Kotler
- Re: increment values from stdin
- Prev by Date: Re: Optimization Questions
- Next by Date: Re: Keyboard Input and Command Line Buffers
- Previous by thread: mouse interrupt - NO DRIVER
- Next by thread: Re: increment values from stdin
- Index(es):
Relevant Pages
|
|