Hello world/Line printer: Difference between revisions

Added alternative solution for EDSAC.
m (added Diego task)
(Added alternative solution for EDSAC.)
Line 421:
 
EZPF</lang>
 
==={{header|Alternative}}===
As noted, null in the sense of zero cannot be used as a string terminator on EDSAC. However, it is possible to use the EDSAC null, whose 5-bit code is 10000. The subroutine below demonstrates this.
 
After the string characters, the terminating null is also sent to the teleprinter. This is because the teleprinter had a one-character buffer, so that an O order did not print its own character immediately, but stored it in the buffer and printed the character set up by the previous O order (Wilkes, Wheeler & Gill, 1951 edition, page 50). Sending the terminating null to the teleprinter ensures that the last character of the string is printed at the same time as the rest.
 
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>
[Alternative "Hello World" for Rosetta Code;
EDSAC, Initial Orders 2.]
 
[Subroutine to print a string.
Input: 0F = A order for first character (not preserved).
String is terminated with EDSAC null, which is sent to the teleprinter.]
T64K GK [load at 64, set base of relative addresses]
A3F T15@ [plant return link as usual]
AF [load A order passed by caller]
[3] T4@ [loop: plant A order for next character]
[4] AF [(planted) load next character]
UF [store char in 0F, also keep in acc]
OF [send char to teleprinter]
E10@ [if char >= 0 then can't be null; jump to continue]
A16@ [if char < 0 then add 011110...0 to test for null]
G14@ [if acc still < 0 then char is null, so jump to exit]
[10] TF [clear acc]
A4@ A2F [inc address in A order above]
G3@ [loop back(*)]
[14] TF [clear acc on exit]
[15] ZF [(planted) jump back to caller]
[16] K2048F [constant, to test for EDSAC null]
[(*) The accumulator contains an A order, so its top 5 bits are the code
for A, i.e. 11100. Hence the accumulator is negative, and G causes a jump.]
 
[Main routine]
T96K GK [load at 96, set base of relative addresses]
[Enter with acc = 0]
[0] A5@ [load A order for first char of string]
TF [pass to subroutine in 0F]
[2] A2@ G64F [call subroutine]
ZF [stop]
[5] A6@ [A order first character of string]
[6] 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]
EZ [define entry point]
PF [acc = 0 on entry]
[end]
</lang>
 
=={{header|ERRE}}==
113

edits