程序集登录程序总是返回“true”

时间:2017-08-15 11:52:49

标签: assembly

我正在处理我的演示文稿,并且我遇到了这个代码,这对我的演示文稿来说是很好的补充。问题是如果我输入“Hello123”(例如),程序假定“Hello123”和“Hello”匹配。

此代码来自here。由于我的低代表,我无法评论他的代码。我做过研究,并试图自己做,但我不能解决问题。如果有人能帮助我,我将非常感激。

.model small
.stack 100h
.data
    a db "Hello$"
    login db "Please Log in: $"
    lg db 21          ;<=== MAXIMUM NUMBER OF CHARS ALLOWED (20).
       db ?           ;<=== NUMBER OF CHARS THAT USER ENTERED (?).
       db 21 dup(0)   ;<=== ARRAY OF CHARS (FINISH WITH 0DH=13).
    helloMsg db 0dh, 0ah, "Hello Message$"

.code
main proc
mov ax, @data
mov ds, ax

mov ah, 09h
lea dx, login
int 21h

mov ah, 0ah
MOV DX, OFFSET lg     ;<=== TELL INT 21H TO STORE CAPTURED STRING HERE.
int 21h

MOV SI, OFFSET LG + 2 ;<=== POINT TO THE ARRAY OF CHARS.
MOV DI, OFFSET A      ;<=== POINT TO THE USER.
ck: 
;CHECK END OF USER.  
MOV DH, [DI]
CMP DH, '$'
JE  hi                ;<=== END REACHED. ALL CHARS MATCH.

;CHECK END OF INPUT.  
MOV DL, [SI]          ;<=== CURRENT ENTERED CHAR.
CMP DL, 13
JE  bye               ;<=== END REACHED. INPUT IS SHORTER.

;COMPARE CURRENT ENTERED CHAR TO CURRENT USER CHAR.  
CMP DL, DH
jne bye               ;<=== CURRENT CHARS ARE DIFFERENT.
INC SI                ;<== NEXT ENTERED CHAR.
INC DI                ;<== NEXT USER CHAR.
JMP CK                ;<== REPEAT.

hi:
mov ah, 09h
lea dx, helloMsg
int 21h

bye:
mov ah, 4ch
int 21h

main endp
 end main

1 个答案:

答案 0 :(得分:0)

这么多时间都不知道只有一行代码才能结束。

cmp byte ptr lg + 1, 5 

在ck之前添加:

ck: 
;CHECK END OF USER.  
MOV DH, [DI]
CMP DH, '$'
JE  hi                ;<=== END REACHED. ALL CHARS MATCH.