求一个长为N(小于255)的ARRAY字数组中正数、负数与零的个数,正数的个数存放在DH中,负数的个数存放在DL中,零的个数存放在BH中。
(扩展:将统计的结果显示出来)
data segment
s1 db"the number of positive numbers is:","$"
s2 db"the number of negative numbers is:","$"
s3 db"the number of zeros is:","$"
crlf db 0ah,0dh,"$";回车换行
array db 7,2,-9,1,3,-1,0,-3,0
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov si,offset array
mov cl,0;用于计数,总共9个
mov bh,0;用于数字为零的计数
mov ch,0;用于数字为正数的计数
mov bl,0;用于数字为负数的计数
a:
cmp cl,9
je output
mov al,[si]
cmp al,0h
jz zero
js negative
jmp positive
zero:
add bh,1;加1h
jmp o;每一次增加后移动指针
negative:
add bl,1
jmp o
positive:
add ch,1
jmp o
o:
add cl,1;计数
add si,1;偏移量
jmp a;回到起点
output:
mov dx,offset s1
mov ah,9
int 21h
add ch,30h
mov dl,ch
mov ah,2
int 21h
lea dx, crlf
mov ah, 09h
int 21h
mov dx,offset s2
mov ah,9
int 21h
add bl,30h
mov dl,bl
mov ah,2
int 21h
lea dx, crlf
mov ah, 09h
int 21h
mov dx,offset s3
mov ah,9
int 21h
add bh,30h
mov dl,bh
mov ah,2
int 21h
sub ch,30h
mov dh,ch
sub bl,30h
mov dl,bl
mov ah,4ch
int 21h
code ends
end start