📄 send.asm
字号:
data segment
dis0 db '+-----------------------------------------------------------------------+',0dh,0ah
db '| Serial Test Send Terminal |',0dh,0ah
db '| (Enter: Send Esc:exit) |',0dh,0ah
db '+-----------------------------------------------------------------------+',0dh,0ah,'$'
dis2 db 0dh,0ah,'Do you want to continue? (y\n)',0dh,0ah,'$'
dis3 db 0dh,0ah,'Send Successfully!',0dh,0ah,'$'
dis4 db 0dh,0ah,'Please input the data which you want to send,then press Enter to send!',0dh,0ah,'-> ','$'
send_data db 100 dup(?)
data ends
code segment
assume cs:code,ds:data
;------------------------------------------------------------------------------------------
main proc far
mov ax,data
mov ds,ax
xor ax,ax
;16色文本显示方式
mov al,3
mov ah,0
int 10h
mov dx,offset dis0
call disp
;初始化串口
call initialize_serial
repeat_all:
;提示输入要发送的数据
mov dx,offset dis4
call disp
;调用输入数据程序段
call inpute_data
;调用发送数据段
call send
;显示发送成功
mov dx,offset dis3
call disp
;询问是否继续
mov dx,offset dis2
call disp
;调用选择是否继续程序段
call inpute_yesno
exit_all:
mov ax,4c00h
int 21h
main endp
;---------------------------------------------------------------------------------------
initialize_serial proc near
;通信控制寄存器D7=1
mov dx,03fbh
mov al,80h
out dx,al
;设置波特率为9600
mov dx,03f8h
mov al,0ch
out dx,al
inc dx
mov al,0
out dx,al
;初始化通信控制寄存器
mov dx,03fbh
mov al,0bh
out dx,al
;初始化modem控制器
mov dx,03fch
mov al,03h
out dx,al
;写中断允许寄存器
mov dx,03f9h
mov al,0
out dx,al
ret
initialize_serial endp
;---------------------------------------------------------------------------------------
send proc near
mov si,0
mov dx,3fdh
lea si,send_data
waitse:
mov al,[si]
;发送数据
push dx
mov dx,3f8h
out dx,al
pop dx
;以$号作为数据发送完的标志
cmp al,24h
jz send_out
in al,dx
cmp al,20h
jz waitse
inc si
jmp waitse
send_out:
ret
send endp
;---------------------------------------------------------------------------------------
inpute_data proc near
mov si,0
inpute_data_again:
mov ah,7
int 21h
cmp al,1bh
je exit_all
cmp al,0dh
je finish
push ax
mov dl,al
mov ah,2
int 21h
pop ax
mov send_data[si],al
inc si
jmp inpute_data_again
finish:
mov send_data[si],24h ;$符号
ret
inpute_data endp
;-----------------------------------------------------------------------------------
inpute_yesno proc near
inpute_yesno_again:
mov ah,7
int 21h
cmp al,79h
je yes
cmp al,6eh
je no
jmp inpute_yesno_again
yes:
jmp repeat_all
no:
jmp exit_all
ret
inpute_yesno endp
;------------------------------------------------------------------------------------------
disp proc near
mov ah,9
int 21h
ret
disp endp
;------------------------------------------------------------------------------------------
code ends
end main
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -