我需要从最小到最大对五个数字进行排序。
我一直在为这个小人电脑模拟器的任务而苦苦挣扎。我尝试添加更多循环来添加 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