出于某种原因,当我切换到鼠标输入切换回我的程序的键盘输入时,增加和减少计数器无效。它在我们输入字符的第一个循环中完美地工作。 这是程序,有什么建议吗? 在鼠标时间跳转后查看whatspeed跳转以供参考。 CX计数器没有更新或类似的东西。 (我不知道计数器是否没有更新或天气在从鼠标时间切换到关键时间后比较CX时出现问题。)
CLEAR MACRO
MOV AX,0600H
MOV BH,07
MOV CX,0000
MOV DX,184FH
INT 10H
ENDM
CURSOR MACRO Col, Row
MOV AH,02
MOV BH,00
MOV DL,Col
MOV DH,Row
INT 10H
ENDM
DISP MACRO MES
MOV AH,09
MOV DX,OFFSET MES
INT 21H
ENDM
CLEARLINE MACRO ROW
CURSOR 00,ROW
DISP SPACES
ENDM
ALWAYSONSCREENINFO MACRO
CURSOR 16,00
DISP TITLE1
CURSOR 50,00
DISP NAMES1
CURSOR 54,01
DISP NAMES2
CURSOR 33,7
DISP MENU
CURSOR 24,9
DISP OPTION1
CURSOR 24,10
DISP OPTION2
CURSOR 22,11
DISP DASHES
CURSOR 18,12
DISP MOUSEMENU
CURSOR 14,13
DISP OPTION3
CURSOR 8,14
DISP OPTION4
CURSOR 13,15
DISP CHARMENU
CURSOR 21,16
DISP KILL
ENDM
.MODEL SMALL ; RUN THE PROGRAM IN DIMENSIONS 79x24
.STACK 64H
.DATA
TITLE1 DB 'MICROPROCESSOR - EENG410','$'
NAMES1 DB 'name1 & name2','$'
NAMES2 DB 'std1 std2','$'
MENU DB 'MENU','$'
OPTION1 DB '1. Press "U" to Speed up the motor','$'
OPTION2 DB '2. Press "D" to Slow Down the motor','$'
OPTION3 DB '1. Right click the mouse to turn motor direction to clockwise','$'
OPTION4 DB '2. Left click the mouse to turn the motor direction to anti-clockwise','$'
DASHES DB '----------------------------------------','$'
MOUSEMENU DB '(Press M to switch to the mouse options)','$'
CHARMENU DB '(Press the scroll button to switch back to fist 2 options)','$'
SPEEDUP DB 'DC motor is speeding up ','$'
SLOWDOWN DB 'DC motor is slowing down','$'
RIGHT DB 'DC motor will now rotate clockwise','$'
LEFT DB 'DC motor will now rotate anti-clockwise','$'
KILL DB '-----To exit the program, press "E"-----','$'
PROGRAMEND1 DB 'Thank you for using our program','$'
PROGRAMEND2 DB 'The program has been terminated','$'
SPACES DB ' ','$'
TRY DB 'Please try again','$'
SPEEDNOW DB 'Speed:','$'
DIRECTION DB 'Motor Direction:','$'
CLOCK DB 'Right','$'
COUNTER DB 'Left ','$'
N1 DB '1','$'
N2 DB '2','$'
N3 DB '3','$'
N4 DB '4','$'
N5 DB '5','$'
N6 DB '6','$'
N7 DB '7','$'
MAXSPEED DB 'Max speed is 7','$'
MINSPEED DB 'Min speed is 1','$'
.CODE
MAIN: MOV AX,@DATA
MOV DS, AX
CLEAR
ALWAYSONSCREENINFO
MOV CX,1
CURSOR 28,21
DISP SPEEDNOW
CURSOR 35,21
DISP N1
CURSOR 22,22
DISP DIRECTION
CURSOR 39,22
DISP CLOCK
MOV CX,1
L0: MOV AH,00 ;LOOP START
INT 16H
CMP AL,' '
JE SPACED
CMP AL,'U'
JE FASTER
CMP AL,'u'
JE FASTER
CMP AL,'D'
JE SLOWER
CMP AL,'d'
JE SLOWER
CMP AL,'M'
JE MOUSETIME
CMP AL,'m'
JE MOUSETIME
CMP AL,'E'
JE EXIT
CMP AL,'e'
JE EXIT
JNE TRYAGAINKEY
A1: MOV AX,03
INT 33H
CMP BX,0
JE A1
CMP BX,1 ;MOUSE LEFT
JE MRIGHT
CMP BX,2 ;MOUSE RIGHT
JE MLEFT
CMP BX,3
JE KEYTIME
SPACED: CLEARLINE 19
JMP L0
FASTER: CLEARLINE 19
CURSOR 27,19
DISP SPEEDUP
JMP INCREASE
SLOWER: CLEARLINE 19
CURSOR 27,19
DISP SLOWDOWN
JMP DECREASE
MOUSETIME: JMP A1
KEYTIME: JMP L0
MRIGHT: CLEARLINE 19
CURSOR 18,19
DISP RIGHT
JMP TRIGHT
MLEFT: CLEARLINE 19
CURSOR 18,19
DISP LEFT
JMP TLEFT
TRYAGAINKEY: CLEARLINE 19
CURSOR 28,19
DISP TRY
JMP L0
INCREASE: CMP CX,7
JE CANNOTINCREASESPEED
INC CX
JMP WHATSPEED
DECREASE: CMP CX,1
JE CANNOTDECREASESPEED
DEC CX
JMP WHATSPEED
TRIGHT: CURSOR 39,22
DISP CLOCK
JMP A1
TLEFT: CURSOR 39,22
DISP COUNTER
JMP A1
CANNOTINCREASESPEED: CLEARLINE 19
CURSOR 27,19
DISP MAXSPEED
JMP L0
CANNOTDECREASESPEED: CLEARLINE 19
CURSOR 27,19
DISP MINSPEED
JMP L0
WHATSPEED: CMP CX,1
JE N11
CMP CX,2
JE N22
CMP CX,3
JE N33
CMP CX,4
JE N44
CMP CX,5
JE N55
CMP CX,6
JE N66
CMP CX,7
JE N77
N11: CURSOR 35,21
DISP N1
JMP L0
N22: CURSOR 35,21
DISP N2
JMP L0
N33: CURSOR 35,21
DISP N3
JMP L0
N44: CURSOR 35,21
DISP N4
JMP L0
N55: CURSOR 35,21
DISP N5
JMP L0
N66: CURSOR 35,21
DISP N6
JMP L0
N77: CURSOR 35,21
DISP N7
JMP L0
EXIT: CLEAR
CURSOR 21,12
DISP PROGRAMEND1
CURSOR 21,13
DISP PROGRAMEND2
MOV AH, 4CH
INT 21H
END MAIN
答案 0 :(得分:0)
导致故障的原因是鼠标中断33h
功能AX=0003h
返回CX
和DX
中的鼠标位置。
这会覆盖你的"计数器"在注册CX
。
在整个程序中将值保存在寄存器中总是一个危险的游戏。最好有一个内存变量位置。
您可以在执行鼠标功能之前尝试PUSH CX
,然后尝试POP CX
,但您的程序结构和流程可能不利于此(我没有完全遵循它)。
此外,您的程序无法从(在您的上下文中)恢复CX
的荒谬值的原因是因为您使用的测试指令。例如这里
INCREASE: CMP CX,7
JE CANNOTINCREASESPEED
你必须始终保持谨慎,并且任何超出范围的值(即使你认为它不会成功)
JGE CANNOTINCREASESPEED
还有
CANNOTINCREASESPEED: MOV CX,7 ;clamp the value
...