Reputation: 27
when user input 1/2/3/4 , it stil display error
my "nextline" already initial as macro
sample output:
your choice : 1
Please enter 1 or 2 or 3 or 4 only!(1/2/3/4)
your choice : 2
Please enter 1 or 2 or 3 or 4 only!(1/2/3/4)
your choice : 3
Please enter 1 or 2 or 3 or 4 only!(1/2/3/4)
your choice : 4
Please enter 1 or 2 or 3 or 4 only!(1/2/3/4)
your choice :
dischoice:
mov ah,09h
lea dx,msg14
int 21h ;display ur choice
xor al,al
mov ah,01h
int 21h
mov ah,1
mov bh,2
mov ch,3
mov dh,4
cmp al,ah
je ok
cmp al,bh
je ok
cmp al,ch
je ok
cmp al,dh
je ok
;jmp ok
jmp notok
notok:
nextline
mov ah,09h
lea dx,msg23;display error
int 21h
nextline
jmp dischoice
ok:
sub al,30h
mov cho,al
nextline
Upvotes: 0
Views: 543
Reputation: 35667
int 21h
looks like... MS DOS? Don't know much of that anymore, was a long time ago, but ah 01h would read from stdin, and I'm pretty sure it would read ASCII value '1' (31h) instead of 1.
So try these instead:
mov ah,31h
mov bh,32h
mov ch,33h
mov dh,34h
or better yet, just do the cmp directly instead of storing it in registers:
cmp al,31h
je ok
cmp al,32h
je ok
cmp al,33h
je ok
cmp al,34h
je ok
Upvotes: 0
Reputation: 58447
You should be comparing against '1'..'4'
, not 1..4
. So something like:
cmp al,'1'
je ok
cmp al,'2'
je ok
; ... and so on ...
Since you take the same action for all numbers that are considered "ok", this can be simplified to:
cmp al,'1'
jb notok ; if al < '1' goto notok
cmp al,'4'
jbe ok ; if al >= '1' and al <= '4' goto ok
notok:
Also, this jump is pointless and should be removed:
jmp notok
notok:
Upvotes: 1