汇编求字符串中空格的个数

.model small
.data
.stack

string db 'You and Me , Can you understand ? $'
result dw ?
count equ $-string;获得字符串的个数

.code

ALdisp 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,7
aldisp1:mov ah, 2
        int 21h
        pop dx
        and dl,0fh
        or dl,30h
        cmp dl,39h
        jbe aldisp2
        add dl,7
aldisp2: mov ah,2
        int 21h
        pop dx
        pop cx
        pop ax
        ret
ALdisp  endp


Print   proc
        push ax
       mov ax,result
       xchg al,ah
       call ALdisp
       xchg al,ah
       call ALdisp
       pop ax
       ret
Print  endp
       
.startup
       mov cx,count
       mov si,offset string
       xor bx,bx
       jcxz done
       mov al,20h
again: cmp al,[si]
       jnz next
       inc bx
next:  inc si
       loop again
done:  mov result,bx
       call Print
       .exit 0
       end
       
       

你可能感兴趣的:(汇编)