1
當你幫我用hlt
指令(我忘記了清除中斷cli
)後,我發現了另一個問題。比較總是清除carry flag
不管緩衝區是不是等於或不是正確的密碼,實際上密碼總是錯誤的。問題是(從osdev.org比較功能):bootsector總是比較錯誤
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
處理器暫停,但在18/18秒之後被時鐘中斷喚醒。 –
如果您確實想停止,請使用'cli'禁用中斷。你也可以在'hlt'後加一個'jmp'到'hlt'。 – Jester
我從這裏刪除了「老問題」。如果您有多個問題,請創建一個新帖子,不要背誦舊帖子,因此不是論壇,這不是它的工作原理。 –