DOSのアセンブラーx86を使用して、実際のアドレスモードを有効にするための詳細なプログラミングを学習しようとしています。しかし、これを実行しようとすると、ユーザーがコントロールキーの1つを押したかどうかを出力するプログラムを作成しようとします。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