I can't seem to fix this code, can anyone tell me what's wrong?

I want to enter 4 characters using the keyboard and compare it to a string. If they are equal than display a message indicating they are. If not, then display a message inidicating they are not equal and repeat. I'm using an 80186 mpu. Using MASM 6.11. I don't know whats wrong. Before this code, I used the CMPSB (compare string) instruction, and didnt work. So I used this longer code but still don't work. I ran debug and saw the data enterred into the memory but for some reason, I think, the code looks at different segments of memor or something. I don't know, please help. Here's the code:

PASSWORD PROC NEAR

PW2: SUB CX, CX
MOV CX, 0004H ;LOAD COUNTER FOR 4 CHAR
MOV DI, OFFSET PASS_TYPED
PW1: LCDCOMM 42H ;LCD MACRO
MOV AH, 07H ;GET KEYPRESSED
INT 21H
MOV [DI], AL ;MOV KEYPRESSED INTO PASS_TYPED
CALL DATWR ;PROC FOR DISPLAY ON LCD
INC DI
DEC CX
CMP CX, 0
JNE PW1
MOV CX, 0004H
MOV SI, OFFSET PASS ;CORRECT 4 DIGIT CODE
MOV DI, OFFSET PASSENT
PW3: MOV BH, [DI]
MOV BL, [SI]
INC SI
INC DI
DEC CX
CMP BH, BL
JNE WRP
JE PW3
STRINGWR WELC1, 26, 00H, 41 ;MACRO FOR LCD (CORRECT PASSW)
WRP: STRINGWR WRONG, 26, 00H, 41 ;MACRO FOR LCD (WRONG PASSW)
LCDCOMM 46H ;MACRO FOR LCD
LCDPARAM 0BH ;MACRO FOR LCD
LCDPARAM 00H ;MACRO FOR LCD
JMP PW2

RET
PASSWORD ENDP

Comments

  • : I want to enter 4 characters using the keyboard and compare it to a string. If they are equal than display a message indicating they are. If not, then display a message inidicating they are not equal and repeat. I'm using an 80186 mpu. Using MASM 6.11. I don't know whats wrong. Before this code, I used the CMPSB (compare string) instruction, and didnt work. So I used this longer code but still don't work. I ran debug and saw the data enterred into the memory but for some reason, I think, the code looks at different segments of memor or something. I don't know, please help. Here's the code:
    :
    : PASSWORD PROC NEAR
    :
    : PW2: SUB CX, CX
    : MOV CX, 0004H ;LOAD COUNTER FOR 4 CHAR
    : MOV DI, OFFSET PASS_TYPED
    : PW1: LCDCOMM 42H ;LCD MACRO
    : MOV AH, 07H ;GET KEYPRESSED
    : INT 21H
    : MOV [DI], AL ;MOV KEYPRESSED INTO PASS_TYPED
    : CALL DATWR ;PROC FOR DISPLAY ON LCD
    : INC DI
    : DEC CX
    : CMP CX, 0
    : JNE PW1
    : MOV CX, 0004H
    : MOV SI, OFFSET PASS ;CORRECT 4 DIGIT CODE
    : MOV DI, OFFSET PASSENT
    : PW3: MOV BH, [DI]
    : MOV BL, [SI]
    : INC SI
    : INC DI
    : DEC CX
    : CMP BH, BL
    : JNE WRP
    : JE PW3
    : STRINGWR WELC1, 26, 00H, 41 ;MACRO FOR LCD (CORRECT PASSW)
    : WRP: STRINGWR WRONG, 26, 00H, 41 ;MACRO FOR LCD (WRONG PASSW)
    : LCDCOMM 46H ;MACRO FOR LCD
    : LCDPARAM 0BH ;MACRO FOR LCD
    : LCDPARAM 00H ;MACRO FOR LCD
    : JMP PW2
    :
    : RET
    : PASSWORD ENDP
    :
    [code]
    [b].DATA[/b]
    strPassword Db 4
    strPassEntered Db 4

    [b].CODE[/b]
    push ds
    pop es
    cld
    mov si, offset [strPassword]
    mov di, offset [strPassEntered]
    mov cx, 4
    repe cmpsb
    je @_PASSWORD_EQUAL

    ; --- HERE PASSWORD IS NOT EQUAL...
    [/code]
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

In this Discussion