?? long3.asm
字號:
;輸入一個字符串,長度小于80,統計其字母,數字與其它字符的個數
.386
;* 數據段
;******************************************************
dseg segment use16
;------------------------------------------------------
;MY OWN DATA
be db 'please input your string: ','$'
data db 80,?,80 dup(?)
output db 'The string has',0dh,0ah
num db 0,20h,20h
db 'numbers' ,0dh,0ah
char db 0,20h,20h
db 'letters',0dh,0ah
other db 0,20h,20h
db 'other characters','$'
d db 5 dup(?)
;------------------------------------------------------
dseg ends
;******************************************************
;* 代碼段
;******************************************************
cseg segment use16
;------------------------------------------------------
assume ds:dseg,cs:cseg
start: mov ax,dseg
mov ds,ax
;------------------------------------------------------
;MY OWN CODE
;提示輸入
lea dx,be
mov ah,9
int 21h
;輸入字符串
lea dx, data
mov ah,0ah
int 21h
;判斷
mov bx,1
check: inc bx
cmp data[bx],0dh
je deal
cmp data[bx],30h
jb others
cmp data[bx],7ah
ja others
cmp data[bx],39h
jbe numbers
cmp data[bx],61h
jae chars
cmp data[bx],41h
jb others
cmp data[bx],5ah
ja others
chars: inc char
jmp check
others: inc other
jmp check
numbers:
inc num
jmp check
deal:
mov ax,0
mov al,num
call bintodec
mov ax, word ptr d
mov word ptr num, ax
mov al,char
call bintodec
mov ax, word ptr d
mov word ptr char, ax
mov al,other
call bintodec
mov ax, word ptr d
mov word ptr other, ax
exit:
mov dl,0dh
mov ah, 2
int 21h
mov dl ,0ah
mov ah,2
int 21h
lea dx,output
mov ah,9
int 21h
;------------------------------------------------------
MOV ah,4CH
int 21H
bintodec proc
push ax
push bx
push dx
push si
push di
mov si, 0
or ax, ax
jz selfexit
xor bl, bl
lea di, table
selfnext: cwd
div word ptr cs:[di]
cmp bl, 0
jnz writeinto
cmp al, 0
je skip
mov bl, 1
writeinto: or al, 30h
mov d[si], al
inc si
skip: mov ax, dx
add di, 2
cmp cs:word ptr [di], 1
jne selfnext
selfexit: or al, 30h
mov d[si], al
inc si
pop di
pop si
pop dx
pop bx
pop ax
ret
table dw 10000,1000,100,10,1
bintodec endp
;------------------------------------------------------
cseg ends
;******************************************************
end start ;程序結束
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -