本文为《汇编语言程序设计》1104小节例程。点击链接…进课程主页。
给出下面一组数据:
data segment
db 8,11,8,1,8,5,63,38
data ends
请编程实现如下统计,用ax保存统计结果
(1)统计数值为8的字节的个数
(2)统计数值大于8的字节的个数
(3)统计数值小于8的字节的个数
参考解答:
(1)统计数值为8的字节的个数
assume cs:code, ds:data
data segment
db 8,11,8,1,8,5,63,38
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bx,0
mov ax,0
mov cx,8
s: cmp byte ptr [bx],8
jne next
inc ax
next:
inc bx
loop s
mov ax,4c00h
int 21h
code ends
end start
或
assume cs:code, ds:data
data segment
db 8,11,8,1,8,5,63,38
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bx,0
mov ax,0
mov cx,8
s: cmp byte ptr [bx],8
je ok
jmp short next
ok: inc ax
next: inc bx
loop s
mov ax,4c00h
int 21h
code ends
end start
(2)统计数值大于8的字节的个数
assume cs:code, ds:data
data segment
db 8,11,8,1,8,5,63,38
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bx,0
mov ax,0
mov cx,8
s: cmp byte ptr [bx],8
jna next
inc ax
next: inc bx
loop s
mov ax,4c00h
int 21h
code ends
end start
(3)统计数值小于8的字节的个数
assume cs:code, ds:data
data segment
db 8,11,8,1,8,5,63,38
data ends
code segment
start:
mov ax,data
mov ds,ax
mov bx,0
mov ax,0
mov cx,8
s: cmp byte ptr [bx],8
jnb next
inc ax
next: inc bx
loop s
mov ax,4c00h
int 21h
code ends
end start