Nakazoto / Hellorld

A collection of the greatest programming on the planet!
21 stars 3 forks source link

Hellorld! on a DEC PDP-8 (ok it's a replica but it's an exact replica & the same code would work exactly the same on a real PDP-8) #7

Closed dburr closed 10 months ago

dburr commented 11 months ago

Not sure how to submit one of these... hopefully This Is The Way(tm)

Here is my response to the "Hellorld!" challenge. I printed "Hellorld!" on a DEC PDP-8 minicomputer. OK, technically it's not a real PDP-8 (unfortunately I don't have space for one) but it is a near perfect replica, the SBC6120 created by Bob Armstrong of Spare Time Gizmos. But the same code would run unmodified and would produce exactly the same results on a real PDP-8.

vlcsnap-2023-10-30-10h09m53s652

I've done "Hellorld!" in not one, not two, but THREE different ways:

In PAL-8 assembly language

/ PDP-8 PAL ASSEMBLY LANGUAGE PROGRAM TO PRINT "HELLORLD!"
/
/ TO LOAD TO PDP-8:
/ - BOOT INTO OS/8
/ - AT "." PROMPT, TYPE "CREATE HELLO.PA"
/ - AT "#" PROMPT, TYPE "A"
/ - PASTE CONTENTS OF FILE
/ - ON A BLANK LINE TYPE <CONTROL-L>
/ - AT "#" PROMPT, TYPE "E"
/ - AT "." PROMPT, TYPE "PAL HELLO" TO ASSEMBLE
/   (OR "PAL HELLO,HELLO<HELLO/H" TO ASSEMBLE WITH LISTING)
/ - IF THERE WERE NO ERRORS, AT "." PROMPT, TYPE "LOAD HELLO/G" TO RUN

        *200                    / START ADDRESS
        AIX1=10                 / SETUP AUTOINDEX REGISTER 1

        CLA                     / CLEAR ACCUMULATOR
        CLL                     / CLEAR AC LINK
        TAD MSG                 / LOAD ADDRESS OF MSG TO PRINT (2'S COMP ADD
                                / TRANSFERS TO AC)
        DCA AIX1                / ...AND STORE IN AUTOINDEX REG 1
                                / (DEPOSIT + CLEAR ACC)

LOOP,   NOP                     / TOP OF PRINT-STRING LOOP
        TAD I AIX1              / INCREMENT INDEX REG, LOAD AC (2'S COMPLEMENT
                                / ADD INDIRECT)
        SNA                     / SKIP NEXT INSTRUCTION IF AC IS NONZERO
        JMP I [7600             / END OF STRING, RETURN TO OS
                                / NOTE: REPLACE WITH "HLT" IF ON BARE METAL
        JMS PRINT               / OUTPUT CHARACTER ON ACCUMULATOR
        JMP LOOP                / LATHER, RINSE, REPEAT

PRINT,  0                       / TTY OUTPUT ROUTINE. FIRST WORD MUST BE
                                / EMPTY (NULL) BECAUSE THE JUMP TO SUBROUTINE
                                / INSTRUCTION INSERTS THE RETURN ADDRESS HERE.
        TLS                     / WRITE ACCUMULATOR TO THE OUTPUT DEVICE (TTY)
        TSF                     / SKIP NEXT INSTR IF TTY IS READY
        JMP .-1                 / TTY IS NOT READY, CHECK AGAIN (RELATIVE JUMP)
        CLA                     / CLEAR ACCUMULATOR
        JMP I PRINT             / RETURN TO CALLER (INDIRECT JMP TO ADDRESS
                                / STORED IN FIRST WORD OF SUB WHEN CALLED)

MSG,    .                       / 1ST WORD IS ADDRESS OF STRING
        110                     / "H"
        105                     / "E"
        114                     / "L"
        114                     / "L"
        117                     / "O"
        122                     / "R"
        114                     / "L"
        104                     / "D"
        041                     / "!"
        000                     / NULL (END OF STRING)

/ *** TYPE <CONTROL-L> HERE ***

Directly input to the machine language monitor ROM (using hand assembled code)

D 00200 7200,7100,1220,3010,7000,1410,7450,7402
D 00210 4212,5204,0000,6046,6041,5214,7200,5612
D 00220 0220,0110,0105,0114,0114,0117,0122,0114
D 00230 0104,0041,0000
ST 0200

Directly input into the PDP-8 memory using the front panel switch register

SET PC TO:
0200   000 010 000 000
THEN KEY IN:
7200   111 010 000 000
7100   111 001 000 000
1220   001 010 010 000
3010   011 000 001 000
7000   111 000 000 000
1410   001 100 001 000
7450   111 100 101 000
7402   111 100 000 010
4212   100 010 001 010
5204   101 010 000 100
0000   000 000 000 000
6046   110 000 100 110
6041   110 000 100 001
5214   101 010 001 100
7200   111 010 000 000
5612   101 110 001 010
0220   000 010 010 000
0110   000 001 001 000
0105   000 001 000 101
0114   000 001 001 100
0114   000 001 001 100
0117   000 001 001 111
0122   000 001 010 010
0114   000 001 001 100
0104   000 001 000 100
0041   000 000 100 001
0000   000 000 000 000
SET PC TO:
0200   000 010 000 000
THEN TOGGLE "CONT"

Link to my video (YouTube) showing me running all three of the above

Nakazoto commented 10 months ago

Ooooh, very cool! I included this one on the Homebrews page as it's not quite a real PDP-8 and has proper Homebrew vibes to it. Sorry it took so long to get to! https://github.com/Nakazoto/Hellorld/wiki/Homebrew-Computers#dburrs-sbc6120-pdp-8-replica