【汇编语言】筛选非负数+冒泡排序
程序员文章站
2024-02-02 18:31:28
...
ASSUME DS:seg1,CS:seg2
seg1 SEGMENT
FIRST DB 5,-8,3,9,-2,-5,7,-9,0,5,4,9,-6,1,-1,8,-3,6,2,-7,0,-4
N EQU $-FIRST
SECOND DB 30 DUP(?)
seg1 ENDS
seg2 SEGMENT
START: MOV AX,seg1
MOV DS,AX
LEA SI,FIRST
LEA DI,SECOND
MOV DX, 0
MOV CX,N
LLP: MOV AL,[SI]
TEST AL,10000000B
JNZ GO ;ZF = 0,是负数
MOV [DI],AL
INC DI
INC DX
GO: INC SI
LOOP LLP
;排序
DEC DX
SORT: MOV CX, DX
LEA DI, SECOND
AGAIN: INC DI
MOV AL, [DI]
CMP [DI - 1], AL
JB LP ;前一个比后一个小
XCHG [DI - 1], AL
MOV [DI], AL
LP: LOOP AGAIN
DEC DX
JNZ SORT
HLT
MOV AH, 4CH
INT 21H
seg2 ENDS
END START