ARRAY DW 1234,2345,5678,7890,3455,1233,0ABCDH,0FFFFH
DW 3421,7654,9867,7777,9999,3333,2222,1111
N1 DW ($-ARRAY)/2
NUMBER DW ($-ARRAY)/2 DUP(?)
COUNT DW 0
DATAS ENDS
CODES SEGMENT
ASSUME CS:CODES,DS:DATAS
START: MOV AX,DATAS
MOV DS,AX
MOV ES,AX
查找奇数
LEA SI,ARRAY
LEA DI,NUMBER
MOV CX,N1
@1:
MOV AX,[SI]
MOV BX,AX
SHR BX,1
JC @2
JMP @3
@2:
MOV [DI],AX
INC WORD PTR COUNT
ADD DI,2
@3:
ADD SI,2
LOOP @1
输出奇数
CALL OUTPUT
排序
LEA SI,NUMBER
MOV CX,COUNT
CALL BUBBLESORT
输出排序后的结果
CALL OUTPUT
退出程序
MOV AX,4C00H
INT 21H
=======================================
OUTPUT PROC NEAR
LEA SI,NUMBER
MOV CX,COUNT
CLD
@4:
LODSW
CALL DISPAX
LOOP @4
MOV AH,2
MOV DL,13
INT 21H
MOV DL,10
INT 21H
RET
OUTPUT ENDP
==============================================
DISPAX PROC NEAR
PUSH BX
PUSH CX
PUSH DX
PUSH SI
PUSH DS
PUSH AX
MOV AH,2
MOV DL,' '
INT 21H
POP AX
PUSH CS
POP DS
MOV BYTE PTR NZ,0
PUSH AX
LEA SI,DIVARR
MOV CX,5
@@1:
POP AX
MOV DX,0
MOV BX,[SI]
DIV BX
PUSH DX
CMP AL,0
JNE @@2
CMP BYTE PTR NZ,1
JE @@2
CMP CX,1
JE @@2
MOV DL,20H
JMP @@3
@@2:
ADD AL,30H
MOV DL,AL
MOV BYTE PTR NZ,1
@@3:
MOV AH,2
INT 21H
INC SI
INC SI
LOOP @@1
POP DX
POP DS
POP SI
POP DX
POP CX
POP BX
RET
DIVARR DW 10000,1000,100,10,1
NZ DB 0
DISPAX ENDP
=============================================
BUBBLESORT PROC NEAR
数组长度置入cx,字数组首地址置入 si
PUSH CX
POP DX
DEC DX
@SORTL1:
MOV CX,DX
MOV DI,SI
@SORTL2:
MOV AX,[DI+2]
CMP AX,[DI]
JA @SORTNEXT JG 或者 JA
XCHG AX,[DI]
MOV [DI+2],AX
@SORTNEXT:
INC DI
INC DI
LOOP @SORTL2
DEC DX
JNZ @SORTL1
RET
BUBBLESORT ENDP
===============================================
CODES ENDS
END START
ORG 0000HLJMPMAIN
ORG0100H
MAIN: MOV R0, #30H
MOV R7, #0AH
LOOP1: MOVA, R7
MOVR6, A
MOV A, R0
MOVR1, A
INC R1
LOOP2: MOV A, @R0
CLR C
SUBB A, @R1
JC LOOP3
MOV A, @R0
XCH A,@R1
MOV @R0, A
LOOP3: INC R1
DJNZR6, LOOP2
INC R0
DJNZ R7, LOOP1
SJMP $
END
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)