Hello world/Line printer: Difference between revisions

m
Small change to code in alternative EDSAC version
(Added alternative solution for EDSAC.)
m (Small change to code in alternative EDSAC version)
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.
<lang edsac>
[Alternative "Hello World" for Rosetta Code;]
EDSAC, Initial Orders 2.]
 
[Subroutine to print a string.]
Input[Parameter: 0F = A order for first character follows subroutine call (notG preservedorder).]
[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.printed]
T64K GK [load at 64, set base of relative addresses]
A3FT56K GK T15@ [plantload at return56; linkset asrelative usualaddressing]
AFA18@ U17@ [plant return link, increasing [load A order passedaddress by caller]3
[3] T4@ [loop: plant A order for next character instead of 2 as usual]
[4] AF S19@ [(planted)make A order to load nextA order after subroutine charactercall]
UFT4@ [store char in 0F, also keepplant in acccode]
[4] AF OF [(planted) load [sendA order charafter tosubroutine teleprintercall]
[5] T6@ E10@ [if char >= 0 thenloop: can'tplant beA null;order jumpfor tonext continuecharacter]
[6] AF A16@ [if char < 0 then add 011110...0 to testload fornext nullcharacter]
G14@UF [if acc still <[to 00F thenfor charprinting; iskeep null,it soin jump to exitacc]
[10] TF OF [clearoutput to accteleprinter]
A4E12@ A2F [incif char address>= in0, Anot orderEDSAC abovenull]
G3A20@ [loopif back(*)char < 0, add 15 to test for EDSAC null]
[14] TF G16@ [clear acc on [jump to exit if null]
[1512] ZFTF [(planted) jump back toclear calleracc]
[16] K2048F A6@ A2F [constant,inc toaddress testin forA EDSACorder nullabove]
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]
T96K GK [load at 96,; set base of relative addresses]addressing
[Enter with acc = 0]
[0] A5A@ G56F [load A order for first charcall ofprint stringsubroutine]
TFA4@ [passA toorder subroutinefor infirst 0Fcharacter of string]
[2] A2@ G64F [call ZF [subroutine returns here; halt machine]
[4] K2048F HF EF ZFLF LF OF !F WF OF RF [stop]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 LFEZ LF OF !F WF OF RF LF DF[define @Fentry &F K4096Fpoint]
[ThePF above string is: letter shift, 'HELLO WORLD', CR,[acc = 0 LF,on nullentry]
EZ [define entry point]
PF [acc = 0 on entry]
[end]
</lang>
113

edits