我必须使用IAS指令集编写一个程序,用于将两个2*2矩阵相乘,并将结果存储在另一个矩阵C中。我看到另一个人发布的用于矩阵加法的程序:
**********************
* 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)
**************************如何将变量'count‘初始化为999?
发布于 2014-03-08 16:29:38
答: IAS没有立即数,但假设内存在某个地方已经有了正确的常量,就像假设内存有程序一样。
Hack:可以使用其他未使用的位,例如L或AC <<= 1指令,但需要浪费6个指令来编码那里的值999:
LEFT and RIGHT instructions 1 and 2 at Selector 0: 20 xxxx 20 1998
L / R instructions 3 and 4 at Selector 1: 20 xxxx 20 999
Left instruction 5: LOAD AC <- S(0)
Right instruction 6: AC -= S(1)这将有效地减去(垃圾+ 1998) -(垃圾+ 999) => 999
其他黑客还需要依赖于使用非零值编码的指令,然后强制生成负值,并反复将其右移以形成常量-1。
https://stackoverflow.com/questions/18455032
复制相似问题