emu8086 : ARR 不包含任何值 (emu8086 : ARR do not contain any value)


問題描述

emu8086 : ARR 不包含任何值 (emu8086 : ARR do not contain any value)

我試圖用彙編語言實現 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

為了進行測試,我在其後添加了另一個字符串數組,該數組甚至沒有顯示在變量窗口中。screen shot of var

誰能指出我的錯誤在哪裡?


參考解法

方法 1:

It appears you are trying to generate a COM program where the DS and CS segment are the same. The problem is that a COM program needs to start at offset 100h. So your ORG 1000H should be ORG 100H . Don't use a second ORG in your code so you should remove the line ORG 1500H . These two problems will confuse EMU8086 and when you go to display the variable it will be in the wrong place and will likely show data (like zeroes) that you don't expect.

The code would look like this:

CODE SEGMENT
ASSUME CS:CODE,DS:CODE   
ORG 100H

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 

ARR  DB 01H,02H,0AH,03H,00H,0CH; RANDOM ARRAY   
NAME DW 'ANKLON'  

ENDS

(by AnklonMichael Petch)

參考文件

  1. emu8086 : ARR do not contain any value (CC BY‑SA 2.5/3.0/4.0)

#emu8086 #assembly #x86-16 #Sorting #arrays






相關問題

使用 include 'emu8086.inc' 反轉字符串的大小寫和順序 (Reverse case and order of a String using include 'emu8086.inc')

emu8086 : ARR 不包含任何值 (emu8086 : ARR do not contain any value)

為什麼這個彙編代碼不刪除擴展名為“.lnk”的文件? (Why doesn't this assembly code delete the file with ".lnk" extension?)

將 C 代碼轉換為 8086 程序集 (Converting C code into 8086 assembly)

循環無法打印字母 (Loop does not work to print alphabets)

如何使用 call 和 ret 更改堆棧內容? (how to change stack content with call and ret?)

彙編語言中的putch函數通過堆棧 (putch function in assembly language through stack)

如何在不使用 HLT 的情況下對程序進行 HLT (How to HLT the program without using HLT)

使用 8086 彙編計算 10 的階乘 (Computing the factorial of 10 using 8086 assembly)

你好,我有一個問題,我需要從用戶那裡得到輸入,輸入是一個數字和一個數字後的數字,數字可以是雙字 (hello , i got a question that i need to get input from user, the input is a number and digit after digit ,the number can be a doubleWord)

在彙編語言中得到錯誤的結果 (Getting wrong result in Assembly language)

我的氣泡代碼是彙編語言嗎? (is my code for bubble right at assembly language?)







留言討論