CS641 MIPS Cross
compiler setup and first example 1/31/11
Edit
your .profile file to add /usr/local/bin/mips to your PATH, and define cs641
PATH=:/usr/local/bin:/usr/local/bin/mips:/usr/ucb:/bin:/usr/bin:$HOME/bin:.
^^^^^^^^^^^^^^^^^^^ added
export
PATH
cs641=/courses/cs641/public_html
; export cs641
hello1.c: Hello-world in C
with string in data section
extern
int printf(char *s, ...); <--to
avoid #include <stdio.h>
char
msg[] = "Hello, world!";
int
main()
{
printf("%s", msg); This compiles and runs on
Linux
}
sf06.cs.umb.edu$
mips-gcc -S hello1.c <--compile to
assembler for MIPS
sf06.cs.umb.edu$
more hello1.s <-- look at
resulting .s file
.file
1 "hello1.c"
<-- ignore all directives except
.section .mdebug.abi32 <-- .data, .text, .ascii, .globl
.previous
.abicalls
.globl
msg
.data
.align
2
.type
msg, @object
.size
msg, 14
msg:
.ascii
"Hello, world!\000"
.rdata
.align
2
$LC0:
.ascii
"%s\000"
.text
.align
2
.globl
main
.ent
main
.type
main, @function
main:
.frame
$fp,32,$31 # vars= 0,
regs= 2/0, args= 16, gp= 8
.mask
0xc0000000,-4
.fmask
0x00000000,0
.set
noreorder
.cpload $25
.set
reorder
addiu
$sp,$sp,-32 <-- we’ll
tackle this soon, ignore for now
sw
$31,28($sp)
sw
$fp,24($sp)
move
$fp,$sp
.cprestore 16
The code that loads a0 and a1 and calls printf
la
$4,$LC0
la
$5,msg
jal
printf
move
$sp,$fp
lw
$31,28($sp)
lw
$fp,24($sp)
addiu
$sp,$sp,32
j
$31
.end
main
.ident
"GCC: (GNU) 3.4.5"