【发布时间】:2021-02-08 03:33:29
【问题描述】:
我正在寻找一个 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
【问题讨论】:
-
你能指出“e-LMC”的语言规范吗?
-
它有更大的内存地址(0-999),通用寄存器(R4到R7),常量寄存器(R0=0,R1=1,R2=2,R3=999),内存-mapped IO 内存地址 990-999 为 IO 保留。指令集:与 LMC 相同,但具有 MUL 用于乘法、DIV 用于除法、MOV (RN
-
例如,要从输入中加载一系列数字,您可以执行以下操作。 1) 初始化相关的“STO”指令。将位置 100 设置为相关值,例如“3500”。 2) 输入一个数字并执行 STO 指令(连同其他相关指令)。 3) 将内存位置 100 (3500) 的内容加载到累加器中,加一,并将其存储回其位置 (100)。 STO 指令现在将读取为“3501”。 4) 转到第 2 步并继续,直到提供了设置的数字计数。
-
这种语言的文档在哪里?
-
你能收到 PDF 吗?
标签: memory bubble-sort continuous little-man-computer