Demo entry 6781011

ee

   

Submitted by anonymous on Dec 31, 2018 at 06:42
Language: NASM. Code size: 4.9 kB.

SSEG SEGMENT STACK
	DW 200 DUP(?)
SSEG ENDS 
DATA SEGMENT
        MESG2    DB 'Please input the direction and the number of the elevator ',0ah,0dh
         DB 'as dir ("UP"or"DOWN") + num (0--9)',0ah,0dh
         DB 'Exit with Esc',0ah,0dh,'$'
	NOW_FLOOR 		DB(1)				;电梯现在楼层
	NEXT_FLOOR 		DB(1)				;电梯目标楼层
	STATE 			DB(0)				;电梯运行的状态 0表示暂停 1表示向上 2表示向下
	TIMECOUNT		DB(0)				;时钟计数
	SIGN				DB(1)
	UP         	 DB 18H,0CH,06H,0FFH,0FFH,06H,0CH,18H
	DOWN  		 DB 18H,30H,60H,0FFH,0FFH,60H,30H,18H
	STOP     	 DB 00H,18H,18H,18H,18H,18H,18H,00H
	SEVLED 		 DB 40H,79H,24H,30H,19H,12H,02H,78H,00H,10H
	SIGN_BUF  DB(0)
	UP_BUF 	  DB 10 DUP(0)
	DOWN_BUF  DB 10 DUP(0)
	MESG1 DB 'THE NUMBER IS ERROR',0DH,0AH,'$'
	INTOA_OFF DW(?)
	INTOA_SEG DW(?)
DATA ENDS

CODE SEGMENT
	ASSUME CS:CODE,DS:DATA
START:
	MOV DX,DATA
	MOV DS,DX
	MOV DX,SSEG
	MOV SS,DX
   MOV AH,09H
   MOV DX,OFFSET MESG2
   INT 21H   ;显示提示信息   

	;初始化8255
	MOV DX,303H
	MOV AL,10000000B
	OUT DX,AL
	MOV DX,300H
	MOV AL,00H
	OUT DX,AL
	MOV DX,301H
	MOV AL,00H
	OUT DX,AL
	MOV DX,302H
	MOV AL,0FFH
	OUT DX,AL

	;中断的设置
	MOV AX,3572H
	INT 21H
	MOV INTOA_OFF,BX
	MOV BX,ES
	MOV INTOA_SEG,BX
	CLI
	MOV AX,2572H
	MOV DX,SEG LEDLIGHT
	PUSH DS
	MOV DS,DX
	MOV DX,OFFSET LEDLIGHT
	INT 21H
	POP DS
	STI

	;打开IRQ10和IRQ2
	IN AL,0A1H
	AND AL,0FBH
	OUT 0A1H,AL
	IN AL,21H
	AND AL,0FBH
	OUT 21H,AL
	
	;8253初始化产生1S的计时
	MOV DX,307H
	MOV AL,00110110B
	OUT DX,AL
	MOV DX,304H
	MOV AL,0E8H
	OUT DX,AL
	MOV AL,03H
	OUT DX,AL
	MOV DX,307H
	MOV AL,01110110B
	OUT DX,AL
	MOV DX,305H
	MOV AL,0E8H
	OUT DX,AL
	MOV AL,03H
	OUT DX,AL

INPUT:
	CALL FAR PTR MATRIX_SHOW
	CALL FAR PTR DIGITRON_SHOW 

	MOV AH,0BH
	INT 21H
	CMP AL,00H
	JZ INPUT

	MOV AH,00H
	INT 16H
	CMP AL,0DH
	JZ NEXT0						;若没有输入为回车,进入运行状态

	CMP AL,1BH
	JNZ NEXT					;若输入ESC则退出程序
	JMP EXIT

NEXT:	
	CMP AH,48H
	JZ M_UP
	CMP AH,50H
	JZ M_DOWN
	JMP INPUTERROR	

M_UP:
	MOV AH,01H
	INT 21H
	CMP AL,'0'
	JB INPUTERROR
	CMP AL,'9'
	JA INPUTERROR
	SUB AL,30H
	MOV AH,00H
	MOV SI,AX
	MOV UP_BUF[SI],01H
	JMP INPUT

M_DOWN:
	MOV AH,01H
	INT 21H
	CMP AL,'0'
	JB INPUTERROR
	CMP AL,'9'
	JA INPUTERROR
	SUB AL,30H
	MOV AH,00H
	MOV SI,AX
	MOV AX,0009H
	SUB AX,SI
	MOV SI,AX
	MOV DOWN_BUF[SI],01H
	JMP INPUT

NEXT0:
	CALL FAR PTR MATRIX_SHOW
	CALL FAR PTR DIGITRON_SHOW
	CMP SIGN_BUF,14H
	JZ REPEAT
	CMP TIMECOUNT,02H
	JBE NEXT0
	MOV TIMECOUNT,00H
	CALL FAR PTR RUN
	JMP NEXT0
REPEAT:
	MOV SIGN_BUF,00H
	MOV AL,NEXT_FLOOR
	MOV NOW_FLOOR,AL
	MOV STATE,00H
	JMP INPUT

INPUTERROR:
	MOV AH,09H
	MOV DX,OFFSET MESG1
	INT 21H
	JMP INPUT

EXIT:
	MOV AX,2572H
	MOV DX,INTOA_SEG
	PUSH DS
	MOV DS,DX
	MOV DX,INTOA_OFF
	INT 21H
	POP DS
	IN AL,0A1H
	OR AL,04H
	OUT 0A1H,AL
	IN AL,21H
	OR AL,04H
	OUT 21H,AL
	MOV AH,4CH
	INT 21H

;电梯状态与运行程序
RUN PROC FAR
	PUSH AX
	PUSH BX
	PUSH SI
	
	MOV AL,NEXT_FLOOR
	CMP AL,NOW_FLOOR
	JA RUP
	CMP AL,NOW_FLOOR
	JB RDOWN
	
	MOV AL,SIGN
	MOV STATE,AL
	MOV AH,00H
	MOV BX,OFFSET UP_BUF
R0:
	MOV AL,SIGN_BUF
	MOV SI,AX
	CMP BYTE PTR[BX+SI],01H
	JZ R1
	INC SIGN_BUF
	CMP SIGN_BUF,14H
	JNZ R0
	JMP RBACK
R1:
	MOV BYTE PTR[BX+SI],00H
	CMP SIGN_BUF,09H
	JA R2
	MOV AL,SIGN_BUF
	MOV NEXT_FLOOR,AL
	JMP RBACK

R2:
	MOV STATE,02H
	MOV AL,SIGN_BUF
	SUB AL,0AH
	MOV AH,09H
	SUB AH,AL
	MOV NEXT_FLOOR,AH
	JMP RBACK
	
RUP:
	ADD NOW_FLOOR,01H
	MOV STATE,01H
	MOV SIGN,01H
	MOV AL,NOW_FLOOR
	CMP AL,NEXT_FLOOR
	JZ R3
	JMP RBACK

RDOWN:
	SUB NOW_FLOOR,01H
	MOV STATE,02H
	MOV SIGN,02H
	MOV AL,NOW_FLOOR
	CMP AL,NEXT_FLOOR
	JZ R3
	JMP RBACK

R3:
	MOV STATE,00H
	JMP RBACK

RBACK:
	POP SI
	POP BX
	POP AX
	RET
RUN ENDP

;点阵显示程序
MATRIX_SHOW PROC FAR
	PUSH AX
	PUSH BX
	PUSH CX
	PUSH DX
	PUSH SI	

	CMP STATE,00H
	JZ MSTOP
	CMP STATE,02H
	JZ MDOWN
	MOV BX,OFFSET UP
	MOV CL,00001000B
	JMP MRUN
MSTOP:
	MOV BX,OFFSET STOP
	MOV CL,00010000B
	JMP MRUN
MDOWN:
	MOV BX,OFFSET DOWN
	MOV CL,00001000B

MRUN:
	MOV SI,0000H
MLP:
	MOV DX,300H
	MOV AL,[BX+SI]
	OUT DX,AL
	MOV DX,301H
	MOV AL,CL
	OUT DX,AL
	INC SI
	INC CL
	CALL FAR PTR DELAY
	CMP SI,0008H
	JNZ MLP

	POP SI
	POP DX
	POP CX
	POP BX
	POP AX
	RET
MATRIX_SHOW ENDP

;7数码管显示程序
DIGITRON_SHOW PROC FAR
	PUSH AX
	PUSH DX
	PUSH SI

	MOV DX,302H
	MOV AH,0000H
	MOV AL,NOW_FLOOR
	MOV SI,AX
	MOV AL,SEVLED[SI]
	OUT DX,AL

	POP SI
	POP DX
	POP AX
	RET 
ENDP

;延迟程序
DELAY PROC FAR
	PUSH CX
	PUSH BX
	MOV BX,0FFH
DLP2:
	MOV CX,0FFFH
DLP1:
	LOOP DLP1
	DEC BX
	JNZ DLP2
	POP BX
	POP CX
	RET
DELAY ENDP

;中断服务程序
LEDLIGHT PROC FAR
	PUSH AX
	PUSH DX
	CLI

	ADD TIMECOUNT,01H

IBACK:
	;发出EOI命令
	MOV AL,62H
	MOV DX,0A0H
	OUT DX,AL
	OUT 020H,AL
	STI

	POP DX
	POP AX
	IRET
LEDLIGHT ENDP

CODE ENDS
	END START

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).