回 帖 发 新 帖 刷新版面

主题:[讨论]大家一定帮忙决绝这个程序啊,不然回不了家了,谢谢

从键盘输入并显示若干个字符(不超过100个),将这些字符照ASC11码由小到大循序显示,统计其中的数字字符,字母字符,及其他字符的个数,并显示如下
DIGIT{数字字符个数}
LETER{字母字符个数}
OTHER{其他字符个数}

回复列表 (共4个回复)

沙发


你太傻了,大菜!

板凳

用masm宏汇编的.if .elseif

3 楼

    .model small
    .stack 128
    .data
numdigit db 0
numletter db 0
numother db 0
Message db 0dh, 0ah, "After sorted:", 0dh, 0ah, "$"
digitm db 0dh, 0ah,  "DIGIT   ","$"
letterm db 0dh, 0ah, "LETTER  ","$" 
otherm db 0dh, 0ah,  "OTHER   ","$"
    
buffer label byte
maxlen db 100
actlen db ?
kbstr  db 100 dup(?)

    .code
main proc far
    mov ax, @data
    mov ds, ax
;get characters
    mov ah, 0ah
    mov dx, offset buffer
    int 21h
        
    call sort
    
    mov ah, 09h
    mov dx, offset Message
    int 21h
    
    xor si, si
    mov bl,actlen
    xor bh, bh
disp:
    mov ah, 02h
    mov dl, [kbstr+si]
    int 21h
    inc si
    cmp si, bx
    jb disp
    
    call cacl;caculate digit, letter, and other characters
        
    mov ah, 09h
    mov dx, offset digitm
    int 21h
    mov al, numdigit
    call prtdec
    
    mov ah, 09h
    mov dx, offset letterm
    int 21h
    mov al, numletter
    call prtdec
    
    mov ah, 09h
    mov dx, offset otherm
    int 21h
    mov al, numother
    call prtdec
    
    mov ax, 4c00h
    int 21h
main endp    
;insertion sort
sort proc near    
    
    mov dx, offset kbstr
    mov di, dx
    mov cl, actlen ;CX hold Total Length
    xor ch, ch
    add cx, dx
    inc di
    
;Insertion sort    
loop1:
    cmp di, cx
    jae exit
    mov ah, [di]   ;ah holds inserting next key element
    mov si, di
    dec si
    ;inloop insert key element to the sorted sequence data1 to di-1             
        inloop:
            cmp si, dx
            jb cont
            mov al, [si]
            cmp ah, al
            jae cont
            mov [si+1], al
            dec si
            jmp inloop            
cont:
    mov [si+1], ah
    inc di
    jmp loop1
exit:
    ret
sort endp

cacl proc near
    mov si, offset kbstr
    mov cl, actlen
    xor ch, ch ;clear ch
    add cx, si    
    cld 
    
again:
    lodsb
    cmp si,cx
    ja return
    cmp al, 30h ;'0'
    jb incother
    cmp al, 39h ;'9'
    jbe incdigit
    cmp al, 41h ;'A'
    jb incother
    cmp al, 5ah ;'Z'
    jbe incletter
    cmp al, 61h ;'a'
    jb incother
    cmp al, 7ah ;'z'
    jbe incletter
incother:
    mov ah, numother
    inc ah
    mov numother, ah
    jmp again
incdigit:
    mov ah, numdigit
    inc ah
    mov numdigit, ah
    jmp again
incletter:
    mov ah, numletter
    inc ah
    mov numletter, ah
    jmp again
    
return:
    ret
cacl endp

prtdec proc near ;only one to two decimal digit

    mov bl, 10
    xor ah, ah
    div bl
    mov bh, ah
    or al, al
    jz oned
    or al, 30h
    mov ah,02h
    mov dl, al
    int 21h
oned:    
    or bh,30h
    mov dl, bh
    mov ah,02h
    int 21h
    
    ret
prtdec endp
    end main
    

4 楼

我也是初学汇编, 欢迎加入我的兴趣小组
[url]http://www.programfan.com/team/team.asp?team_id=781[/url]

我来回复

您尚未登录,请登录后再回复。点此登录或注册