汇编实验 查找大小写字符数

assume    cs:code,ds:data
data    segment
	msg    db    'Enter a string:$'
	buffer    db    80,?,80 dup (?);中间问号表示存放字符个数,后面问号表示不初始化,可以写(0)
	number    db    0
	cap    db    0
	lower    db    0
	other    db    0
	nummsg    db    'numbers of digit:$'
	capmsg    db    'numbers of cap-letter:$'
	lowermsg    db    'numbers of lower-letter:$'
	othmsg    db    'numbers of other-char:$'
data    ends

code    segment
start:
    mov ax,data
    mov ds,ax

    mov dx,offset msg;offset 取标号的偏移地址
    mov ah,9
    int 21h
    
    mov dx,offset buffer
    mov ah,10
    int 21h

    call crlf
 
;------------------输出输入的字符串方式1----------------------循环    ah 2
    mov bx, offset buffer+2
    mov cl,buffer+1;必须是cl,内存单元的内容是一个字节一个字节,地址可以给cx
ls:
	mov dx,[bx]
	mov ah,2
	int 21h
	inc bx
	loop ls
	  
    call crlf
;------------------输出输入的字符串方式2----------------------末尾+'$' ah 9    
;    mov dx, offset buffer+2
 ;   mov al, buffer[1]
    mov bl, buffer[1]
    mov bh,0
    mov buffer[bx+2],'$';要加上第一位和数量位;间接寻址只能用bx bp si di
    mov dx, offset buffer+2
    mov ah,9
    int 21h
    
    call crlf
    ;mov bx,offset buffer+2;从  判断 或者用 
    lea bx, buffer+2;或者写lea bx, [buffer+2]
    mov cl,buffer+1;
judge:
    mov al,[bx];;
    cmp al,'0'
    jae az
    jmp oth
az:
    cmp al,'9'
    jbe num
    jmp zm
num:
    inc number
    jmp jx
zm:
    cmp al,'A'
    jae zm0
    jmp oth
zm0:
    cmp al,'Z'
    jbe zm1
    jmp zm2
zm1:
    inc cap
    jmp jx
zm2:
    cmp al,'a'
    jae zm3
    jmp oth
zm3:
    cmp al,'z'
    jbe zm4
oth:
    inc other
    jmp jx
zm4:
    inc lower
jx:
    inc bx
    loop judge
     
 
    mov dx,offset nummsg
    mov ah,9
    int 21h
 
    mov dl,number
    call disp
     
    call crlf
 
    mov dx,offset capmsg
    mov ah,9
    int 21h
     
    mov dl,cap
    call disp
 
    call crlf
 
    mov dx,offset lowermsg
    mov ah,9
    int 21h
 
    mov dl,lower
    call disp
 
    call crlf
 
    mov dx,offset othmsg
    mov ah,9
    int 21h
 
    mov dl,other
    call disp
 
    mov ah,4ch;4c退出程序
    int 21h
;crlf
crlf proc near
    mov ah,2
    mov dl,10
    int 21h
    
    mov dl,13
    int 21h
    ret
crlf    endp

;input:dx
disp proc near
	cmp dl,10
	jl l10
	jmp a10
a10:
	mov ax,dx;被除数在ax
	mov bl,10
	div bl;al是商 ah 余数
	mov bx,48
	mov ch,ah;后面输出会变化ah!
	
	mov dh,0
	mov dl,al
	add dl,bl
	mov ah,2
	int 21h
	
	mov dl,ch
	add dl,bl
	mov ah,2
	int 21h
	ret

l10:
	add dl,48
	jmp return
	
return:
	mov ah,2
	int 21h
	ret
    ;mov ax,dx
    ;xor dx,dx;异或 dx置零,这样更快
    ;mov bx,10
    ;mov cx,0
;d2:    cmp ax,10
    ;jb ok2
    ;div bx
    ;add dl,30h
    ;push dx
    ;xor dx,dx
    ;inc cx
    ;jmp d2
;ok2:    add al,30h
    ;push ax
    ;inc cx
;d3:    pop dx
	;add dl,48;如果这样超过9会输出字母、符号(输出是输出对应的ascii码)
    ;mov ah,2
    ;int 21h
    ;loop d3
    ;ret
disp    endp
;
code    ends
end    start

猜你喜欢

转载自blog.csdn.net/dsfsdfrtjj/article/details/114649175