【发布时间】:2015-10-04 12:24:25
【问题描述】:
在你帮我完成了hlt 指令之后(我忘记了清除中断cli),我发现了另一个问题。比较总是清除carry flag 无论缓冲区是否等于正确密码,实际上密码总是错误的。问题在于(比较来自osdev.org的函数):
org 0x7c00
bits 16
cld
mov bl,0x0F
mov si, MSGPassword
mov dh,0xA
mov dl,0x2
call printf
call password
mov si, buffer
mov di, VARpassword
call cmpstr
;jc right
;jnc error
hlt
hlt
right:
mov si,MSGRight
mov bl,0x03
call printf
hlt
error:
mov si,MSGWrong
mov bl,0x04
call printf
hlt
;definitions
;al - letter to write
;bl - color
;write char at cursor location, then moves its to next column
write:
mov ah,0x9
xor bh,bh
mov cx,0x1
int 0x10
mov ah,0x3
int 0x10
mov ah,0x2
inc dl
int 0x10
ret
;al - letter to write
;bl - color
; same as write, but dont go to next column
writen:
mov ah,0x9
xor bh,bh
mov cx,0x1
int 0x10
ret
;si - message
;bl - colour
;dh - row
;dl - column
;print string
printf:
mov ah,0x2
int 0x10
.loop:
lodsb
or al,al
jz .end
call write
jmp .loop
.end:
ret
;get password, with write * on screen
;no args
;password is written to buffer
password:
xor cl,cl
mov si, buffer
.loop:
xor ah,ah
int 0x16
cmp al, 0x08
je .backspace
cmp al,0x0D
je .done
cmp cl, 0x3F
je .loop
stosb
inc cl
mov al,'*'
mov bl,0x0F
call write
jmp .loop
.backspace:
cmp cl,0x0
je .loop
dec di
mov byte [di], 0
dec cl
pusha
mov ah,0x3
int 0x10
dec dl
mov ah,0x2
int 0x10
popa
mov al,' '
mov bl,0x0F
call writen
jmp .loop
.done:
mov al,0
stosb
ret
;compare string
; di, si - strings to compare
cmpstr:
.loop:
mov al,[si]
mov bl,[di]
cmp al,bl
jne .notequal
cmp al,0x0
je .equal
inc di
inc si
jmp .loop
.notequal:
clc
ret
.equal:
stc
ret
MSGRight db "Right password", 0x0
MSGWrong db "Wrong password", 0x0
MSGPassword db "Password:",0x0
buffer:
times 64 db 0x0
VARpassword db "test", 0x0 ;right password
times 0x1FE - ($-$$) db 0x0
db 0x55
db 0xAA
【问题讨论】:
-
处理器停止,但在 1/18 秒后被时钟中断唤醒。
-
如果您真的想停止,请使用
cli禁用中断。您也可以在hlt之后将jmp添加回hlt。 -
我从中删除了“旧问题”。如果您有多个问题,请创建一个新帖子,不要背负旧帖子,因此不是论坛,它不是这样运作的。
-
另外,这些 cmets 应该是答案,因此他们可以被投票并相应地接受。
-
输入密码时会不会是 capslock 处于活动状态?
标签: assembly x86 nasm bootloader real-mode