assembly 更改以使用户输入不回显到屏幕

rsaldnfx  于 2023-03-30  发布在  其他
关注(0)|答案(1)|浏览(81)
.MODEL SMALL
.STACK 100H
.DATA
    MSG DB 'Enter password: $'
    DISPLAY_MSG DB 0dh, 0ah, 'NAME: display name', 0dh, 0ah, 'ID NUMBER: display number', '$'
    ERROR_MSG DB 'Password does not match.!$'
    PASSWORD DB '123'
    BUFFER DB 4
.CODE
    MAIN PROC
        MOV AX, @DATA
        MOV DS, AX
        LEA DX, MSG
        MOV AH, 9
        INT 21H ; print prompt message
        
        MOV AH, 0AH
        LEA DX, BUFFER
        INT 21H ; read input from user

        
        MOV SI, OFFSET BUFFER+2 ; skip first byte (input length)
        MOV DI, OFFSET PASSWORD
        MOV CX, 3 ; compare up to 6 characters
    CMP_LOOP:
        LODSB ; load byte from SI into AL, increment SI
        CMP AL, [DI] ; compare with password character
        JNE CMP_FAIL ; jump to failure if not equal
        INC DI ; move to next password character
        LOOP CMP_LOOP ; repeat until CX is zero
        JMP SUCCESS
    CMP_FAIL:
        ; passwords don't match, print error message
        LEA DX, ERROR_MSG
        MOV AH, 9
        INT 21H
    SUCCESS:
        ; passwords match, print success message
        LEA DX, DISPLAY_MSG
        MOV AH, 9
        INT 21H
        
        MOV AH, 4CH
        INT 21H ; return to DOS
    MAIN ENDP
    END MAIN

我如何改变它,使用户输入不显示。我尝试使用int 21h ah=08h,但我似乎不能使它工作。
我尝试使用int 16h ah=00h,也尝试使用int 21h ah=08h创建一个循环。它可以工作,但用户输入没有存储在声明的密码db中。

rks48beu

rks48beu1#

声明od BUFFER DB 4是不够的,请参阅BUFFERED INPUT,它应该类似于
BUFFER DB 4,0,'XXXX'。但是,如果您不想显示输入的字符,请使用DOS函数CHARACTER INPUT WITHOUT ECHO。在这种情况下,您不必将输入数据存储到内存中,只需将每个获得的字符与PASSWORD模板进行比较。
代替

MOV AH, 0AH
  MOV DX, BUFFER
  INT 21H ; read input from user

试试这个:

LEA SI,[PASSWORD]
       MOV CX,3       ; Size of the PASSWORD.
       MOV AH,8       ; Input one character to AL without echo.
CMP_LOOP:       
       INT 21H        ; Get one character from keyboard.
       CMP AL,[SI]    ; Does it match the template?
       JNE CMP_FAIL
       INC SI         ; Compare the next character.
       LOOP CMP_LOOP:
SUCCESS:              ; passwords match, print success message
        MOV DX, DISPLAY_MSG
        MOV AH, 9
        INT 21H
        MOV AX, 4C00H ; Terminate with errorlevel 0.
        INT 21H       ; return to DOS
CMP_FAIL:             ; passwords don't match, print error message
        MOV DX, ERROR_MSG
        MOV AH, 9
        INT 21H
        MOV AX, 4C08H ; Terminate with errorlevel 8.
        INT 21H       ; return to DOS

相关问题