又是锻炼汇编能力的训练。发现自己在每次写汇编程序之前都不知道基本的代码模式...具体的实现倒不是很难,只是刚开始的时候由于不知道基本模式浪费了一些时间。
1.步进电机控制应用程序设计
.MODEL SMALL
.STACK
.DATA
PORT DW 0E460H
WELCOME DB 'welcome to my programme,please make choice',0DH,0AH,'$'
OP1 DB '1.clockwise',0DH,0AH,'$'
OP2 DB '2.counter-clockwise',0AH,0DH,'$'
OP3 DB '3.exit',0AH,0DH,'$'
OP DB 'input your choice:','$'
TEM DB '?'
.CODE
SHOWMENU PROC NEAR
PUSH AX
MOV DX,OFFSET WELCOME
MOV AH,09H
INT 21H
MOV DX,OFFSET OP1
INT 21H
MOV DX,OFFSET OP2
INT 21H
MOV DX,OFFSET OP3
INT 21H
MOV DX,OFFSET OP
INT 21H
POP AX
RET
SHOWMENU ENDP
DELAY PROC NEAR
PUSH DX
PUSH BX
MOV DX,0FFFH
T2:
MOV BX,5FFFH
T1:
DEC BX
JNZ T1
DEC DX
JNZ T2
POP BX
POP DX
RET
DELAY ENDP
.startup
MOV AX,@DATA
MOV DS,AX
ABC:
CALL SHOWMENU
MOV AH,01H ;input one char
INT 21H
PUSH AX
MOV AH,02H
MOV DL,0AH
INT 21H
MOV DL,0DH
INT 21H
POP AX
CMP AL,'1'
JZ OPTION1
CMP AL,'2'
JZ OPTION2
CMP AL,'3'
JZ EXIT
OPTION1:
MOV DX,PORT
MOV AL,33H
MOV CX,100
AGAIN:
OUT DX,AL
CALL DELAY
ROL AL,1
LOOP AGAIN
JMP ABC
OPTION2:
MOV DX,PORT
MOV AL,33H
MOV CX,100
AGAIN2:
OUT DX,AL
CALL DELAY
ROR AL,1
LOOP AGAIN2
JMP ABC
EXIT:
.EXIT 0
END
2.温度测量与控制应用程序设计
.model small
.stack
.data
ten db 0AH
port1 dw 0E460H
port2 dw 0E480H
heat db 0ffh
cool db 00h
wel db 'welcome to my programme',0dh,0ah,'$'
op1 db '1.heat the device',0ah,0dh,'$'
op0 db '0.exit to dos',0ah,0dh,'$'
warn db '----->>>>>>warnning:if the TEMP is over 70,it will be cut off',0ah,0dh,'$'
chioce db 'choice:','$'
.code
show proc near
push dx
push ax
mov ah,09h
mov dx,offset wel
int 21h
mov dx,offset op1
int 21h
mov dx,offset op0
int 21h
mov dx,offset warn
int 21h
mov dx,offset chioce
int 21h
pop ax
pop dx
ret
show endp
delay proc near
push dx
push bx
mov dx,5fffh
T2:
mov bx,5fffh
T1:
dec bx
jnz T1
dec dx
jnz T2
pop bx
pop dx
ret
delay endp
change proc near;interface ax
push ax
push dx
div ten
mov dh,00h
mov dl,ah
push dx
mov ah,0
div ten
mov dh,00H
mov dl,ah
push dx
pop dx
add dx,30h
mov ah,02h
int 21h
pop dx
add dx,30h
int 21h
mov dl,0ah
int 21h
mov dl,0dh
int 21h
pop dx
pop ax
ret
change endp
.startup
init:
call show
mov dx,port1
mov al,cool
out dx,al
mov ah,01h
int 21h
push ax
mov ah,02h
mov Dl,0ah
int 21h
mov Dl,0dh
int 21h
pop ax
cmp al,'1'
jnz exit
option1:
mov dx,port2
mov ax,0
out dx,al
call delay
mov dx,port1
mov al,heat
out dx,al
again:
mov dx,port2
mov ax,0
out dx,al
mov dx,port2
in al,dx
call delay
mov ah,0
call change
cmp al,70
ja init
mov ah,01h
int 16h
jnz init
jmp again
exit:
.exit 0
end