汇编语言之排序并输出

2017-10-22 / ASM

 

;--------------------------------------------
DATA  SEGMENT
    BUF  DB  10H, 25H, 32H, 13H, 43H
DATA  ENDS

;--------------------------------------------
STACK  SEGMENT  STACK  'STACK'
    SB  DB  100  DUP(?)
STACK  ENDS

;--------------------------------------------

CODE  SEGMENT
    ASSUME  CS:CODE, DS:DATA, SS:STACK

START:
    MOV  AX, STACK
    MOV  SS, AX
    MOV  AX, DATA
    MOV  DS, AX
    LEA  DI, BUF
    MOV  BL, 5

AGN:
    MOV  SI, DI
    MOV  CL, BL

AGN2:
    MOV  AL, [SI]
    CMP  AL, [SI + 1]
    JNC  AGN3
    XCHG [SI + 1], AL
    MOV  [SI], AL

AGN3:
    INC  SI
    DEC  CL
    JNZ  AGN2
    DEC  BL
    JNZ  AGN

;-------------------------
    MOV  CH, 06H
    MOV  CL, 04H
    MOV  AH, 02H

NEXT:
    MOV  DL, [DI]
    ROL  DL, CL
    AND  DL, 0FH
    CMP  DL, 0AH
    JB   STORE
    ADD  DL, 07H

STORE:
    ADD  DL, 30H
    INT  21H

;---------------
    MOV  DL, [DI]
    AND  DL, 0FH
    CMP  DL, 0AH
    JB   STORE2
    ADD  DL, 07H

STORE2:
    ADD  DL, 30H
    INT  21H
    MOV  DL, ' '
    INT  21H
    INC  DI
    DEC  CH
    JNE  NEXT

;-------------------------
    MOV  AH, 4CH
    INT  21H
CODE  ENDS

;--------------------------------------------
    END  START