我试图用汇编语言实现 QUICK SORT。当我在模拟器中运行代码时,数组“ARR”只包含零,没有加载任何值。我不知道我做错了什么。(ARR 在代码末尾定义。)
CODE SEGMENT
ASSUME CS:CODE,DS:CODE
ORG 1000H
MOV DI,05H ; LAST INDEX (6-1)
XOR SI,SI; INNITAL INDEX
XOR BX,BX; PIVOT INDEX
XOR BP,BP;
CALL QSORT
HLT
QSORT:
PUSH BP
PUSH DI
PUSH SI
CALL PARTITION
MOV SI,BP;
INC SI ; PIVOT INDEX +1 = INITIA IDEX
CMP SI,DI
JNL SKIP_CALL
CALL QSORT
SKIP_CALL:
POP SI;
PUSH SI;
MOV DI,BP;
DEC DI;
CMP SI,DI;
JNL SKIP_AGAIN
CALL QSORT
SKIP_AGAIN:
POP SI;
POP DI;
POP BP;
RET
PARTITION:
PUSH SI
PUSH DI
MOV BP,SI ;PIVOT INDEX
DEC SI; // TO INVALIDATE FIRST INCREMENT
FOR_1:
INC SI
CMP SI,DI
JGE END_FOR_1
MOV AL,ARR[SI]
CMP AL,ARR[DI]; COMPAREING TWO INDEXVAL
JL NO_SWAP
;SWAP OPERATION
PUSH AX;
XOR AX,AX; ENSURING ZEROS IN AH
MOV AL,ARR[BP]; SAVING ARR[SI] CONTENT
MOV ARR[SI],AL;
POP AX;
MOV ARR[BP],AL; SAVING BP'S CONTENT IN SI :P
INC BP;
NO_SWAP:
JMP FOR_1;
END_FOR_1:
MOV AL,ARR[DI];
MOV AH,ARR[BP];
MOV ARR[DI],AH;
MOV ARR[BP],AL;
POP DI;
POP SI;
RET
ORG 1500H
ARR DB 01H,02H,0AH,03H,00H,0CH; RANDOM ARRAY
NAME DW 'ANKLON'
ENDS
为了测试,我在变量窗口中添加了另一个字符串数组,它甚至没有显示。
谁能指出我的错误在哪里?