Input a character string from the keyboard (the length does not exceed 30), count the number of non-digits in the character string, and display the statistical result on the screen, using EXE format.

problem

Input a character string from the keyboard (the length does not exceed 30), count the number of non-digits in the character string, and display the statistical result on the screen, using EXE format.

Source code

data segment
   hintinput db "please input a string:$";输入提示语
   hintoutput db "non-number:$";输出提示语
   str  db 30,?,30 dup(?);将输入的字符串保存在str中
   crlf db 0ah,0dh,'$';回车换行符
data ends
code segment
   assume cs:code,ds:data
main proc far
start:
  mov ax,data
  mov ds,ax
  lea dx,hintinput;输出提示语
  mov ah,09h
  int 21h
  lea dx,crlf     ;回车换行
  mov ah,09h
  int 21h
  lea dx,str
  mov ah,0ah
  int 21h
  lea dx,crlf     ;回车换行
  mov ah,09h
  int 21h
  lea si,str+2;si保存str首地址
  mov cl,str+1;cl保存str长度
  mov al,0  ;用al非数字计数
  mov ch,0
L1:
  mov dl,[si] ;把str中的数依次送入dl中
  cmp dl,'0'  ;如果dl<0,al加1
  jb L2
  cmp dl,'9';如果dl>9,al加1
  ja L2
  cmp dl,'9'
  jbe L3
L2:
  inc al
L3:
  inc si  
  loop L1       
  lea dx,hintoutput;输出提示语
  mov ah,09h
  int 21h
  mov dl,al
  cmp dl,9h       
  jbe L             ;如果非字母个数小于10,则直接加30输出
  mov dh,0           ;否则把dx存入ax中
  mov ax,dx
  mov bl,10               ;ax除以10后,ah作为商
  div bl                              ;al作为余数
  mov dl,al
  add dl,30h            ;先输出商,再输出余数,就是10进制了
  mov ah,02h
  int 21h 
  mov dl,ah
L:
  add dl,30h
  mov ah,02h
  int 21h
  lea dx,crlf     ;回车换行
  mov ah,09h
  int 21h 
  mov ax,4c00h
  int 21h
main endp
code ends
end start

Example of running result

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_43475285/article/details/106290666