c#給定二維數組按升序排序
Problem: Write a program in 8086 microprocessor to sort numbers in ascending order in an array of n numbers, where size n is stored at memory address 2000 : 500 and the numbers are stored from memory address 2000 : 501.
問題:在8086微處理器中編寫一個程序,以按n個數字的升序對數字進行排序,其中大小n存儲在內存地址2000:500中,而數字存儲在內存地址2000:501中。
Algorithm:
算法:
Load data from offset 500 to register CL (for count).
將數據從偏移500加載到寄存器CL(用于計數)。
Travel from starting memory location to last and compare two numbers if first number is greater than second number then swap them.
從起始存儲位置移動到最后一個位置,如果第一個數字大于第二個數字,則比較兩個數字,然后交換它們。
First pass fix the position for last number.
首遍確定最后一個號碼的位置。
Decrease the count by 1.
將計數減少1。
Again travel from starting memory location to (last-1, by help of count) and compare two numbers if first number is greater than second number then swap them.
再次從起始存儲位置移動到(last-1,借助計數),如果第一個數字大于第二個數字,則比較兩個數字,然后交換它們。
Second pass fix the position for last two numbers.
第二遍確定最后兩個數字的位置。
Repeated.
重復。
Program:
程序:
ADDRESS | MNEMONICS | COMMENTS |
---|---|---|
400 | MOV SI, 500 | SI ← 500 |
403 | MOV CL, [SI] | CL ← [SI] |
405 | DEC CL | CL ← CL-1 |
407 | MOV SI, 500 | SI ← 500 |
40A | MOV CH, [SI] | CH ← [SI] |
40C | DEC CH | CH ← CH-1 |
40E | INC SI | SI ← SI+1 |
40F | MOV AL, [SI] | AL ← [SI] |
411 | INC SI | SI ← SI+1 |
412 | CMP AL, [SI] | AL-[SI] |
414 | JC 41C | JUMP TO 41C IF CY=1 |
416 | XCHG AL, [SI] | SWAP AL AND [SI] |
418 | DEC SI | SI ← SI-1 |
419 | XCHG AL, [SI] | SWAP AL AND [SI] |
41B | INC SI | SI ← SI+1 |
41C | DEC CH | CH ← CH-1 |
41E | JNZ 40F | JUMP TO 40F IF ZF=0 |
420 | DEC CL | CL ← CL-1 |
422 | JNZ 407 | JUMP TO 407 IF ZF=0 |
424 | HLT | END |
地址 | 記憶 | 注釋 |
---|---|---|
400 | MOV SI,500 | SI←500 |
403 | MOV CL,[SI] | CL←[SI] |
405 | DEC CL | CL←CL-1 |
407 | MOV SI,500 | SI←500 |
40A | MOV CH,[SI] | CH←[SI] |
40度 | DEC CH | CH←CH-1 |
40E | INC SI | SI←SI + 1 |
40樓 | MOV AL,[SI] | AL←[SI] |
411 | INC SI | SI←SI + 1 |
412 | CMP AL,[SI] | AL- [SI] |
414 | JC 41C | 如果CY = 1,則跳至41C |
416 | XCHG AL,[SI] | 交換AL和[SI] |
418 | DEC SI | SI←SI-1 |
419 | XCHG AL,[SI] | 交換AL和[SI] |
41B | INC SI | SI←SI + 1 |
41C | DEC CH | CH←CH-1 |
41E | JNZ 40F | 如果ZF = 0,則跳至40F |
420 | DEC CL | CL←CL-1 |
422 | JNZ 407 | 如果ZF = 0,則跳至407 |
424 | HLT | 結束 |
Explanation:
說明:
MOV SI, 500: set the value of SI to 500.
MOV SI,500:將SI的值設置為500。
MOV CL, [SI]: load data from offset SI to register CL.
MOV CL,[SI]:將數據從偏移量SI加載到寄存器CL。
DEC CL: decrease value of register CL BY 1.
DEC CL:將寄存器CL的值減1。
MOV SI, 500: set the value of SI to 500.
MOV SI,500:將SI的值設置為500。
MOV CH, [SI]: load data from offset SI to register CH.
MOV CH,[SI]:將數據從偏移量SI加載到寄存器CH。
DEC CH: decrease value of register CH BY 1.
DEC CH:將寄存器CH的值減1。
INC SI: increase value of SI BY 1.
INC SI:SI的值增加1。
MOV AL, [SI]: load value from offset SI to register AL.
MOV AL,[SI]:從偏移量SI加載到寄存器AL的值。
INC SI: increase value of SI BY 1.
INC SI:SI的值增加1。
CMP AL, [SI]: compares value of register AL and [SI] (AL-[SI]).
CMP AL,[SI]:比較寄存器AL和[SI](AL- [SI])的值。
JC 41C: jump to address 41C if carry generated.
JC 41C:如果產生進位,則跳轉到地址41C。
XCHG AL, [SI]: exchange the contents of register AL and SI.
XCHG AL,[SI]:交換寄存器AL和SI的內容。
DEC SI: decrease value of SI by 1.
DEC SI:將SI的值減1。
XCHG AL, [SI]: exchange the contents of register AL and SI.
XCHG AL,[SI]:交換寄存器AL和SI的內容。
INC SI: increase value of SI by 1.
INC SI:將SI的值增加1。
DEC CH: decrease value of register CH by 1.
DEC CH:將寄存器CH的值減1。
JNZ 40F: jump to address 40F if zero flat reset.
JNZ 40F:如果歸零平面復位,則跳轉到地址40F。
DEC CL: decrease value of register CL by 1.
DEC CL:將寄存器CL的值減1。
JNZ 407: jump to address 407 if zero flat reset.
JNZ 407:如果歸零平面復位,則跳轉到地址407。
HLT: stop.
HLT:停止。
翻譯自: https://www.includehelp.com/embedded-system/sort-numbers-in-ascending-order-in-an-array.aspx
c#給定二維數組按升序排序