实验九 子程序设计1 (2学时)
【实验目的】
1 .掌握程序设计方法,合理划分层次 2 .掌握子程序的调用与返回的方法 3 .了解子程序的嵌套与递归
【实验内容】
1、从键盘输入数据并显示 (1)从键盘输入字符 (2)删除指定的字符
(3)将剩余字符在屏幕上显示 参考程序: data segment
buffer db 80 dup(?) flag db ? data ends code segment main proc far
assume cs:code,ds:data
start: push ds
xor ax,ax push ax
mov ax,data mov ds,ax
mov bx,offset buffer mov flag,0
next: mov ah,01h int 21h
test flag,01h jnz follow cmp al,20h jnz exit mov flag,1 jmp next
follow: cmp al,20h
jz exit
mov [bx],al inc bx jmp next
exit: mov [bx],al mov di,offset buffer mov al,'5'
45
call del
mov si,offset buffer call disp ret main endp
del proc near
cld
loop1: mov ah,[di]
cmp ah,20h jz exit0 cmp al,[di] jz loop2 inc di jmp loop1
loop2: mov al,[di+1]
mov [di],al cmp al,20h jz exit0 inc di jmp loop2 exit0: ret del endp
disp proc near
disp0: mov dl,[si]
mov ah,02h int 21h inc si
mov al,[si] cmp al,20h jnz disp0 ret
disp endp code ends
end start
46