【发布时间】:2021-04-26 15:39:12
【问题描述】:
我需要将五个数字从小到大排序。
我一直在为这个小人电脑模拟器的任务而苦苦挣扎。我尝试添加更多循环来添加 2 个输入数字,但它从未奏效。
3 个数字的工作排序器:
INP // Read in the first value
STA 91 // store it
INP // Read in the second value
STA 92 // store it
INP // Read in the third value
STA 93 // store it
LDA 92 // LOOP 1, STEP 1:
SUB 91 //
BRP STEP2 // if r91 and r92 are in order, don't swap them
LDA 92 // Begin swapping registers
STA 99 // temp = r92
LDA 91
STA 92 // r92 = r91
LDA 99
STA 91 // r91 = temp
STEP2 LDA 93 // LOOP 1, STEP 2
SUB 92
BRP STEP3 // If r92 and r93 are in order, don't swap them
LDA 93 // Begin swapping registers
STA 99 // temp = r93
LDA 92
STA 93 // r93 = r92
LDA 99
STA 92 // r92 = temp
STEP3 LDA 92 // LOOP 2, STEP 1
SUB 91
BRP STEP4 // if r91 and r92 are in order, don't swap them
LDA 92 // Begin swapping registers
STA 99 // temp = r92
LDA 91
STA 92 // r92 = r91
LDA 99
STO 91 // r91 = temp
STEP4 LDA 91 // Write out the sorted values
OUT
LDA 92
OUT
LDA 93
OUT
HLT // stop
【问题讨论】:
-
"我一直在挣扎"
-
是的,我尝试将这三个数字扩展到 5,但没有成功,抱歉,我会编辑我的帖子
-
“从未工作”恐怕仍然不是问题描述 ;-) 你运行它时发生了什么?为什么错了?
-
您使用的是哪个 LMC 模拟器?你试过什么没用?
-
你在吗?有什么意见吗?