使用8085按升序排序。

时间:2015-01-30 11:24:34

标签: sorting microprocessors 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

这是在课堂上讲授的。 当我尝试在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.

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:1)

在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