Wednesday, April 24, 2013

A Hello-World program in Unix V6 on the SIMH simulator

In my previous post I've talked about how to get Unix Version 6 to run in the SIMH PDP-11 simulator. Now that you have Unix V6 up and running, there is some nice hacking you can do. Here's the classic "Hello World" program in retro '70s style.

System setup

At this point you should have successfully started up and logged in as root into your Unix V6 system on the SIMH pdp11 simulator. For instructions on how to do that, read here. Once everything is correct, you should be greeted by the root prompt "#".

This where the times of ed

So in Unix V6 we're actually in a pre vi and emacs world. So the standard editor that was available at that time was ed (a so called line editor) which you will find even less intuitive to use than vim or emacs.

So here's how to write a Hello-World C program with ed and compile with cc:

  • I'm just moving in any directory since I had some issues in the root directory. Note that "cd" was known as "chdir" at that time.
  • Open up ed without any parameters.
  • "a" means that you want to go into append mode. Write the code after that.
  • "." signifies the end of append mode. I guess this really was for coding and not writing, because I have no idea how to write an actual point...
  • "w hello.c" write the content to the file hello.c. It outputs the character count.
  • "q" is for quitting the editor.

No backspace...

Note that there was no backspace character at that time. So neither in the editor, nor in the terminal could you delete your mistakes. So you really have to be careful when typing... (It took me several tries to get that screenshot ;-).

However the special characters "#" and "@" had a similar functionality. Use "#" to overwrite your last character and "@" to overwrite your last line. I didn't test them out inside ed though.


I'd sometimes get an "intermediate file error" when compiling and I didn't know what caused it. What solved it for me was moving into the "/etc" directory.

On other times when compiling I would get an error "cannot write to /tmp/something" and I'm also not sure of the cause.

In general I would check with "cat" that my source file is correct. Then since the files are written in the *.dsk files, for troubleshooting I also replaced them by the new downloaded unix *.dsk files to get a clean environment. Hopefully these things help you debugging.

Let me know if you came across other issues! Otherwise, enjoy!

Let me know what you think of this article and where you see room for improvement. I only just started this blog, so feedback of any kind is appreciated!

Related Articles:
Running Unix V6 in the SIMH PDP-11 simulator
Unix in a Nutshell
Prepping for Coding Interviews - Part I

No comments:

Post a Comment