// My first program void main() { printString("Hello world.\n"); }The Cebollita compiler compiles a language called C--. Not suprisingly, C-- looks a lot like C. Roughly speaking, C-- is a subset of the C programming language. For more details on what you can and can't do with C--, see the specification.
Now compile the program:
prompt %java comp.Scc hello.cThe above step translated your C-- source code to MIPS assembly code. You might want to have a look at the file that was created. If all went well, it should be called hello.s.
void printString(char* str); void printInt(int x); int readString(char* buffer, int length); int readInt();You'll have to compile the source code for this module (currently it lives in the tests directory) as well:
prompt %java comp.Scc tests/iolib.c
prompt %java asm.Asm hello.s prompt %java asm.Asm tests/iolib.s prompt %java asm.Asm tests/prologue.sThis should have produced three files: hello.o, tests/iolib.o, and tests/prologue.o. From now on, you should never have to recompile or reassemble the iolib or the prologue file, unless you feel compelled to change them for some reason.
prompt %java asm.Linker tests/prologue.o hello.o tests/iolib.oThis should produce a file called a.out, your first Cebollita executable.
prompt %java sim.UI a.outA window should pop up and you can hit the run button. You should see the message printed to the console where you started the program. See the Cebollita MIPS Simulator document for more information on the simulator, and its console based cousin...
prompt %java asm.Module hello.oTry it. What do you see? The other utility lets you inspect whole executables:
prompt %java util.Exe a.outTry it and have a look at the output.
int fib(int n) { printString("Calculating fib of: "); printInt(n); printString("\n"); if (n == 1) { return 0; } if (n == 2) { return 1; } else { return fib(n-1) + fib(n-2); } } void main() { printInt(fib(6)); }
The answer is that the toolset was designed and presented to you in this manner to expose you to the things that are normally hidden by modern development environments. We wanted to make the steps taken en camera by integrated development environments explicit. We did it not to make life hard, but to help people learn things.
Obviously, the next step would be for you to (a) write your own simple development environment or (b) to learn a little about Makefiles to cobble together these steps as needed. We prefer the latter approach, and in fact Cebollita ships with a simple Makefile that you can look at to get you started down this path.