Hacker News new | past | comments | ask | show | jobs | submit login
Unix Programmer's Manual, First Edition (1971) (bell-labs.com)
119 points by segfaultbuserr on Jan 29, 2021 | hide | past | favorite | 16 comments



TIL the "switch" keyword in C was originally a PDP-11 assembly helper subroutine in the Unix system library (this was written before the invention of C). It explains everything about C's behavior.

    NAME   switch -- switch on value

    SYNOPSIS     (switch value in r0)
                 jsr r5,switch; 
                 swtab
                 (not—found return)

                     swtab: val1; lab1;

                 valn; labn
                 ..; 0

    DESCRIPTION  switch compares the value of r0 against each 
                 of the vali; if a match is found, control is
                 transferred to the corresponding lab. (after
                 popping the stack once). If no match has been
                 found by the time a null labi occurs, switch
                 returns.


And I think that this switch subroutine mirrors one way of compiling the BCPL switchon statement (on which C's switch statement was explicitly modelled), though the BCPL compiler I used in the mid-1970s was smarter if the cases formed a compact integer sequence.

C was based upon B, which was based upon BCPL. Clearly, the Bell Labs crew were trying to give themselves some BCPL goodness, even in assembly language.


And BCPL was desiged as very thin language just to be good enough to write the CPL compiler, it was never planned to be used to write full applications.

Bootstrap CPL.


BCPL (1967), B (1969), PDP-11 (1970), C (1972).


Here you can read the source code of first edition unix:

https://minnie.tuhs.org/cgi-bin/utree.pl?file=V1

Where can we learn the PDP assembly to be able to understand these historical source code?


Read the official manual - PDP-11/40 Processor Handbook.

https://pdos.csail.mit.edu/6.828/2005/readings/pdp11-40.pdf

The PDP-11 instruction set is small and elegant.


From the manual:

> The PDP-11/40 was designed to fit a broad range of applications, from small stand alone situations ... to large multi-user, multi-task applications requiring up to 124K of addressable memory space.

I'm young, and it's crazy to look back and see how far we've come.


For some context, the PDP-11/40 debuted in 1973, and was $40k in 1973 dollars which is $233k inflation adjusted for today.

There wasn't much available for a "home computer" at the time, but the Kenbak-1 might be a good example for comparison of what one would have cost. It was $750, or $4400 inflation adjusted. It had 256 bytes of memory.


> The PDP-11 instruction set is small and elegant.

Scared PDP-endianess sounds...


It's little-endian, same as x86.


I thought on the PDP-11 bytes in a 16 bit word were stored little endian but the 16 bit words in a 32 bit long were stored the other way around so it's a bit of both?


Words are little-endian but the two halves of a long are big-endian. In consistently little-endian, a 32-bit quantity would be stored with the 1's, 256's, 65536's, and 16777216's place bytes in that order, but the PDP-11 puts them in the order 65536 16777216 1 256.


And here's a (big!) project that aims to reconstruct a complete source history from the current FreeBSD all the way back to 1970 Unix.

https://github.com/dspinellis/unix-history-repo


https://en.wikipedia.org/wiki/MACRO-11

and linked from that page

http://bitsavers.trailing-edge.com/pdf/dec/pdp11/rsx11/RSX11...

There are probably better references, but that's what I found in a quick look.



If you want something still usable nowadays, get Unix Programming Environment, and "The C Programming Languge, 2nd Edition". Both complement each other really well.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: