0
汇编实验:
source link: https://seineo.github.io/%E6%B1%87%E7%BC%96%E5%AE%9E%E9%AA%8C%EF%BC%9A%E7%BB%9F%E8%AE%A1%E6%95%B0%E5%AD%97%E4%B8%AA%E6%95%B0.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
输入一个字符串,统计数字出现的次数。
算法流程图
data segment
buffer db 5 dup(?)
input db 'please input a number <= 5 digits', 0ah, 0dh, '$'
outOfBound db 0ah, 0dh, 'error: more than 5 digits',0ah, 0dh, '$'
notANum db 0ah, 0dh, 'error: not a number',0ah, 0dh,'$'
data ends
code segment
assume ds:data, cs:code
start:
mov bl, 0
l4:
mov ah, 01h
int 21h
cmp al, 20h ; 空格结束输入
je count
cmp al, byte ptr '0'
jb l4
cmp al, byte ptr '9'
ja l4
inc bl
jmp l4
count:
mov ah, 0
mov al, bl ; 将要输出的数字
or ax, ax
jz zero ; 是零则直接输出
mov bx, -1 ; 栈底
push bx
mov bx, 10 ; 除数
l5:
xor dx, dx ; 余数清零
div bx
mov cx , ax ;商
or cx , dx
jz print ; 商与余数全零则结束
push dx
jmp l5
zero:
mov dl , 30h
mov ah , 02h
int 21h
jmp exit
print:
pop dx
cmp dx , -1
je exit
add dx , 30h
mov ah , 02h
int 21h
jmp print
exit:
mov ah, 08h ;结束时停留
int 21h
mov ah , 4ch ;返回DOS
int 21h
code ends
end start
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK