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#给定二维数组按升序排序