使用 8085 升序排序。

Sorting in ascending order using 8085.

因此,在下面的代码中,我正在编写代码以按升序对数字进行排序。

start: nop

MVI B, 09 ; Initialize counter     
LXI H, 2200H  ;Initialize memory pointer
MVI C, 09H; Initialize counter 2
BACK: MOV A, M ;Get the number
INX H ;Increment memory pointer
CMP M; Compare number with next number
JC SKIP;If less, don't interchange
JZ SKIP; If equal, don't interchang
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H ;Interchange two numbers
DCR C  ; Decrement counter 2
JNZ BACK ;If not zero, repeat
DCR B ; Decrement counter 1
JNZ START
HLT ; Terminate program execution

这是 class 中教授的内容。 当我在 GNUSim 中尝试 运行 代码时,出现如下错误:

1. Line 9: Undefined symbol.
2. Line 9: Invalid operand or symbol.Check whether operands start with a 0. Like a0H should be 0a0H.

有人可以帮忙吗?

在 8085 (js8085) 中,我将采用下一种方式(使用冒泡排序):

@begin 0100
@next 0100
MVI A 00
MVI B 00
MVI C 00
MVI D 00
MVI E 00
MVI H 00
MVI L 00
IN 00
out 00
DCR A 
out 06
bubble: in 06
cmp c
jz finished
inr e
ldax b
mov h,a
ldax d
cmp h
jc change;
comprobation: in 00
cmp e
jz semi-fin
call bubble
semi-fin: inr c
mov a,c
mov e,c
call bubble
change: stax b
mov a,h
stax d
call comprobation
finished: hlt

在端口 00 中,你得到了你拥有的元素数量,元素本身从位置 0000 开始到 元素数量 - 1.