📅  最后修改于: 2022-03-11 15:00:37.881000             🧑  作者: Mango
.MODEL SMALL
.STACK 100H
.DATA
N DB 44H,22H,11H,55H,33H ; N is an array
LEN DW 5 ; LENGTH OF ARRAY N
.CODE
MAIN PROC
MOV AX,@DATA
MOV DS,AX
MOV CX,LEN ;Cx is counter for OUTERLOOP CX=5
DEC CX ; CX = 4
OUTERLOOP:
MOV SI,0 ; SI is the index of array N
MOV DX,CX ; Dx is counter for INNERLOOP
INNERLOOP:
MOV AH,N[SI] ; assign the number N[SI] into reg.AH
MOV AL,N[SI+1] ; assign the next number N[SI+1] into reg.AL
CMP AH,AL ; Compare between N[SI] and N[SI+1]
JC CARRY ; if AL > AH => Carry Flag =1 ,THEN jump to carry
MOV N[SI] , AL ; else , Do Switching bteween N[SI] and N[SI+1]
MOV N[SI+1] ,AH
CARRY:
INC SI
DEC DX
JNZ INNERLOOP
LOOP OUTERLOOP
;exit
MOV AH,4CH ;service number
INT 21H ; interrupt
MAIN ENDP
END