汇编输入字符串并求空格个数

来源:互联网 发布:计算机与网络期刊等级 编辑:程序博客网 时间:2024/05/16 03:43
.model small.data.stackresult dw ?Prompt db 'please input a string :',0dh,0ah,'$'stringdb 255;缓冲区,用于存放字符串db ?db 255 dup (?) count equ string+1h;获得字符串的个数Newlinedb 0dh, 0ah, "$";回车换行.codeALdisp proc        push ax        push cx        push dx        push ax        mov dl,al        mov cl,4        shr dl,cl        or dl,30h        cmp dl,39h        jbe aldisp1        add dl,7aldisp1:mov ah, 2        int 21h        pop dx        and dl,0fh        or dl,30h        cmp dl,39h        jbe aldisp2        add dl,7aldisp2: mov ah,2        int 21h        pop dx        pop cx        pop ax        retALdisp  endpPrint   proc        push ax       mov ax,result       xchg al,ah       call ALdisp       xchg al,ah       call ALdisp       pop ax       retPrint  endp       .startup           mov dx,offset Prompt    mov ah,09h    int 21hmovax, seg string;取数据段存入ds中movds, ax ;输入字符串到buffmov dx,offset stringmovah, 0ahint21h leadx, Newline;输出回车换行movah, 9hint21h   leasi, string + 2h;取字符串地址到si中        mov cl,count       mov si,offset string       xor bx,bx       jcxz done       mov al,20hagain: cmp al,[si]       jnz next       inc bxnext:  inc si       loop againdone:  mov result,bx       call Print       .exit 0       end              

1 0