assembly 程序集16位问题[已关闭]

hpxqektj  于 2023-01-13  发布在  其他
关注(0)|答案(1)|浏览(138)

**已关闭。**此问题需要debugging details。当前不接受答案。

编辑问题以包含desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem。这将有助于其他人回答问题。
昨天关门了。
Improve this question
我试图使一个密码检查器在tasm 16位,但它不工作。

.model small
.stack 100h

.data
    missmatch db 'Mismatch at position: ','$'
    password db 'mypassword',10,'$'   ; stored password
    prompt db 'Enter password:',0
    try_again db 'Incorrect password. ',0
    try_again2 db 'You have ',0
    try_again3 db ' tries left.','$'
    correctmsg db 'Correct password','$'
    incorrect db 'Too many incorrect attempts, exiting',0
    newline db 13,10,'$'
    input db 100 dup('$')   ; buffer to store input
    tries db 3   ; number of tries remaining
    indx db 0;
    pos db 3 dup(0)
.code

start:
    mov ax, @data
    mov ds,ax
    mov byte ptr [input],0
    mov bx,0 ;valoarea 0 este pentru tastatura
    mov cx,100 ;nr. octeti de citit
    mov dx, offset input
    mov ah, 3fh
    int 21h
    mov cx,0
    mov ah, 09h
    mov dx, offset input
    int 21h
    mov dx, offset newline
    int 21h
    mov dx, offset password
    int 21h
    mov dx, offset newline
    int 21h

    mov si, offset input   ; load the offset of the first string into si
    mov di, offset password   ; load the offset of the second string into di

    
next_char:
    mov al,[si]    ; move the value of the current character in the first string to al
    cmp al,0   ; check if the current char is a null terminator
    je correct ; if it is, we have reached the end of the first string
    mov ah,[di] ; move the value of the current character in the second string to ah
    cmp al,ah  ; compare the values of al and ah
    jne failed  ; if they are not equal, jump to the failed label
    inc si        ; move to the next character in the first string
    inc di       ; move to the next character in the second string
    inc indx
    jmp next_char; continue the loop

failed:
    dec tries
    cmp tries, 0
    jz quit
    mov ah, 09h
    mov dx, offset missmatch
    int 21h
    mov dl, indx ; move the index variable to dl
    add dl,'0'  ; convert index variable value to ascii
    mov ah,02h
    int 21h
    mov dx, offset newline
    int 21h
    ;mov dx, offset try_again
    ;int 21h
    ;mov dx, offset try_again2
    ;int 21h
   ; mov dl, [tries]
   ; mov ah, 02h
   ; int 21h
   ; mov dx, offset try_again3
    ;int 21h
    ;mov dx, offset newline
   ; int 21h
    mov indx,0 ; reset the index variable
    jmp start
correct:
    mov dx, offset correctmsg
    mov ah, 09h
    int 21h
    jmp exit
    
quit:
    mov dx, offset incorrect
    mov ah, 09h
    int 21h
    
exit:
    mov ax, 4c00h
    int 21h

end start

程序应该从键盘上读取密码,并检查是否与程序中保存的密码匹配,用户有3次尝试。有人能帮我吗?

eyh26e7m

eyh26e7m1#

您没有使用DOS.ReadDevice函数3Fh的返回值。
How buffered input works上的答案之一有一章是关于使用这个DOS函数的。

mov byte ptr [input],0
mov bx,0 ;valoarea 0 este pentru tastatura
mov cx,100 ;nr. octeti de citit
mov dx, offset input
mov ah, 3fh
int 21h
mov cx,0
  • 预加载零值没有任何意义。
  • 事后归零CX有什么用?
  • 为实现无故障运行,设置CX=129并相应定义 * 输入 *。
  • 您的密码'mypassword'有10个字符,因此检查此函数是否返回AX=12(多2个字符,因为它同时包含字节13和10)

下面的代码应该可以让你开始工作了。它还不完美,但这是你的任务,不是吗?

password  db 'mypassword'
  newline   db 13, 10, '$'
  input     db 127+2+1 dup('$')
  
  ...
  
  mov  dx, offset input
  mov  cx, 127+2
  xor  bx, bx       ; STDIN
  mov  ah, 3Fh
  int  21h          ; -> AX CF
  jc   ErrorOccured ; ????
  mov  cx, ax       ; [2,129]
  
  ...
  
  cmp  cx, 12
  jne  failed
  mov  si, offset input
  mov  di, offset password
next_char:
  mov  al, [si]
  mov  ah, [di]
  cmp  al, ah
  jne  failed
  inc  si
  inc  di
  inc  indx
  dec  cx
  jnz  next_char
correct:
  ...
failed:
  ...

相关问题