Reputation: 171
i want to write a program that prints constantly a number (variable) and when '+' is pressed the number will increase and when '-' is pressed the number will decrease, but i don't want the program to stop and wait for input, i want the interruption to start on the key stroke... any ideas??? i tried to set "AH = 6" and int "21h", but then the program waits for input. i want the program to wait for the input while running
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
Upvotes: 1
Views: 616
Reputation: 9899
org 100h mov ax, 127 array db "000", 0Dh,0Ah, 24h temp dw 10 start:
The code is messed-up here! You have to jump over the data. (And the mov ax,127
instruction is probably not what you want).
org 100h
jmp Start
array db "000", 0Dh,0Ah, 24h
temp dw 10
start:
i want the program to wait for the input while running
Why not use the BIOS keyboard functions? Function 01h tests if a key is available and returns immediately reporting the presence of a key in the ZeroFlag. If a key is available you receive a preview of it in AX
but the key stays in the keyboard buffer. If ZF=0
you use function 00h to actually retrieve the key. This won't take long since you know that there is a key waiting!
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
There's a severe error in your program. The my_print_num proc is called with 2 parameters on the stack. That's fine but you need to remove these from the stack also.
The callee removes the parameters if you write:
ret 4
endp my_print_num
or the caller removes the parameters if you write:
call my_print_num
add sp,4
Your logic to turn the heat on/off is too complicated.
Next code does the same:
in ax, 125
cmp ax, temp
mov ax, 1 ;Heat ON
jl heat
dec ax ;Heat OFF
heat:
out 127, ax
Alternatively if you're allowed to use instructions that are better than 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
Upvotes: 3