assume cs:code, ds:data
extrn write:far
data segment
str1 db 0dh, 0ah, "There are $"
str2 db " data equal to zero in the array! $"
str3 db " data greater than zero in the array! $"
str4 db " data less than zero in the array! $"
str5 db 0dh, 0ah, "The max is $"
str6 db 0dh, 0ah, "The min is $"
zero_count dw 0 ;等于0的计数器
greater_count dw 0 ;大于0的计数器
less_count dw 0 ;小于0的计数器
max dw 0 ;最大值
min dw 0 ;最小值
array dw 40, 12, 0, -2, 23, -12, 0, 2, -10, 100, 0, -100
len equ ($ - array) / 2
data ends
code segment
outstr macro msg
lea dx, msg
mov ah, 9
int 21h ;调用9号功能输出字符
endm
disp macro integer
mov ax, integer
stc
call far ptr write
endm ;这一段调用子程序write用来输出
start:
mov ax, data
mov ds, ax
;查找等于0的个数
find_zero:
lea bx, array
mov cx, len
mov zero_count, 0
s:
cmp word ptr[bx], 0
jne next
inc zero_count
next:
add bx, 2
loop s
;查找大于0的个数
find_greater_zero:
lea bx, array
mov cx, len
mov greater_count, 0
s1:
cmp word ptr[bx], 0
jng next1
inc greater_count
next1:
add bx, 2
loop s1
;查找小于0的个数
find_less_zero:
lea bx, array
mov cx, len
mov less_count, 0
s2:
cmp word ptr[bx], 0
jnl next2
inc less_count
next2:
add bx, 2
loop s2
;查找最大值
find_max:
lea bx, array
mov cx, len
mov ax, [bx]
mov max, ax
s3:
mov ax, [bx]
cmp max, ax
jg next3
mov max, ax
next3:
add bx, 2
loop s3
;查找最小值
find_min:
lea bx, array
mov cx, len
mov ax, [bx]
mov min, ax
s4:
mov ax, [bx]
cmp min, ax
jl next4
mov min, ax
next4:
add bx, 2
loop s4
outstr str1
disp zero_count ;输出等于0的数据的个数
outstr str2
outstr str1
disp greater_count ;输出大于0的数据的个数
outstr str3
outstr str1
disp less_count ;输出小于0的数据的个数
outstr str4
outstr str5
disp max ;输出最大值
outstr str6
disp min ;输出最小值
mov ax, 4c00h
int 21h
code ends
end start