0

I have to write a program using IAS Instruction set for multiplying two 2*2 matrices and store the result in another matrix C. I saw a program posted by another guy for matrix addition:

**********************
* 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)

**************************

How do we initialize a variable 'count' to 999?

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • **[The 1950 IAS](http://en.wikipedia.org/wiki/IAS_machine)**?! Why the heck do you have to write a program for *that* architecture? – nneonneo Aug 27 '13 at 05:43

1 Answers1

0

Answer: IAS doesn't have immediates, but assumes that memory has already the correct constants somewhere, just as it is assumed that the memory has somehow the program.

Hack: It is possible to use otherwise unused bits of e.g. L or AC <<= 1 instruction, but one would be required to waste 6 instructions to encode the value 999 there:

 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)

Effectively this would subtract (garbage + 1998) - (garbage + 999) => 999

Other hacks would also need to rely on instructions being encoded with non-zero values, then forcing a negative value to be produced, and repeatedly shifting it right to form the constant -1.

Aki Suihkonen
  • 19,144
  • 1
  • 36
  • 57