25.12.2012 Views

MIPS Assembly Language Programming

MIPS Assembly Language Programming

MIPS Assembly Language Programming

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 2<br />

<strong>MIPS</strong> Tutorial<br />

by Daniel J. Ellard<br />

This section is a quick tutorial for <strong>MIPS</strong> assembly language programming and the<br />

SPIM environment 1 . This chapter covers the basics of <strong>MIPS</strong> assembly language, including<br />

arithmetic operations, simple I/O, conditionals, loops, and accessing memory.<br />

2.1 What is <strong>Assembly</strong> <strong>Language</strong>?<br />

As we saw in the previous chapter, computer instructions can be represented as<br />

sequences of bits. Generally, this is the lowest possible level of representation for a<br />

program– each instruction is equivalent to a single, indivisible action of the CPU.<br />

This representation is called machine language, since it is the only form that can be<br />

“understood” directly by the machine.<br />

A slightly higher-level representation (and one that is much easier for humans to<br />

use) is called assembly language. <strong>Assembly</strong> language is very closely related to machine<br />

language, and there is usually a straightforward way to translate programs written<br />

in assembly language into machine language. (This algorithm is usually implemented<br />

by a program called the assembler.) Because of the close relationship between ma-<br />

1 For more detailed information about the <strong>MIPS</strong> instruction set and the SPIM environment, consult<br />

chapter 4 of this book, and SPIM S20: A <strong>MIPS</strong> R2000 Simulator by James Larus. Other<br />

references include Computer Organization and Design, by David Patterson and John Hennessy<br />

(which includes an expanded version of James Larus’ SPIM documentation as appendix A), and<br />

<strong>MIPS</strong> R2000 RISC Architecture by Gerry Kane.<br />

17

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

Saved successfully!

Ooh no, something went wrong!