How not to permit user from inputing a invalid characters

kindly help me..
i have this idea that the user can only type letters from a-z / A-Z
if the user type other character besides the given from the permitted characters the computer will ask again for the input it will only stop when the user have the right input.
then if the user type letter "D" (for example) then the screen will display D-Z characters. or example the input is "r" then the screen will display r-z letters..
i'm using the dos command can u help me with my prob? i have a sample program but it allows the user from entering special characters. which is my prob.. it shouldn't allow the user...

0AEE:0100 mov ah,07
0AEE:0102 int 21
0AEE:0104 mov ah,02
0AEE:0106 mov dl,al
0AEE:0108 int 21
0AEE:010A inc dl
0AEE:010C cmp dl,5a
0AEE:010F jle 108
0AEE:0111 cmp dl,5b
0AEE:0104 jz 011f
0AEE:0106 int 21
0AEE:0108 inc dl
0AEE:010A cmp dl,7a
jle 0116
int 20

>>> hope you can help thanks ^_^

Comments

  • You have to check if AL after INT21/AH=07 is in the range a-z or A-Z.
    ASCII codes for A and a are 65 and 97 respectively, so the ranges are 65-90 and 97-122.

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
  • i try to change my code by what u said but the problem is the display character is only 2 consecutive if i type "a" the display shows only ab instead of a-z
  • : i try to change my code by what u said but the problem is the
    : display character is only 2 consecutive if i type "a" the display
    : shows only ab instead of a-z
    :

    Are you using Debug.exe for your code? If so, I advise you download NASM.
    Then you can write the code in notepad and compile when you're done. The advantage is that you can then use labels.
    Consider the following:
    [code]
    mov ah, 07h
    int 21h
    cmp al, 41h ; Compare AL with 'A'
    je CharIsA
    ; Character is not 'A'
    *** lots of code here ***

    CharIsA:
    mov ah, 02h
    int 21h
    [/code]
    You can just use the label CharIsA and not worry about which address it's going to be on - meaning you don't need to know how much code will be put at the ***'s.

    Anyway, maybe you already knew this all and I'm just boring you to death ;)

    Now to answer your question:
    You need to create a loop.
    Here's an example in NASM-style. It only works for when AL contains a character from 'A' to 'Z' (not for the non-capital either).
    [code]
    mov cx, 1Ah ;1A = 26 = number of characters in the alfabet
    mov dx, al
    sub dx, 41h ;dx = the amount of characters from 'A' to AL exclusively
    sub cx, dx ;cx = the amount of character from AL to 'Z' inclusively
    PrintLoop:
    mov ah, 02h
    int 21h ;Print character
    inc al ;Proceed to next character
    loop PrintLoop ;Do this loop cx times
    [/code]

    Best Regards,
    Richard

    The way I see it... Well, it's all pretty blurry
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories