首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用8085按升序排序。

使用8085按升序排序。
EN

Stack Overflow用户
提问于 2015-01-30 19:24:34
回答 1查看 10.4K关注 0票数 0

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

代码语言:javascript
复制
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中运行代码时,我得到如下错误:

代码语言:javascript
复制
1. Line 9: Undefined symbol.
2. Line 9: Invalid operand or symbol.Check whether operands start with a 0. Like a0H should be 0a0H.

有人能帮帮忙吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-22 17:47:55

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

代码语言:javascript
复制
@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。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28234859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档