According to my assignment requirement I wrote this program, but still doesn't work......can someone help.....please
Here is my exercise:

"Write assembly code in ASSEMBLY LANGUAGE to read a password from the keyboard. Display the message ' Enter Password: ' and echo each character that the user types as an asterisk(*). If the user types a backspace character ( which enters as the number 8), erase the last character typed by displaying a backspace. a space and another backspace. You shouldn't erase beyond the beginning of the password so you need to keep a count of the asterisks on the screen."

Here is my code

.model small
.586
.stack 100h
INCLUDE C:\MASM615\Programs\PCMAC.INC
.DATA

MSG DB 'Enter Password: $'
PWD DB 'abcd'
Correct db 'Password Correct!$'
WRONG DB 'Password not correct! Please Enter again!$'

.CODE

PASSWORD PROC

START:
     mov ax, @DATA
     mov ds, ax
     mov di, offset pwd
     _Begin
     _PutStr msg


GetLoop:    

     _GetCh noEcho
     cmp al, 13
     je COMPARE
     cmp al, 'a'
     jnae EchoIt
     cmp al, 'z'
     jnbe EchoIt
     add al, '*'-'a'

     cmp al, 8
     je BACKSPACE

BACKSPACE:
    mov ah, 0Eh
    mov al, 8
    int 10h
    mov al, 32
    int 10h
    mov al, 8
    int 10h
    jmp GetLoop

COMPARE:
    mov dl, [di]
    mov ah, 8h
    int 21h
    cmp dl, al
    je DONE
    jmp NOTCORRECT

EchoIt:
     _PutCh al
     jmp GetLoop


DONE:
    _PutStr Correct
     _Exit 0

NOTCORRECT:
    _PutStr WRONG
    jmp START


PASSWORD ENDP
END PASSWORD

Recommended Answers

The first problem is that you aren't storing the password anywhere. You can't just compare characters as they come in. The user is allowed to backspace and correct mistakes. You don't compare the password to anything until the user presses enter (13). So you'll need an area large enough to …

Jump to Post

All 2 Replies

The first problem is that you aren't storing the password anywhere. You can't just compare characters as they come in. The user is allowed to backspace and correct mistakes. You don't compare the password to anything until the user presses enter (13). So you'll need an area large enough to hold the longest password you allow, and a length field. I haven't done 8086 assembly in years, but something like:

MAX_LENGTH equ 16
password_length dw 0
password_data db MAX_LENGTH dup (?)
              db ? ; guard byte, leave room for terminating 0x00

In the input routine, I'd separate the control characters (01Fh and below, plus the 07Fh DEL control) from printable ASCII (020h..07Eh).
For each printable ASCII character, test to see that the password_length is less than the maximum. If so, store the byte, and increase the length:

      mov bx,password_length
      cmp bx,MAX_LENGTH
      jae ERROR ; too big, go beep or something
      mov password_data[bx],al ; store pw char
      inc bx                   ; and increment length
      mov password_length,bx
      mov al,'*'               ; and finally, echo the *
      _PutCh al

Something like that. The backspace code will test the length for being greater than 0, jumping to ERROR if not, and simply decrement password_length by 1 before displaying the 08h, ' ', 08h sequence.

When the Enter key (0Dh) is detected, compare the length of the entered password to the length of the actual password (unless you're using a C-style string comparison where each string has a terminating 00h byte) and then compare the first (password_length) bytes of password_data to the actual password. If you use C strings (aka "ASCIIZ strings"), be sure to append a zero byte to terminate the entered password text:

        mov bx,password_length
        mov password_data[bx],00h

I don't know what string handling macros you have, or if you can call C runtime functions like strcmp().

If you're going to use the DOS "Write string" function, you'll need to terminate the string with a '$' instead of a zero byte.

Finally, I don't see what you're doing testing for 'a' and 'z' in the input. It looks like you're trying to convert to upper case, but the value to subtract is ('a' - 'A') in that case, and I don't see case shifting in your assignment description.

Thanks for your reply

The reason of why to testing for 'a' and 'z' it is an example from the book that convert when user typing a-z will convert to a upper case, that's why I try to using this example to convert all into '*' when user input from a-z

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.