查看命令列表,您似乎可以通过从第二个输入中减去第一个输入然后使用条件分支来查看哪个更大。像这样的东西:
INP // Get input into accumulator
BRZ QUIT // If zero, we're finished
STA A // Accumulator to A
INP // Get input into accumulator
BRZ QUIT // If zero, we're finished
STA B // Accumulator to B
SUB A // Subtract A from accumulator (B)
BRP LOOP // Jump to LOOP if B > A already, otherwise swap
LDA A // Put A into accumulator
STA TEMP // Accumulator to TEMP
LDA B // Put B into accumulator
STA A // Overwrite A with B
LDA TEMP // Put TEMP (A) into accumulator
STA B // Overwrite B with A: now B > A
LOOP LDA AB // Put result into accumulator (starts off as zero)
ADD B // Add larger input to accumulator
STA AB // Update result
LDA A // Put loop counter (A) into accumulator
SUB ONE // Decrement
STA A // Update loop counter
BRZ DONE // Jump to DONE if loop counter is zero
BRP LOOP // Jump to LOOP if loop counter is positive
DONE LDA AB // Put result into accumulator
QUIT OUT // Output
HLT // Finish
ONE DAT 1 // ONE = 1
A DAT // First input
B DAT // Second input
AB DAT // A * B
TEMP DAT // Temporary (needed for swap)
请注意,这是完全未经测试的,因此它很可能包含错误!但是,我已经评论了来源,所以你可以看到这个想法。
编辑结果证明没有错误——在黑暗中刺伤还不错;)无论如何,以下是在评论中提到的基于 Java 的模拟器上运行的稍作修改的语法:
INP // Get input into accumulator
BRZ :QUIT // If zero, we're finished
STA :A // Accumulator to A
INP // Get input into accumulator
BRZ :QUIT // If zero, we're finished
STA :B // Accumulator to B
SUB :A // Subtract A from accumulator (B)
BRP :LOOP // Jump to LOOP if B > A already, otherwise swap
LDA :A // Put A into accumulator
STA :TEMP // Accumulator to TEMP
LDA :B // Put B into accumulator
STA :A // Overwrite A with B
LDA :TEMP // Put TEMP (A) into accumulator
STA :B // Overwrite B with A: now B > A
LOOP: LDA :AB // Put result into accumulator (starts off as zero)
ADD :B // Add larger input to accumulator
STA :AB // Update result
LDA :A // Put loop counter (A) into accumulator
SUB :ONE // Decrement
STA :A // Update loop counter
BRZ :DONE // Jump to DONE if loop counter is zero
BRP :LOOP // Jump to LOOP if loop counter is positive
DONE: LDA :AB // Put result into accumulator
QUIT: OUT // Output
HLT // Finish
ONE: 1 // ONE = 1
A: 0 // First input
B: 0 // Second input
AB: 0 // A * B
TEMP: 0 // Temporary (needed for swap)