|
发表于 2012-5-25 10:48:57
|
显示全部楼层
assume cs:code,ds:data,ss:stack
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;函数功能:将输入的大写字母转换为小写
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
data segment
dwStrMaxLen dw 0
dwStrLen dw 0
szHintLen db 'Please input the max length of words:',0dh,0ah,'$'
szHintText db 'Please input the content:',0dh,0ah,'$'
szHintChange db 'Text changed is:',0dh,0ah,'$'
szInputBuf db 128 dup (?)
szOutBuf db 128 dup (?)
data ends
stack segment
db 32 dup (0)
stack ends
code segment
start: mov ax,data
mov ds,ax
mov ax,stack
mov ss,ax
mov sp,20h
call ShowHintLen
call InputHintLen
call ShowHintText
call InputHintText
call TextChange
call ShowHintChange
call ShowText
jmp Stop
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;显示提示字符(输入最大长度)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ShowHintLen:
mov ah,9
mov dx,offset szHintLen
int 21h
ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;处理输入最大长度,ds:dwStrMaxLen保存结果,最大128
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
InputHintLen:
push bx
push cx
push dx
push es
push si
xor bx,bx
xor dx,dx
mov ax,0b800h ;设定显示的初始位置
mov es,ax
mov si,160*4
Input1: mov ah,0
int 16h
cmp al,0dh ;回车结束输入
je Back1
cmp al,30h
jb Back1
cmp al,39h ;判断是否为数字0-9
ja Back1
push ax
mov ax,ds:dwStrMaxLen
mov bl,10
mul bl ;获取已经输入的数据,*10
pop bx
and bx,00ffh
or bx,2c00h
mov es:[si],bx
add si,2 ;显示输入的字符
and bx,000fh ;获得新输入的数据
add ax,bx
mov ds:dwStrMaxLen,ax
jmp Input1
Back1: pop si
pop es
pop dx
pop cx
pop bx
cmp ds:dwStrMaxLen,128 ;设置最大输入长度
jb Back1_Ret
mov ds:dwStrMaxLen,128
Back1_Ret: ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;显示提示字符(输入字符)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ShowHintText:
mov ah,9
mov dx,offset szHintText
int 21h
ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;处理输入字符,ds:szInPutBuf保存结果,最大128,回车结束
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
InputHintText:
push bx
push cx
push dx
push es
push si
xor bx,bx
xor dx,dx
mov ax,0b800h ;设定显示的初始位置
mov es,ax
mov si,160*5
mov cx,ds:dwStrLen
Input2: mov ah,0
int 16h
cmp al,0dh ;回车结束输入
je Back2
mov ds:szInputBuf[bx],al
inc bx
and ax,00ffh
or ah,2ch
mov es:[si],ax
add si,2 ;显示输入的字符
mov ax,ds:dwStrLen
inc ax
mov ds:dwStrLen,ax ;保存输入字符的长度
loop Input2
Back2: pop si
pop es
pop dx
pop cx
pop bx
ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;处理输入字符的转换,ds:szOutBuf保存结果
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
TextChange:
push bx
push cx
push dx
push es
push si
xor bx,bx
xor dx,dx
mov cx,ds:dwStrLen
Change: mov al,ds:szInputBuf[bx]
cmp al,'A'
jb Next1
cmp al,'Z'
ja Next1
or al,20h
Next1: mov ds:szOutBuf[bx],al
inc bx
loop Change
Back3: pop si
pop es
pop dx
pop cx
pop bx
ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;显示提示字符(字符转换)
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
ShowHintChange:
mov ah,9
mov dx,offset szHintChange
int 21h
ret
ShowText:
push bx
push cx
push dx
push es
push si
xor bx,bx
xor dx,dx
mov ax,0b800h
mov es,ax
mov si,160*6
mov cx,ds:dwStrLen
Show: mov al,ds:szOutBuf[bx]
mov ah,2ch ;设定颜色
mov es:[si],ax
add si,2
inc bx
loop Show
Back4: pop si
pop es
pop dx
pop cx
pop bx
ret
Stop:
mov ax,4c00h
int 21h
code ends
end start |
|