X,319H ;端口BР IN AL,DX ;读开关状态Р AND AL,03H ;保留B1,B0位,其他位置0Р MOV X,AL ;将AL暂时装入XР MOV CX,02HР B: MOV DL,AL ;AL装入DL以备子程序使用Р CALL DISP ;调用显示子程序,显示PB2的状态Р SHL AL,1Р LOOP B ;循环2次,显示2个开关状态Р MOV AL,X ;开关状态装入AL Р CMP AL,00H ;比较开关状态,00调用STATE0Р JNZ MР CALL STATE0 Р M: CMP AL,01H ;比较开关状态,01调用STATE1Р JNZ NР CALL STATE1Р N: CMP AL,02H ;比较开关状态,10调用 STATE2Р JNZ OР CALL STATE2Р O: CMP AL,03H ;比较开关状态,11调用STATE3Р JNZ MР CALL STATE3РSTATE0 PROC NEAR ;前四灯同时亮,熄灭后,接着后四个同时亮Р MOV AH,09H Р MOV DX,OFFSET ZEROР INT 21HР MOV DX,318H Р MOV CX,04H ;端口AР H: MOV AL,0FHР OUT DX,ALР CALL DELAY10Р MOV AL,0F0HР OUT DX,ALР CALL DELAY10 Р LOOP H Р JMP SР RETРSTATE0 ENDPРSTATE1 PROC NEAR ;8灯依次点亮Р MOV AH,09H Р MOV DX,OFFSET ONEР INT 21HР MOV DX,318H ;端口AР MOV CX,08HР D: MOV AL,80HР NOT ALР ROR AL,1Р OUT DX,ALР CALL DELAY10Р LOOP D