News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

i need help

Started by wghh, November 28, 2009, 12:58:59 PM

Previous topic - Next topic

wghh


i try to wrote an assembly program that will write 10 lines down :

welcome

do you like to proceed (Y/N)

please enter your password

XXXX 4 digits

you have successfully logged in

and that is my code

------------------------------

title my lab4 (exp40.asm)

.model small
.stack 100h
.data
.386
cr equ 0dh
lf equ 0ah
pass equ 4067h

msg1 db "You are welcome to the keyboard program",cr,lf,'$'

msg2 db "Do you like to proceed (Y/N)",cr,lf,'$'

msg3 db "You have pressed Y",cr,lf,'$'


msg4 db "You have pressed N",cr,lf,lf,'$'

msg5 db "Press only Y or N and not ",cr,lf,lf,lf,'$'



msg6 db "Please enter your four digits password",cr,lf,'$'


msg7 db  "you entered correct password",cr,lf,'$'


msg8 db  "you entered wrong password",cr,lf,'$'

msg9 db "x",'$'


.code

main proc

mov ax,@data

mov ds,ax

mov ah,02

mov dx,0808h

mov bh,00

int 10h

mov ah,9

mov dx,offset msg2

int 21h

mov ah,0

int 16h

cmp al,"Y"

jz Yes

cmp al,"N"

jz no

Yes:


mov ah,9
mov dx,offset msg3
int 21h


mov ah,4ch

int 21h

no:

mov ah,9

mov dx,offset msg4

int 21h


mov ah,4ch

int 21h

other:

mov ah,9

mov dx,offset msg5

mov ah,4ch


int 21h



mov ax,@data

mov ds,ax

mov ah,9

mov dx,offset msg6

int 21h

mov di,41h

mov cx,2

next:

mov ah,9

int 16h

stosb

mov ah,9

mov dx,offset msg9

int 21h

loop next

mov ax,offset pass

cmp ax,es:[400h]

jz correct

jmp wrong

correct:

mov ah,9

mov dx,offset msg7

int 21h

wrong:

mov dx,offset msg8

int 21h

mov ah,4ch

int 21h

main endp

end main

----------------

no syntax error
but each time i press character it proceed whether it is Y or n or any other character
can you help me please








------------------------------




FORTRANS

Hi,


mov ah,0

int 16h

cmp al,"Y"

jz Yes

cmp al,"N"

jz no

Yes:


   If you type 'N' or "Y' it matches and you jump correctly.
Anything else falls through to yes.  Add a 'JMP other' between
the 'jz no' and 'Yes:'.

Steve

dedndave

        title   my_lab4 (exp40.asm)

        .model  small
        .stack  100h

cr      equ     0dh
lf      equ     0ah

        .data

msg1    db "Welcome to the keyboard program",cr,lf,'$'
msg2    db "Would you like to proceed (Y/N)",cr,lf,'$'
msg3    db "You have pressed Y",cr,lf,lf,'$'
msg4    db "You have pressed N",cr,lf,lf,'$'
msg5    db "Press only Y or N and not  ",cr,lf,'$'
msg6    db "Please enter your four digit password",cr,lf,'$'
msg7    db "You entered the correct password",cr,lf,'$'
msg8    db "You entered the wrong password"
msg9    db cr,lf,'$'
pass    db "4067"

        .data?

buffer  db 4 dup(?)

        .code

main    proc

        mov     ax,@DATA
        mov     ds,ax
        mov     es,ax             ;added this line

        mov     dx,offset msg1    ;"Welcome to the keyboard program"
        mov     ah,9
        int     21h

     ;   mov     dx,808h          ;removed this section
     ;   mov     bh,0
     ;   mov     ah,2
     ;   int     10h

        mov     dx,offset msg2    ;"Would you like to proceed (Y/N)"
        mov     ah,9
        int     21h

keyin:
        mov     ah,0
        int     16h
        cmp     al,"Y"
        jz      Yes

        cmp     al,"y"
        jz      Yes

        cmp     al,"N"
        jz      no

        cmp     al,"n"
        jz      no

        mov     msg5+26,al        ;put the key they pressed in the string
        mov     dx,offset msg5    ;"Press only Y or N and not  "
        mov     ah,9
        int     21h
        jmp     keyin

no:
        mov     dx,offset msg4    ;"You have pressed N"
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

Yes:
        mov     dx,offset msg3    ;"You have pressed Y"
        mov     ah,9
        int     21h
        mov     dx,offset msg6    ;"Please enter your four digit password"
        mov     ah,9
        int     21h

        cld                       ;make sure the direction flag is "up"
        mov     di,offset buffer  ;was mov di,41h - yikes! - what is at ES:41h ?
        mov     cx,4              ;was mov cx,2

next:
        mov     ah,0              ;was mov ah,9
        int     16h
        stosb
        mov     dl,al
        mov     ah,2              ;ah = 2, display a single character from DL
        int     21h
        loop    next

        mov     dx,offset msg9    ;cr lf
        mov     ah,9
        int     21h

        mov     si,offset pass
        mov     di,offset buffer
        mov     cx,4
        repz    cmpsb             ;repeats 4 times, compares DS:[SI] with ES:[DI]
        jnz     wrong

correct:
        mov     dx,offset msg7    ;"You entered the correct password"
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

wrong:
        mov     dx,offset msg8    ;"You entered the wrong password"
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

main    endp

        end     main

wghh

Quote from: FORTRANS on November 28, 2009, 02:04:03 PM
Hi,


mov ah,0

int 16h

cmp al,"Y"

jz Yes

cmp al,"N"

jz no

Yes:


   If you type 'N' or "Y' it matches and you jump correctly.
Anything else falls through to yes.  Add a 'JMP other' between
the 'jz no' and 'Yes:'.

Steve



thanks steve

wghh

Quote from: dedndave on November 28, 2009, 02:24:14 PM
        title   my_lab4 (exp40.asm)

        .model  small
        .stack  100h

cr      equ     0dh
lf      equ     0ah

        .data

msg1    db "Welcome to the keyboard program",cr,lf,'$'
msg2    db "Would you like to proceed (Y/N)",cr,lf,'$'
msg3    db "You have pressed Y",cr,lf,lf,'$'
msg4    db "You have pressed N",cr,lf,lf,'$'
msg5    db "Press only Y or N and not  ",cr,lf,'$'
msg6    db "Please enter your four digit password",cr,lf,'$'
msg7    db "You entered the correct password",cr,lf,'$'
msg8    db "You entered the wrong password"
msg9    db cr,lf,'$'
pass    db "4067"

        .data?

buffer  db 4 dup(?)

        .code

main    proc

        mov     ax,@DATA
        mov     ds,ax
        mov     es,ax             ;added this line

        mov     dx,offset msg1    ;"Welcome to the keyboard program"
        mov     ah,9
        int     21h

     ;   mov     dx,808h          ;removed this section
     ;   mov     bh,0
     ;   mov     ah,2
     ;   int     10h

        mov     dx,offset msg2    ;"Would you like to proceed (Y/N)"
        mov     ah,9
        int     21h

keyin:
        mov     ah,0
        int     16h
        cmp     al,"Y"
        jz      Yes

        cmp     al,"y"
        jz      Yes

        cmp     al,"N"
        jz      no

        cmp     al,"n"
        jz      no

        mov     msg5+26,al        ;put the key they pressed in the string
        mov     dx,offset msg5    ;"Press only Y or N and not  "
        mov     ah,9
        int     21h
        jmp     keyin

no:
        mov     dx,offset msg4    ;"You have pressed N"
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

Yes:
        mov     dx,offset msg3    ;"You have pressed Y"
        mov     ah,9
        int     21h
        mov     dx,offset msg6    ;"Please enter your four digit password"
        mov     ah,9
        int     21h

        cld                       ;make sure the direction flag is "up"
        mov     di,offset buffer  ;was mov di,41h - yikes! - what is at ES:41h ?
        mov     cx,4              ;was mov cx,2

next:
        mov     ah,0              ;was mov ah,9
        int     16h
        stosb
        mov     dl,al
        mov     ah,2              ;ah = 2, display a single character from DL
        int     21h
        loop    next

        mov     dx,offset msg9    ;cr lf
        mov     ah,9
        int     21h

        mov     si,offset pass
        mov     di,offset buffer
        mov     cx,4
        repz    cmpsb             ;repeats 4 times, compares DS:[SI] with ES:[DI]
        jnz     wrong

correct:
        mov     dx,offset msg7    ;"You entered the correct password"
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

wrong:
        mov     dx,offset msg8    ;"You entered the wrong password"
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

main    endp

        end     main








thank you dedndave for your help

dedndave

do you understand the changes ?
do you see where you went wrong storing and comparing the entered password ?

dedndave

a little improvement...

        repz    cmpsb             ;repeats 4 times, compares DS:[SI] with ES:[DI]
        mov     dx,offset msg8    ;"You entered the wrong password"
        jnz     wrong

correct:
        mov     dx,offset msg7    ;"You entered the correct password"

wrong:
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

main    endp

        end     main

wghh

Quote from: dedndave on November 28, 2009, 03:00:56 PM
a little improvement...

        repz    cmpsb             ;repeats 4 times, compares DS:[SI] with ES:[DI]
        mov     dx,offset msg8    ;"You entered the wrong password"
        jnz     wrong

correct:
        mov     dx,offset msg7    ;"You entered the correct password"

wrong:
        mov     ah,9
        int     21h
        mov     ah,4ch
        int     21h

main    endp

        end     main


but how can add the line to enter my name before password

dedndave

i am not sure what you mean ?

wghh

when i open the program now
forst line appear would you like to proceed
then i want it to ask me to put my name
for example

wghh

then it asks me about my password

and thanks again for your help

dedndave

well - that would be similar to the way we entered the password
what i suggest is to create a subroutine for entry
then, use the same subroutine for both

keyboard entry is always messy
that is because their are so many keys to test for if you want to make a nice routine (enter, backspace and edit, etc)
rather than using INT 16h to get these entries, it may be better to use INT 21h function 0Ah buffered standard input
that allows the user to edit their input, without having to write a lot of code
here is a link to some previous forum discussion about INT 21h function 0Ah (including a program d/l)
http://www.masm32.com/board/index.php?topic=12435.msg95419#msg95419