Wednesday, October 18, 2006

Bad luck

This is a program that simply extracts numbers from buffered input. I do not have any idea why this didn’t work. I got a zero.



input:
mov ah, 0ah ; buffered input sys call
lea dx, strptr ; load effective address
int 21h ; call kernel

mov ah, 02h ; write character to stdout sys call
mov dl, 0ah ; issue carriage-return
int 21h ; call kernel

lea si, string ; set source index to start of string
mov cl, [strlen] ; set loop counter

here:
mov dl, [si] ; place current character in dl
cmp dl, '0' ; compare if below '0'
jb traverse
cmp dl, '9' ; compare if above '9'
ja traverse

mov ah, 02h ; write character to stdout sys call
int 21h ; call kernel
cmp dl, '$' ; check end-of-string sentinel
je exit

traverse:
inc si ; increment source index pointer

loop here

exit:
int 20h ; terminate

strptr label byte
maxlen db 49
strlen db ?
string db 50 dup ('$')

It runs smoothly on my machine. Damn it.

No comments: