汇编语言(二十)之分类统计字符个数

汇编语言(二十)之分类统计字符个数

输入一串字符串,分别统计英文字符,数字字符和其他字符的个数

程序运行:

www.zeeklog.com  - 汇编语言(二十)之分类统计字符个数

代码:


datas segment

     line_max_length    db 0ffh
     line               db  0, 100h  dup(?)

	 letter_count       dw  0
	 digit_count        dw  0
	 other_count        dw  0
	 
	 input                     db 'input a line:$'
	 output_letter_count       db 0dh,0ah,'letter count:$'
	 output_digit_count        db 0dh,0ah,'digit count:$'
	 output_other_count        db 0dh,0ah,'other count:$'
	 
datas ends

stacks segment stack

    db  100h dup(?)

stacks ends

codes segment

assume cs:codes,ds:datas,ss:stacks
main   proc  far
start:
       push ds
	   mov ax,0h
	   push ax
       mov ax,datas          ;初始化ds
	   mov ds,ax
       ;输入一行字符提示
       lea dx,input
	   mov ah,9
	   int 21h
	   ;输入一行字符
	   lea dx,line_max_length
	   mov ah,10 
	   int 21h 
	   
	   ;对输入的一行字符进行统计
	   mov cl,line
	   xor ch,ch
	   mov si,1
	   cmp cx,0         ;判断字符串的长度是否为0
	   jz break          ;若为0,跳转
	 s:
       mov al,line[si]
	   cmp al,'0'             ;判断字符是否小于'0'
	   jb other               ;若小于'0',则字符为其他字符
	   cmp al,'9'             ;判断字符是否大于'9'
	   ja letter_or_other     ;若大于'9',则字符为字母或其他字符
	   inc digit_count        ;否则,字符为数字字符,数字记录器加1
	   jmp next               ;跳转
	 letter_or_other:
	    and al,11011111b      ;将字符转为大写字符
		cmp al,'A'            ;判断字符是否大于'A'
		jb other               ;若小于,则字符是其他字符,跳转
		cmp al,'Z'            ;判断字符是否大于'Z'
		ja other               ;若大于,则字符为其他字符,跳转
		inc letter_count       ;否则,字符为字母字符,字母记录器加1
		jmp next
	 other:
	   inc other_count         ;字符为其他字符,其他记录器加1 
	 next:
	   inc si
	   loop s
     
    break:	 
        ;输出记录器的值
		lea dx,output_letter_count
		mov ah,9
		int 21h	
		mov ax,letter_count
		call decimal
		
		lea dx,output_digit_count
		mov ah,9
		int 21h
		mov ax,digit_count
		call decimal
		
		lea dx,output_other_count
		mov ah,9
		int 21h
		mov ax,other_count
		call decimal
       ret
	   
main endp

decimal proc near 

        push ax
		push cx 
		push dx
		push bx 
		
		cmp ax,0
		jge no_negative 
		mov bx,ax 
		mov dl,'-'
		mov ah,2 
		int 21h 
		neg bx 
		mov ax,bx 
		
	no_negative:
	   mov cx,0
	   mov bx,10 
	  de:
	   xor dx,dx 
	   div bx 
	   push dx 
	   inc cx
	   cmp ax,0 
	   jnz de 
	   
	  de1:
	   pop dx
	   add dl,30h
	   mov ah,2 
	   int 21h
	   loop de1 
	   
	  pop bx 
	  pop dx 
	  pop cx 
	  pop ax 
	  
	  ret 
	  
decimal endp
codes ends

end main

Read more

🚀Zeek.ai一款基于 Electron 和 Vite 打造的跨平台(支持 Windows、macOS 和 Linux) AI 浏览器

🚀Zeek.ai一款基于 Electron 和 Vite 打造的跨平台(支持 Windows、macOS 和 Linux) AI 浏览器

是一款基于 Electron 和 Vite 打造的跨平台(支持 Windows、macOS 和 Linux) AI 浏览器。 集成了 SearXNG AI 搜索、开发工具集合、 市面上最流行的 AI 工具门户,以及代码编写和桌面快捷工具等功能, 通过模块化的 Monorepo 架构,提供轻量级、可扩展且高效的桌面体验, 助力 AI 驱动的日常工作流程。

By Ne0inhk
超快速,使用ChatGPT编写回归和分类算法

超快速,使用ChatGPT编写回归和分类算法

本文将使用一些 ChatGPT 提示,这些提示对于数据科学家在工作时非常重要。 微信搜索关注《Python学研大本营》,加入读者群,分享更多精彩 以下是一些示例ChatGPT 提示的列表以及数据科学家的响应。 ChatGPT 提示 为决策树回归算法生成 python 代码。 下面是使用scikit-learn在 Python 中进行决策树回归的示例代码: import numpy as np import matplotlib.pyplot as plt from sklearn.tree import DecisionTreeRegressor # Generate random data rng = np.random.default_rng() x = 5 * rng.random(100) y = np.sin(x) + 0.

By Ne0inhk
力扣每日一题:993.二叉树的堂兄弟节点 深度优先算法

力扣每日一题:993.二叉树的堂兄弟节点 深度优先算法

993.二叉树的堂兄弟节点 难度:简单 题目: 在二叉树中,根节点位于深度 0 处,每个深度为 k 的节点的子节点位于深度 k+1 处。 如果二叉树的两个节点深度相同,但 父节点不同 ,则它们是一对堂兄弟节点。 我们给出了具有唯一值的二叉树的根节点 root ,以及树中两个不同节点的值 x 和 y 。 只有与值 x 和 y 对应的节点是堂兄弟节点时,才返回 true 。否则,返回 false。 示例: 示例 1: 输入:root = [1,2,3,4], x = 4, y = 3 输出:false

By Ne0inhk