第1个回答 2010-01-05
; 本程序在MASMPlus 1.2集成环境下通过编译,经过调试,运行正确。
Code Segment
Assume CS:Code,DS:Code
; -------------------------------------
; 功能:显示指定地址(Str_Addr)的字符串
; 入口:
; Str_Addr=字符串地址(要求在数据段)
; 用法: Output Str_Addr
; 用法举例:Output PromptStr
Output MACRO Str_Addr
push ax
lea dx,Str_Addr
mov ah,9
int 21h
pop ax
EndM
; -------------------------------------
; 功能:输出回车换行
Output_CTLF proc Near
push ax
push dx
mov ah,02h
mov dl,0dh
int 21h
mov dl,0ah
int 21h
pop dx
pop ax
ret
Output_CTLF endp
; -------------------------------------
; 功能:延时指定的时钟嘀嗒数
; 入口:
; Didas=时钟嘀嗒数(1秒钟约嘀嗒18.2次,10秒钟嘀嗒182次。若延时不是秒的10数次倍,误差稍微大点)
Delay Proc Near
push dx
push cx
push ax
xor ax,ax
int 1ah
mov cs:@@Times,dx
mov cs:@@Times[2],cx
Read_Time: xor ax,ax
int 1ah
sub dx,cs:@@Times
sbb cx,cs:@@Times[2]
cmp dx,Didas
jb Read_Time
pop ax
pop cx
pop dx
ret
@@Times dw 0,0
Delay EndP
; -------------------------------------
; 功能:键盘输入字符串
Input_String Proc Near
Output Prompt_Str ;提示输入字符串
lea dx,Buffer
@@Input_Str: mov ah,0ah
int 21h
mov cl,Buffer[1] ;取字符串长度
cmp cl,2
jb @@Input_Str ;要求输入的字符串最少2个字符,否则,重新输入字符串
xor ch,ch
mov Str_Lenth,cx ;字符串字符数
ret
Input_String EndP
; -------------------------------------
; 功能:字符显示方式下,画一个矩形框
Rectangler Proc Near
mov di,160*17+10*2
mov al,201 ;左上角字符
mov ah,9 ;LightBlue
stosw
mov al,205 ;横线符
mov cx,58
rep stosw
mov al,187 ;右上角字符
stosw
mov di,160*18+10*2
mov al,186 ;竖线符
stosw
mov Screen_Buffer,di ;矩形框左边界显示缓冲区地址
mov cx,58
mov al,20h ;空格符
rep stosw
mov Screen_Buffer[2],di ;矩形框右边界显示缓冲区地址
mov al,186 ;竖线符
stosw
mov di,160*19+10*2
mov al,200 ;左下角字符
stosw
mov al,205 ;横线符
mov cx,58
rep stosw
mov al,188 ;右下角字符
stosw
ret
Rectangler EndP
; -------------------------------------
Disp_Str Proc Near
push di
@@Disp_Str: lodsb
stosw
loop @@Disp_Str
pop di
ret
Disp_Str EndP
; -------------------------------------
; 所显示字符串在一矩形框内从无到有,从右至左移动,完全从框内移出后,又从
; 右至左移动,直到有任意键按下,停止字符串动画显示返回到主菜单。
Dynamic_Disp Proc Near
call Rectangler ;画矩形框
mov bx,Str_Lenth ;字符串长度
mov Buffer[bx][2],20h
@@Moving_0: mov di,Screen_Buffer[2]
dec di
dec di
mov cx,Str_Lenth ;字符串长度
mov bx,cx
inc bx
@@Moving_1: lea si,Buffer[2]
mov ah,14 ;字符显示属性:黄色字符
push cx
mov dx,cx
mov cx,bx
sub cx,dx
call Disp_Str ;写字符串到显示缓冲区
dec di
dec di
pop cx
call Delay ;延时
mov ah,1
int 16h
jz $+3
ret
loop @@Moving_1
mov cx,Str_Lenth ;字符串长度
inc cx
mov bx,cx
@@Moving_2: lea si,Buffer[2]
mov ah,14 ;字符显示属性:黄色字符
mov cx,bx
call Disp_Str ;写字符串到显示缓冲区
call Delay ;延时
mov ah,1
int 16h
jz $+3
ret
dec di
dec di
cmp di,Screen_Buffer
jae @@Moving_2
inc di
inc di
lea si,Buffer[3]
mov cx,Str_Lenth ;字符串长度
@@Moving_3: push cx
push si
mov ah,14 ;字符显示属性:黄色字符
call Disp_Str ;写字符串到显示缓冲区
pop si
inc si
pop cx
call Delay ;延时
mov ah,1
int 16h
jz $+3
ret
loop @@Moving_3
jmp @@Moving_0
ret
Dynamic_Disp EndP
; -------------------------------------
Didas equ 1 ;延时1个嘀嗒时间
Prompt_Menu db 4 dup(10)
db 35 dup(20h),'Main Menu',13,10
db 30 dup(20h),201,17 dup(205),187,13,10
db 30 dup(20h),186,' Input a String ',186,13,10
db 30 dup(20h),186,' Dynamic Display ',186,13,10
db 30 dup(20h),186,' Return to DOS ',186,13,10
db 30 dup(20h),200,17 dup(205),188,13,10
db 32 dup(20h),'Choice(I,D,R):$'
Cursor_Tmp dw ?
Str_Lenth dw ? ;字符串字符数
Screen_Buffer dw 2 dup(?) ;显示缓冲区左右边界地址
Prompt_Str db 13,10,10,'Please input a string:$'
Press_Key db 7,13,12 dup(10),'The complated. Press any key to exit...$'
Start: push cs
pop ds ;使数据段与代码段同段
push cs
pop es ;使附加段与代码段同段
mov ax,3 ;设置25*80字符显示方式
int 10h
Output Prompt_Menu ;显示主菜单
xor bx,bx
mov ah,3
int 10h
mov Cursor_Tmp,dx
mov ax,0b800h
mov es,ax ;设置字符显示方式缓冲区段地址
mov di,160*4+35*2+1
mov al,13 ;LightMagenta
mov cx,10
cld
Attribute: stosb
inc di
loop Attribute
mov di,160*6+32*2+1
stosb
add di,159
stosb
add di,159
stosb
mov di,160*10+39*2+1
stosb
add di,3
stosb
add di,3
stosb
Choice_Func: mov dx,Cursor_Tmp
xor bx,bx
mov ah,2
int 10h
mov ah,1
int 21h
and al,0dfh
cmp al,'R'
jz Exit_Proc
cmp al,'I'
jnz $+7
call Input_String
jmp Choice_Func
cmp al,'D'
jnz Choice_Func
call Dynamic_Disp
jmp Choice_Func
; -------------------------------------
Exit_Proc: Output Press_Key ;提示操作完成,按任意键结束程序
mov ah,1
int 21h
mov ah,4ch ;结束程序
int 21h
Buffer db 25 ;输入字符串缓冲区
Code ENDS
END Start ;编译到此结束