计算机科学与技术,汇编语言程序设计,新版,答案,钱晓捷
gtekey: mov ah,1 ;调用BIOS判断按键功能
int 16h
jz getkey ;如 zf = 0,无键按下,等待
cmp al,‘0’ ;有键按下,键值与‘0’比较
jb error ;如 < ‘0’,出错处理
cmp al, ‘9 ’ ;有键按下,键值与 ‘9’比较
ja error ;如 〉‘9’,出错处理
mov ah,02h ;调用DOS显示字符功能,显示该数字
mov dl,al
int 21h
.exit 0 ;终止程序执行,返回DOS
error: mov ah,09h ; 出错,调用DOS 功能显示str2字符串
mov dx,offset str2
int 21h
jmp getkey ;等待按键
end ; 汇编结束
3.7、将第2章习题2.37采用完整段定义格式编写成一个完整的源程序。
;xt307.asm
stack segment
dw 512 dup(?)
stack ends
data segment
array db 255
db 0
array1 db 255 dup('$')
array2 db 0dh,0ah,'$'
data ends
code segment 'code'
assume cs:code, ds:data, ss:stack
start: mov ax,data
mov ds,ax
mov ah,0ah ; 键盘输入字符串
mov dx,offset array
int 21h