cs3410 Spring 2010 ------------------ Note: This is available from the csug machines in the file /courses/cs3410/README-csug.txt Setting up your shell The csuglab uses "csh" as the the default interactive shell (i.e. the program that is reading and executing the commands you are typing). Most people prefer "bash" instead. Some prefer "tcsh". You can find out which you are currently using by typing: echo $0 and you can switch to any of the others easily by typing, for example (to start using bash): exec bash /courses/cs3410/mipsel-linux/bin/ This directory contains a version of the gcc compiler for MIPS, but that runs on the x86 linux machines available in the csuglab. This is called cross-compiling: the compiler targets a platform (MIPS) different than the one the compiler is running on (x86). * Add this directory to your PATH so that you can easily run the gcc commands. In bash, you can add to your PATH by typing this: export PATH=$PATH:/courses/cs3410/mipsel-linux/bin/ In csh or tcsh, you have to do this instead: setenv PATH ${PATH}:/courses/cs3410/mipsel-linux/bin * Or, just append the whole directory name to the start of each command, like this: /courses/cs3410/mipsel-linux/bin/mipsel-linux-gcc -S foo.c * To avoid having to re-set your PATH manually each time you log in to the csuglab, you can configure your shell to do it automatically every time you log in. These settings won't take effect until you log out and log back in. If you are using bash, type this: cd chmod u+w .bashrc echo 'export PATH=${PATH}:/courses/cs3410/mipsel-linux/bin' >> .bashrc In csh or tcsh, you have to instead do this: cd chmod u+w .cshrc echo 'setenv PATH ${PATH}:/courses/cs3410/mipsel-linux/bin' >> .cshrc Example of using mipsel-linux-gcc: (Everything below assumes you have correctly configured your PATH as described above). Let's create a file test.c containing some C code. In bash, type: echo "int max(int a, int b) { return (a > b) ? a : b; }" >> test.c You can see your C code file like so: cat test.c Then we can compile using mipsel-linux-gcc, stopping at the assembly level: mipsel-linux-gcc -o test.s -S test.c The test.s file (a plain text file) will now contain MIPS assembly code. You can look at it using an editor, or just: cat test.s Or we can compile all the way to the machine code level: mipsel-linux-gcc -o test.o -c test.c The test.o file (a raw binary file) will now contain MIPS machine code as an object file. You won't see much in a text editor, just some garbled data. You can use the mipsel-linux-nm or mipsel-linux-objdump commands to examine the object file: mipsel-linux-objdump --syms test.o You an use PuTTY or SCP to upload other C files and download the resulting mips code. Or you can learn to use one of the text editors available. For beginners, try the "nano" editor, like so: nano test.c