90 lines
4.8 KiB
Plaintext
90 lines
4.8 KiB
Plaintext
[Transpose a matrix in place. EDSAC, Initial Orders 2.]
|
|
..PZ [blank tape and terminator]
|
|
T50K [to call matrix transpose with 'G X']
|
|
P160F [address of matrix transpose subroutine]
|
|
T47K [to call matrix print subroutine with 'G M']
|
|
P120F [address of matrix print subroutine]
|
|
T46K [to call print subroutine with 'G N']
|
|
P56F [address of print subroutine (P1 in EDSAC library)]
|
|
T48K [to call division subroutine with 'G &']
|
|
P77F [address of division subroutine]
|
|
|
|
[Subroutine to transpose a matrix of 17-bit values in place.
|
|
Translated and slightly modified from C version on Rosetta Code website.
|
|
Parameters, all in the address field (i.e. n is stored as P n F):
|
|
10F = width (number of columns, "w" in C program)
|
|
11F = height (number of rows, "h" in C program)
|
|
12F = start address of matrix]
|
|
E25K TX GK
|
|
A3F T64@ [set up return to caller]
|
|
H10F V11F L32F L64F [acc := size of matrix as width*height]
|
|
T84@ T85@ [store size; C variable start := 0]
|
|
[8] TF A85@ T86@ T87@ [set C variables, next := start, i := 0]
|
|
[12] TF A87@ A2F T87@ [i++]
|
|
A16@ G65@ [call subroutine to update "next"]
|
|
A85@ S86@ G12@ [acc := start - next, loop back if < 0]
|
|
[Skip to location 58 if acc > 0 or i = 1.
|
|
We already know that acc >= 0 and i > 0.]
|
|
S2F E58@ [subtract 1 from acc, skip if still >= 0]
|
|
S2F A87@ G58@ [acc := -2 + i, skip if < 0]
|
|
[The assignment next := start in the C program is unnecessary]
|
|
TF A86@ A12F A81@ T31@ [make and plant order to load m{next}]
|
|
[31] AF T83@ [tmp := m{next}]
|
|
[33] TF [clear acc; also added to an address to make T order for that address]
|
|
[34] A86@ A12F A33@ T54@ [make and plant order to store m{next}]
|
|
A38@ G65@ [call subroutine to update "next"]
|
|
A86@ S85@ G48@ [go to 48 if i < start]
|
|
S2F E48@ [go to 48 if i > start]
|
|
TF A82@ G52@ [make order to load tmp, and go to 52]
|
|
[48] TF A86@ A12F A81@ [make order to load m{next}]
|
|
[52] T53@ [plant order to load tmp or m{next}]
|
|
[53] AF [manufactured order; if i = start loads tmp, else loads m{next}]
|
|
[54] TF [manufactured order; stores m{next}, using old value of "next"]
|
|
A85@ S86@ G33@ [acc := start - next, loop back if < 0]
|
|
[58] TF A85@ A2F U85@ [start++]
|
|
S84@ G8@ [loop until start = size]
|
|
[64] ZF [overwritten by return to caller]
|
|
[Subroutine to execute next = (next % h) * w + next / h in C program]
|
|
[65] A3F T80@ [set up return to caller]
|
|
A86@ T4F A11F T5F [set up parameters to divide "next" by "h"]
|
|
A71@ G& [call division subroutine]
|
|
[In case anybody is following this in detail, note that "next" and "h" are
|
|
stored in the address field, so we need to shift the quotient 1 left]
|
|
H4F V10F L64F L16F A5F LD T86@ [compute RHS and store in "next"]
|
|
[80] ZF [overwritten by return to caller]
|
|
[Constants]
|
|
[81] AF [added to an address to make A order for that address]
|
|
[82] A83@ [order to load C variable "tmp"]
|
|
[Variables; integers are stored in the address field for convenience.]
|
|
[83] PF [C variable "tmp" (holds value of a matrix element)]
|
|
[84] PF [size of matrix, width*height]
|
|
[85] PF [C variable "start"]
|
|
[86] PF [C variable "next"]
|
|
[87] PF [C variable "i"]
|
|
|
|
[Subroutine to print a matrix of 17-bit real numbers.]
|
|
E25K TM
|
|
GKA3FT30@A13FT18@A12FA31@T14@S11FT36@S10FT37@O34@O35@TDAFT1FA16@
|
|
GN
|
|
PFA14@A2FT14@A37@A2FG10@O32@O33@A36@A2FG8@ZFAF@F&F!FMFPFPF
|
|
|
|
[Library subroutine P1.
|
|
Prints positive number in 0D to n places of decimals, where
|
|
n is specified by 'P n F' pseudo-order after subroutine call.]
|
|
E25K TN
|
|
GKA18@U17@S20@T5@H19@PFT5@VDUFOFFFSFL4FTDA5@A2FG6@EFU3FJFM1F
|
|
|
|
[Integer division: number at 4F, divisor at 5F
|
|
Returns remainder at 4F, quotient at 5F
|
|
Working location 0D. 37 locations.]
|
|
E25K T&
|
|
GKA3FT34@A5FUFT35@A4FRDS35@G13@T1FA35@LDE4@T1FT5FA4FS35@G22@
|
|
T4FA5FA36@T5FT1FAFS35@E34@T1FA35@RDT35@A5FLDT5FE15@EFPFPD
|
|
|
|
[Main routine]
|
|
[Given in condensed form, since it's the same as in part 1, except
|
|
that the address of the transposed matrix is not required.]
|
|
PKT250KGK#F@F&FP7FP4FP320FP2FTFP328FPFPFO@A5@A7@T23@H4@N3@L64FL32F
|
|
T10@A9@A8@U9@TFA23@A2FT23@A10@A2FG19@A3@T10FA4@T11FA5@T12FA6@T13F
|
|
A38@GMO1@O2@A42@GXA10FTFA11FT10FAFT11FA50@GMO@ZFE11ZPF
|