我正在编写一个代码来乘以三个数字。
A x B x C = Z. 您必须输入所有初始值。 还有一个有害的变量P. 您按此顺序输入A B C Z P ... 一个B& C可以是任何东西。 Z输入0,P输入1.(如果你可以告诉我如何设置它们的初始值也很好。)
我真正的问题是当我在程序结束时输出Z时,它会打印一个空格或x。任何帮助将不胜感激。
ORG 100
INPUT /USER INPUT VARIABLE
STORE A /STORE IN MEM LOCATION
OUTPUT /SHOW WHAT USER ENTERED
INPUT /USER INPUT VARIABLE
STORE B /VARIABLE B
OUTPUT
INPUT /VARIABLE C
STORE C
OUTPUT
INPUT
STORE Z
OUTPUT
INPUT
STORE P
OUTPUT
LOOP, LOAD Z /START LOOP TO ACCUMULATE A
ADD A
STORE Z
LOAD B
SUBT P /DECRIMENT VARIABLE B
STORE B
SKIPCOND 01 /CHECK IF B = 0
JUMP LOOP /REPEAT LOOP UNTIL B = 0
LOOP2, LOAD Z
ADD A
STORE Z
LOAD C
SUBT P /DECRIMENT C
STORE C
SKIPCOND 01 / CHECK IF C = 0
JUMP LOOP2 /REPEAT LOOP UNTIL C = 0
CLEAR
LOAD A
STORE A
CLEAR
LOAD Z
STORE Z
OUTPUT /DON'T KNOW WHY IT WON'T PRINT
HALT
A,DEC 0
B,DEC 0
C,DEC 0
Z,DEC 0
P,DEC 0
答案 0 :(得分:1)
不幸的是,我在一个半月后才看到这个问题,所以你可能不再需要帮助,但我相信你的问题其实很简单。听起来您可能将输出模式设置为ASCII(默认值)而不是十进制( Dec )。请参见下面的屏幕截图:
此外,请确保您选择了正确的输入类型,否则您的答案可能会出错:
至于如何设置初始值,您实际上已经通过包含以下内容来实现:
A, DEC 0
B, DEC 0
C, DEC 0
Z, DEC 0
P, DEC 0
这些行最初将值初始化为零。因此,如果P和Z应为零并且实际上不需要用户输入,则可以跳过获取用户输入。但是,如果您想重置值,可以执行以下操作:
/ ... Some stuff going on before you want to reset the values...
Clear / This will reset the value in AC to 0.
Store P / Store current AC Value (0) in memory at P
Store Z / Store current AC Value (0) in memory at Z
/ ... Store it wherever you want to reset values to Zero
/ Proceed with the rest of your program now that the values are reset.
/ And down at the bottom like normal:
A, DEC 0
B, DEC 0
C, DEC 0
Z, DEC 0
P, DEC 0
我通常喜欢做的一件事是设置一个子程序来重置所有内存。所以,我会创建如下内容:
TempAcValStorage, Dec 0 / Used to preserve value on AC so it is not lost when clearing
InitializeVals, HEX 0
Store TempAcValStorage / Store current AC val
CLEAR / Set value of AC to 0
STORE A / Store 0 in variable
STORE B / Store 0 in next variable
STORE C / ...
STORE Z
STORE P / Store 0 in last variable
Load TempAcValStorage / Restore whatever was on AC
JumpI InitializeVals
/ ... Futher down in my code when I need to initialize or reset my
/ values, I just execute a Jump-and-Store for InitializeVals:
JnS InitializeVals
此例程的一个好处是它保留了AC上的值,因此在重置所有存储变量的值时不会丢失它。