如何使用IAS指令集将两个数字数组相加?

时间:2011-07-31 13:13:36

标签: arrays architecture von-neumann

我必须使用IAS指令集编写一个程序,该指令集将循环遍历两个数组并将一个元素的每个元素添加到另一个数组并将结果存储在thrid数组中。所以例如我必须取A(1)+ B(1)并将其存储在C(1)中,然后取A(2)+ B(2)并存储在C(2)中,依此类推,直到我到达A(20)+ B(20)存储在C(20)中。但是我不知道如何在IAS中创建一个反控制循环......反正......这就是我所做的......但它不起作用:))

00000001 LOAD M(A[1]) Transfer M(A[1]) to the accumulator
00000101 ADD M(B[1]) Add M(B[1]) to AC and store result in AC
00100001 STOR M(C[1]) Transfer contents of accumulator to memory location C[1]

感谢您的帮助:))

1 个答案:

答案 0 :(得分:1)

对于未来的任何人。这个问题实际上有很多解决方案,这是我选择的那个(可能需要一些细化):

* Initialize a variable 'count' to 999
Label: TOP
00000001    LOAD M(A[count])            Transfer M(A[count]) to the accumulator
00000101    ADD M(B[count])             Add M(B[count]) to AC and store result in AC
00100001    STOR M(C[count])            Transfer contents of accumulator to memory location C[count]
00001010    LOAD M(address of count)    Transfer the contents of M(address of count) to the AC
00000110    SUB M(the number 1)         Subtract one from AC and store in AC
00100001    STOR M(D)                   Transfer contents of AC to location M(D)
00001111    JUMP+ M(X,0:19)             If number in accumulator is non-negative take next
                                        instruction from left half of M(X)
LH: go to TOP
RH: exit