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

.model small
.data
.stack

result dw ?

Prompt db 'please input a string :',0dh,0ah,'$'
string	db 255			;缓冲区,用于存放字符串
	db ?
	db 255 dup (?) 
	
count equ string+1h;获得字符串的个数
Newline	db 0dh, 0ah, "$"	;回车换行

.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 dx,offset Prompt
    mov ah,09h
    int 21h
	mov	ax, seg string	;取数据段存入ds中
	mov	ds, ax
 
	;输入字符串到buff
	mov dx,offset string
	mov	ah, 0ah
	int	21h
 
	lea	dx, Newline	;输出回车换行
	mov	ah, 9h
	int	21h
	
	
	   lea	si, string + 2h	;取字符串地址到si中
 
       mov cl,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
       
       



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