我正在寻找一个 e-LMC 扩展的小人计算机程序,它将接受不确定的输入并对它们进行冒泡排序。我需要有更多的连续输入,然后进行冒泡排序。
INP //read 1st value
STA 0 // for store
INP // read 2nd value
STA 1 // store
INP // read 3rd value
STA 2 // store
LDA 1 // LOOP 1, STEP 1:
SUB 0 //
BRP STEP2 // if R0 and R1 are in order, don't swap them
LDA 1 // Begin swapping registers
STA 3
LDA 0
STA 1 // R1 = R0
LDA 3
STA 0 //R0 = temp
STEP2 LDA 2 // LOOP 1, STEP 2
SUB 1
BRP STEP3 // If R1 and R2 are in order, don't swap them
LDA 2 // Begin swapping registers
STA 3 // temp =R2
LDA 1
STA 2 //R2=R1
LDA 3
STA 1 // R1 = temp
STEP3 LDA 1 // LOOP 2, STEP 1
SUB 0
BRP STEP4 // if R0 andR1 are in order, don't swap them
LDA 1 // Begin swapping registers
STA 3 // temp = R1
LDA 0
STA 1 //R1=R0
LDA 3
STO 0 // R0 = temp
STEP4 LDA 0
OUT
LDA 1
OUT
LDA 2
OUT
HLT