急!会汇编语言的大侠帮帮我啊!!!

2024-12-19 00:16:22
推荐回答(1个)
回答1:

DSEG SEGMENT
;数据段:在此处添加程序所需的数据
n equ 10
a db 1,3,5,7,9,2,4,6,8,0
evenn db 0
oddn db 0
DSEG ENDS

CSEG SEGMENT
assume cs:CSEG, ds:DSEG
MAIN PROC FAR ;主程序入口
mov ax, dseg
mov ds, ax
;此处添加主程序代码
call sort
call sum
mov bl,evenn
call display
call crlf
mov bl,oddn
call display
next:
;按任意键退出
mov ah,1
int 21h
mov ax, 4c00h ;程序结束,返回到操作系统系统
int 21h
MAIN ENDP
sort proc
mov cx,n
dec cx
loop1: mov di,cx
mov bx,0
loop2: mov al,a[bx]
cmp al,a[bx+1]
jge continue
xchg al,a[bx+1]
mov a[bx],al
continue: add bx,1
loop loop2
mov cx,di
loop loop1
ret
sort endp
sum proc
mov cx,n
lea si,a
next2:
mov al,[si]
test al,01h
jz even1
add oddn,al
jmp next1
even1: add evenn,al
next1: inc si
loop next2
ret
sum endp
display proc
mov ch,10d
call dec_div
mov ch,1d
call dec_div
ret
display endp
dec_div proc near
mov al,bl
mov ah,0
div ch
mov bl,ah
mov dl,al
add dl,30h
mov ah,2
int 21h
ret
dec_div endp

crlf proc near
mov dl,0ah
mov ah,2
int 21h
mov dl,0dh
mov ah,2
int 21h
ret
crlf endp
CSEG ENDS

END MAIN