问题
I just have ended my code which allow to cover your password. It goes like this(FASM):
org 100h
mov cx, 16
petla:
mov ah,08h
int 21h
cmp al,0dh
je OK
mov ah,02h
mov dl,42
int 21h
cmp cx,0
je Fail
loop petla
Fail:
mov dl, 0ah
int 21h
mov dx, pass2
mov ah,9
int 21h
jmp koniec
OK:
mov dl, 0ah
int 21h
mov dx, pass
mov ah,9
int 21h
jmp koniec
koniec:
mov ah,4ch
int 21h
pass db 'Password OK', 0Ah, 0Dh, '$'
pass2 db 'Password Fail', 0Ah, 0Dh, '$'
And now I need to print the genuine password. I know the string buffer is a must and how declaration of the buffer should look like but I don't really know how to use it and make it work. Calling for help :) Cheers.
回答1:
Since your program allows the input of 15 characters of password, you could setup the buffer with:
Buffer db 16 dup ("$")
You initialize the DI register before your petla loop and put the ASCII code you got from the DOS function in the buffer via a stosb instruction:
mov di, Buffer
mov cx, 16
petla:
mov ah,08h
int 21h
cmp al,0dh
je OK
stosb
mov ah,02h
mov dl,42
int 21h
;;;cmp cx,0
;;;je Fail
loop petla
Please note that compairing for CX=0 is useless just before the loop instruction in your code.
来源:https://stackoverflow.com/questions/33948308/string-buffer-in-assembly-code