The Mask
The Mask

Reputation: 17437

check if is digit

I have a routine that convert a number to ASCII. The problem is the digit-checking,isn't working.

.loop1: 
    xor edx,edx ;0
    mov ebx,10  ;divisor    
    div ebx      ;eax = eax/ebx 
    add edx,48   ;eax += 48 

    cmp edx,'0' ;if(edx < '0')      
    jl error    ; error()       
    cmp edx,'9' ;if(edx > '9')      
    jg error    ;error()        

    push edx    ;put value into STACK   
    add esi,1       
    test eax,eax    
    jz loop2
    jmp loop1   

The problem is:

    cmp edx,'0'     
    jl error        
    cmp edx,'9'     
    jg error    

Even for mov eax,msg where msg is msg db "abc" the code will not to error routine.

How to fix this?

Upvotes: 0

Views: 1554

Answers (1)

Alexey Frunze
Alexey Frunze

Reputation: 62106

The remainder from unsigned division by 10 is never going to be less than 0 or greater than 9, so those jl and jg instructions are never going to jump to error.

Upvotes: 3

Related Questions