Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

assembly - emu8086 remove items more arithmetic mean

organize keyboard input

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.
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...