The MIPS is a RISC microprocessor. It is small, powerful, and standard on many embedded system and advanced computing systems (Corporations such as SGI, NEC and MIPS technology still produced them in large quantities). The MIPS assembly often frustrates new users with its unfamiliar sequence of operation. Hereby I provide a startup kit for the newbies to quickly master the art of programming MIPS processors in assembly. Entering the MIPS WorldFirst, we start with a simple assembly file and show how it could be compiled in the R2000 format in a R10000 plus machine equipped with IRIX operating system. Users who doesn't have a MIPS machine at hand can use the freely available SPIM (with X Window and Windows support) to simulate MIPS R2000. .ent main We named this file as "test.s" which does do anything other then adding two general register ($2, $3) together and store the result into another register ($4). Other than that, there are two menomics for assembly language including the ".ent" and ".end" command denoting the begining and end of an function object (entity). After that, we can assembly it and link it into an executable ELF file. Here is the command sequence: as -mips1 test.s -n32 -o test_4.o ld -L/usr/lib32/mips4 -L/usr/lib32 /usr/lib32/mips4/crt1.o test_4.o -lc /usr/lib32/mips4/crtn.o Some brief explanation: "as" is the standalone assembler provided by the SGI MIPS C compiler suite. We use "-mips1" to generate the R2000 compatible code which are easier to analyze. R2000 is the standard RISC processor covered in computer architecture textbook. Then -n32 generate a (new) 32-bit object which are required for the (new) linker editor we used. This will produce a warning since (new) object are usually used together with "-mips3" or "-mips4". Then you can play around with these compiled executable file and object file with the following useful command. nm test_4.o It prints out the symble table of this object file. Also you can disassemble this object file by dis test_4.o How to build a MIPS crosscompiler using GNU toolchain (gcc)?Here I show how to build a cross tool chain for a little endian mips-linux target on x86-linux host. The procedure is basically borrowed from Wei Qin's description on how to build a GNU toolchain on ARM . Decide where are you going to put in your source, build directory and the installlation directory. Step 1: Build the binutils cd $SRC_DIR Add $PREFIX/bin to your current PATH. In bash, this is Step 2 -- Build gccSUBSTEP1 -- Configure linux kernel to get header files (we use the CVS server of MIPS-linux)cd $SRC_DIR SUBSTEP2 -- Build gcccd $SRC_DIR cd $BUILD_DIR Edit the file "tconfig.h" in "$BUILD_DIR/gcc" cd $BUILD_DIR Ignore the error message saying that the built C compiler cannot produce executables. make install SUBSTEP3 -- Unpack glibccd $SRC_DIR STEP4 -- Build glibcSet environmental variable CC as mips-unknow-linux-gcc, in bash Clear LD_LIBRARY_PATH, in bash, this is cd $BUILD_DIR make Reference on MIPSA good tutorial from a class . A Quick Start on MIPS Assembly . MIPS Programming Book containing a lot of examples. Class Notes on MIPS programming Very good . Some Books as well. I recommend the classic: MIPS RISC Architecture and a newer book See MIPS Run . |