我正在尝试通过 DOS 中的汇编程序 x86 学习一些深度编程,因为它启用了真实地址模式。但是在我尝试这样做时,我试图制作一个程序来打印用户是否按下了其中一个控制键;CTRL、CAPS LOCK 或 SCROLL LOCK,但问题是程序不打印出来。感觉好像缺乏某种基础知识,所以我问这里是否有人知道我的程序有什么问题。如果我按 q (如退出),它不会写出任何内容但能够关闭?..谢谢
;reads the key and prints out whether a control key has been entered
; (CTRL, CAPS LOCK or SCROLL LOCK)
[BITS 16]
SEGMENT data
ctrlmsg db 'ctrl has been pressed', '$'
capslockmsg db 'caps lock has been pressed', '$'
scrollmsg db 'scroll lock has been pressed', '$'
SEGMENT code
..start:
mov ax, pile
mov ss, ax
mov ax, topofstack
mov sp, ax
mov ax, data
mov ds, ax
mov ax, ctrlmsg
WAITER:
mov ah, 00h
int 16h
cmp al, 71h ; user pressed q, and wants to end program
je END
mov ah, 02h ; wait until user press keyboard and return keyboard flag in AL
int 16h
add al, 71h ; add 71h back to al, so it goes unchanged in other comparisons
cmp al, 02h ; if key board flag is 02h then I expect user to have pressed CTRL
je CTRL ; then jump to CTRL label, in the same way it goes...
add al, 02h
cmp al, 04h
je SCROLLOCK
add al, 04h
cmp al, 06h
je CAPSLOCK
jmp WAITER
END:
mov ax, 04c00h ; ends program
int 21h
WRITESTRING:
mov ah, 13h ; 13h of int 10 is print string
mov al, 00h ; write mode 0 (no attributes)
mov bh, 0h ; video page number
mov bl, 07h ; foreground color
mov cx, 05h ; string length
mov dh, 25 ; row
mov dl, 80 ; col
int 10h
ret
CTRL: ; the other labels CAPS LOCK and SCROLL LOCK are quite similar why I haven't included them in the codesnippet
push ds ; save ds for subroutine
pop es ; pop it in es
push bp
move bp, ctrlmsg ; base pointer point to string
call WRITESTRING
pop bs
jmp waiter ; loop