Hello world/Line printer: Difference between revisions

Content added Content deleted
(Added alternative solution for EDSAC.)
m (Small change to code in alternative EDSAC version)
Line 429: Line 429:
The EDSAC PC simulator allows .F for null and *F for letter shift, but it seems from WWG that on the original EDSAC these had to be input as K4096F and K2048F respectively.
The EDSAC PC simulator allows .F for null and *F for letter shift, but it seems from WWG that on the original EDSAC these had to be input as K4096F and K2048F respectively.
<lang edsac>
<lang edsac>
[Alternative "Hello World" for Rosetta Code;
[Alternative "Hello World" for Rosetta Code]
EDSAC, Initial Orders 2.]


[Subroutine to print a string.
[Subroutine to print a string.]
Input: 0F = A order for first character (not preserved).
[Parameter: A order for first character follows subroutine call (G order).]
[Modified 2022-07-13: A order for first character was formerly passed in 0F.]
String is terminated with EDSAC null, which is sent to the teleprinter.]
[String is terminated with EDSAC null, which is printed]
T64K GK [load at 64, set base of relative addresses]
A3F T15@ [plant return link as usual]
T56K GK [load at 56; set relative addressing]
AF [load A order passed by caller]
A18@ U17@ [plant return link, increasing address by 3
[3] T4@ [loop: plant A order for next character]
instead of 2 as usual]
[4] AF [(planted) load next character]
S19@ [make A order to load A order after subroutine call]
UF [store char in 0F, also keep in acc]
T4@ [plant in code]
OF [send char to teleprinter]
[4] AF [(planted) load A order after subroutine call]
E10@ [if char >= 0 then can't be null; jump to continue]
[5] T6@ [loop: plant A order for next character]
A16@ [if char < 0 then add 011110...0 to test for null]
[6] AF [load next character]
G14@ [if acc still < 0 then char is null, so jump to exit]
UF [to 0F for printing; keep it in acc]
[10] TF [clear acc]
OF [output to teleprinter]
A4@ A2F [inc address in A order above]
E12@ [if char >= 0, not EDSAC null]
G3@ [loop back(*)]
A20@ [if char < 0, add 15 to test for EDSAC null]
[14] TF [clear acc on exit]
G16@ [jump to exit if null]
[15] ZF [(planted) jump back to caller]
[12] TF [clear acc]
[16] K2048F [constant, to test for EDSAC null]
A6@ A2F [inc address in A order above]
G5@ [loop back, because top 5 bits = A = 11100]
[(*) The accumulator contains an A order, so its top 5 bits are the code
[16] TF [clear acc on exit (EDSAC convention)]
for A, i.e. 11100. Hence the accumulator is negative, and G causes a jump.]
[17] ZF [(planted) jump back to caller]
[18] U3F [constant for making return link]
[19] U1F [constant for picking up parameter]
[20] K2048F [constant for testing final null]


[Main routine]
[Main routine]
T96K GK [load at 96, set base of relative addresses]
T96K GK [load at 96; set relative addressing
[Enter with acc = 0]
[Enter with acc = 0]
[0] A5@ [load A order for first char of string]
[0] A@ G56F [call print subroutine]
TF [pass to subroutine in 0F]
A4@ [A order for first character of string]
[2] A2@ G64F [call subroutine]
ZF [subroutine returns here; halt machine]
ZF [stop]
[4] K2048F HF EF LF LF OF !F WF OF RF LF DF @F &F K4096F
[The above string is: letter shift, 'HELLO WORLD', CR, LF, null]
[5] A6@ [A order first character of string]
[6] K2048F HF EF LF LF OF !F WF OF RF LF DF @F &F K4096F
EZ [define entry point]
[The above string is: letter shift, 'HELLO WORLD', CR, LF, null]
PF [acc = 0 on entry]
EZ [define entry point]
PF [acc = 0 on entry]
[end]
[end]
</lang>
</lang>