25.12.2012 Views

MIPS and SPIM tutorial

MIPS and SPIM tutorial

MIPS and SPIM tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

loop.s<br />

.text<br />

.globl main<br />

main: add $t0, $zero, $zero # loop counter i<br />

addi $s0 ,$zero, 5 # loop limit N<br />

You should be<br />

loop: beq $t0, $s0, done # for i = 0...(N-1)<br />

Choose<br />

descriptive<br />

names for<br />

your labels.<br />

able to<br />

underst<strong>and</strong><br />

what the<br />

add $a0, $zero, $t0 # print i<br />

# system program call code does for print_int<br />

li by $v0, only 1 looking<br />

syscall<br />

at the<br />

comments <strong>and</strong><br />

the labels.<br />

addi $t0, $t0, 1 # i ++<br />

Example of good comments<br />

j loop # loop again<br />

done: jr $ra # return to caller<br />

Introduce<br />

abstractions<br />

in your<br />

comments.<br />

Refer to<br />

previously<br />

defined.<br />

abstractions.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!