Hello World in Sam (or Acme)

First of all we have to create a file to work with, so create a new window by right clicking the mouse button and selecting new from the menu. Hold down the right mouse button and drag it across the screen to the size you want your new window (again remember to middle-mouse button click and select scrolling from the green menu – that way the terminal will scroll with your text). You will get the term% prompt and it is here that you want to create the new hello world file. So type in touch helloworld.c.

To check that it exists, you can use ls to see if it was created: Your directory might look similar to what is below.

term%
bin
helloworld.c
readme.acme
readme.reo
sam.save
lib

So lets edit the hello world file in Sam. Start the editor by typing in sam -d filename (the -d option disables mouse editing – and that is the option we want).

sam -d helloworld.c

And lets add some lines to the dot.

a
#include <u.h>
#include <libc.h>
#include <stdio.h>
void main(void){
print("Hello World!\n");
exits(0);
}
.

Now that those lines are in our dot we can check that they are all there OK by printing using ‘p’ and hitting enter. You should get the lines of code that we entered that looks something like this:

#include <u.h>
#include <libc.h>
#include <stdio.h>
void main(void){
print("Hello World!\n");
exits(0);
}

Remember that you can undo what you entered by typing in ‘u’ if you have made a mistake or starting again with ‘c’ to overwrite what is in dot – and if everything went in ok then we can write to our helloworld.c file.

w helloworld.c

And hopefully you will get a status message of what happened – in my case it was:

helloworld.c: #104.

Okay! Now we can compile and run the code that we created. Close the window you were using and check the contents of the helloworld.c file that you created by using ‘cat’ helloworld.c.

term% cat helloworld.c

Now its time to compile it with the Intel compiler and link the code. The Intel compiler is run with the command 8c, and the linker 8l. Other compilers are listed below and you are welcome to use those to generate the object file and the binary file.

      1. term% 8c hellworld.c
      2. term% 8l -o helloworld helloworld.8 
      3. term% helloworld
      4. Hello World!
      5. term%

If you struggle in writing this in Sam, there is an easier option that makes editing files simpler, and that is the acme editor. To run and edit a new file on acme (lets say that its helloworld.c again):
term% acme helloworld.c
Will give you a new acme window where you can edit and write text. When you are finished with that, you can hover the mouse over the “PUT” selection and that will save the file. Then just highlight the “EXIT” selection and middle mouse button click to exit acme. Then run the compiler and the linker against helloworld.c.
Man pages for the C compilers available on plan 9 can be located at http://plan9.bell-labs.com/sys/doc/comp.html and http://plan9.bell-labs.com/sys/doc/compiler.html .
And for Sam there is a reference card that is quite good located here http://plan9.bell-labs.com/sources/contrib/steve/doc/sam-refcard.pdf
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: