我想编写一个不断打印数字(变量)的程序,当按'+'时,数字会增加,而当按'-'时,数字会减少,但是我不希望程序停止并等待输入,我希望中断从击键开始...有任何想法吗???我试图设置“ AH = 6”和整数“ 21h”,但随后程序等待输入。我希望程序在运行时等待输入
org 100h
mov ax, 127
array db "000", 0Dh,0Ah, 24h
temp dw 10
start:
followHeater:
in ax, 125
push ax
mov bx, offset array
push bx
call my_print_num
mov dx, offset array
mov ah, 9
int 21h
in ax, 125
cmp ax, temp
mov ax, 1
jl heat:
mov ax, 0
jmp continue
heat:
mov ax, 1
continue:
out 127, ax
jmp followHeater
mov ah, 0
int 16h
ret
jmp start
proc my_print_num
push bp
mov bp, sp
pusha
mov di, 10
mov si, 2
mov cx, 3
mov ax, [bp+6]
mov bx, [bp+4]
getNum:
xor dx, dx
div di
add dl, '0'
mov [bx+si], dl
dec si
loop getNum
popa
mov sp, bp
pop bp
ret
endp my_print_num
org 100h mov ax, 127 array db "000", 0Dh,0Ah, 24h temp dw 10 start:
这里的代码搞砸了!您必须跳过数据。 (mov ax,127
指令可能不是您想要的。)>
org 100h jmp Start array db "000", 0Dh,0Ah, 24h temp dw 10 start:
我希望程序在运行时等待输入
为什么不使用BIOS键盘功能?函数01h测试密钥是否可用,并立即返回以报告ZeroFlag中存在密钥。如果有按键,您会在AX
中收到其预览,但按键仍保留在键盘缓冲区中。如果为ZF=0
,则使用功能00h实际检索密钥。这不会花很长时间,因为您知道有一个键等待着!
proc在堆栈上用2个参数调用。很好,但是您还需要从堆栈中删除它们。callee会删除以下参数:mov ah,01h ;TestKey int 16h jz NoKey mov ah,00h ;GetKey int 16h mov cx,1 cmp al,'+' je SetTemp neg cx cmp al, '-' je SetTemp ; Here you can test for more keys! NoKey: jmp followHeater SetTemp: add temp,cx jmp followHeater
您的程序中存在严重错误。 my_print_num
ret 4
endp my_print_num
或caller
会删除参数,如果您编写:call my_print_num add sp,4
您打开/关闭热量的逻辑太复杂。接下来的代码执行相同的操作:
in ax, 125 cmp ax, temp mov ax, 1 ;Heat ON jl heat dec ax ;Heat OFF heat: out 127, ax
或者,如果允许您使用比8086更好的说明。
in ax, 125 cmp ax, temp setl al ;Sets AL=1 if condition Less, else sets AL=0 cbw ;Makes AH=0 out 127, ax