emu8086删除更多算术平均值的项目 [英] emu8086 remove items more arithmetic mean
本文介绍了emu8086删除更多算术平均值的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
组织键盘输入
您必须从键盘指定一维元素数组 该数组是找到算术平均值所必需的 删除项目,算术平均值更高 打印生成的元素数组(元素不超过算术平均值)
You must specify a one-dimensional array of elements from the keyboard This array is necessary to find the arithmetic mean Remove items more arithmetic mean Print the resulting array of elements (elements with no more than the arithmetic mean)
;srednee arifmiticheskoe
data segment
mas dw 2, 4, 6, 8, 10
n dw 0
ends
stack segment
dw 128 dup(0)
ends
code segment
start:
; set segment registers:
mov ax, data
mov ds, ax
mov es, ax
xor ax, ax
xor si, si
mov cx, 5
@1:
add ax, mas[si]
add si, 2
inc n
loop @1
cwd
idiv n
mov ax, 4c00h ; exit to operating system.
int 21h
ends
end start ; set entry point and stop the assembler.
推荐答案
我将展示如何输出不大于平均值的元素.要输出整数,请先将数字转换为文本.
I'll show how to output the elements that are not greater than the mean value. To output an integer you first convert the number into text.
...
idiv n ; -> AX=mean
mov dx,ax ; -> DX=mean
mov cx,n ; -> CX=count
xor si,si
Show:
mov ax, mas[si]
add si, 2
cmp ax,dx
jg Skip
pusha
; Insert here YourRoutineThatOutputsAnInteger
mov dl,32
mov ah,2
int 21h ;Output a space to separate numbers
popa
Skip:
loop Show
mov ax, 4c00h ; exit to operating system.
int 21h
...
MyRoutineThatOutputsAnInteger
MyRoutineThatOutputsAnInteger
mov bx,sp
mov cx,10
next:
xor dx,dx
div cx
add dl,30h
push dx
test ax,ax
jnz next
print:
pop dx
mov ah,2
int 21h
cmp sp,bx
jb print
这篇关于emu8086删除更多算术平均值的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文