0

我被要求编写一个代码,在 Marie 的程序集中将用户的 2 个输入相乘。我做的一切都是正确的,除了在问题中有一个伪代码中的条件我不能在我的代码中完全暗示..如果 x = 0 那么 x = x + 3 这意味着如果第一个输入为零,我需要将 x 增加 3 . 我原来的乘法代码有效,就是这样:

ORG 512
Input
Store x
Input
Store y
loop,Load z
 Add x
 Store z
 Load y
 Subt one
 Store y
 Skipcond 400
 Jump loop
Load z
Output
Halt
x, DEC 0
y, DEC 0
one, DEC 1
z, DEC 0

此代码适用于任何 x 或 y 相乘,但即使我尝试过,我也无法实现上述条件

ORG 512
Input
Store x
Skipcond 800   /in case of input x to 0
Add one    /adding one to x to reach 1
Add one     /adding one to x to reach 2
Add one      /adding one to x to reach 3
Store x
Input
Store y
loop,Load z
   Add x
   Store z
   Load y
   Subt one
   Store y
   Skipcond 400
   Jump loop
Load z
Output
Halt
x, DEC 0
y, DEC 0
one, DEC 1
z, DEC 0

但是当我把 x 和 y 都作为正数时,这就搞砸了,它对乘法给出了奇怪的答案。

4

0 回答 0