我只是汇编语言编程的初学者。我们的第一个任务是让程序仅在输入为 ESC 时退出。退出之前请求确认 (y/n),否则循环。我知道 ESC 在 ASCII 代码中具有等效值,但我对插入位置或是否需要添加更多内容感到困惑。请帮我!
这是程序:
.model small
.stack 100h
.data
msg1 db " <-- Non alpha!$"
msg2 db "Bye!$"
.code
start:
; display ?
mov dl, "?" ; copy ? to dl
mov ah, 2h ; display subprogram
int 21h ; display ?
mov dl, " " ; Provide space
mov ah, 2h ; display subprogram
int 21h
; read character from keyboard
mov ah, 1h ; keyboard input subprogram
int 21h ; read character into al
; save character while we display a Return and Line-feed
cmp al,65d ; 'A'
jb Non_alpha
cmp al,90d ; 'Z'
ja above_alpha_upper
mov bl, al ; save character in bl
add bl,32d ; ADD 32 decimal
mov dl, bl ; copy character to dl
mov ah, 2h ; display subprogram
int 21h ; display character in dl
jmp x
Non_alpha:
mov ax, @data
mov ds,ax
mov dx,offset msg1
mov ah,9h
int 21h
jmp x ; je,ja, jb
above_alpha_upper:
cmp al,97d ; 'a'
jb Non_alpha
cmp al,122d ; 'z'
ja Non_alpha
mov bl, al ; save character in bl
sub bl,32d ; SUBTRACT 32 decimal
mov dl, bl ; copy character to dl
mov ah, 2h ; display subprogram
int 21h ; display character in dl
x: ; exit
mov dl, 13d ; dl = CR, Dh
mov ah, 2h ; display subprogram
int 21h ; display CR
; display Line-feed
mov dl, 10d ; dl = LF , Ah
mov ah, 2h ; display subprogram
int 21h ; display LF
; display character read from keyboard
mov ax, @data
mov ds,ax
mov dx, offset msg2 ; Bye
mov ah,9h
int 21h
mov ax, 4c00h ; return to ms-dos
int 21h
end start