Anda di halaman 1dari 5

Lab 1 (Sections 501 and 502) Prelab: Introduction to

MIPS instructions

Name:

Your Name

Sign the following statement:

On my honor, as an Aggie, I have neither given nor received unauthorized


aid on this academic work

Type Name

1 Objective

The main objective of this prelab is to familiarize you with several basic MIPS instructions
and their appropriate encoding formats.

2 Prerequisites

Before proceeding, you should learn basic MIPS instructions such add, sub, addi, lw, sw
and their appropriate formats (refer to Sections 2.2-2.5 of the text book).

3 Introduction

Before commanding a computer’s hardware, you must speak its language. The words of a
computer language are called instructions, and its vocabulary is called an instruction set.
For example, the following add instruction tells a computer to add the two variables b and
c and store the result in a.

add a, b, c

1
Computer Architecture and Design, PreLab 1 2

In this lab, we will explore several instructions in the MIPS instruction set and under-
stand their encoding formats.

4 Instruction encoding

Instructions inside the computer are represented as a series of ones and zeros (binary digits).
For example the instruction add $t0, $s1, $s2 is encoded as:

000000 10001 10010 01000 00000 100000


6bits 5bits 5bits 5bits 5bits 6bits

Each of these segments of an instruction is called a field. The first and last fields in com-
bination tell the MIPS computer that this instruction performs addition. The second field
specifies the number of the register which corresponds to the first source operand of the ad-
dition operation (17 = $s1). The third field specifies the second source operand (18 = $s2),
and the fourth field specifies the register to hold the result (8 = $t0). The fifth field is
unused in this instruction, so it is set to 0.
This layout of the instruction is referred to as instruction format. In MIPS, the size of each
instruction is exactly of 32 bits. The instruction format in MIPS can be categorized as
register (R), immediate (I ), or jump (J ). The above example is an R-format instruction.
For this lab, we will concentrate on the register (R) and immediate (I ) formats.

Note: A word is defined as the unit of access in a computer. In MIPS, all data and
instruction accesses are 32-bits and hence a 32-bit value is called a word in MIPS.

Most of the processors have a restriction on the alignment of data. In MIPS, we have
this alignment restriction; words in MIPS must start at addresses that are multiples of 4.
For the following questions, feel free to use the MIPS reference card that can be found
on the last page.

5 Questions

1. Write down the representation of R- and I-format instructions. Explain the purpose
of each field in the instruction.
Computer Architecture and Design, PreLab 1 3

2. Which of the following are Register or Immediate type instructions? Place the ap-
propriate letter (R or I) next to them:

sub andi beq


lw slt srl

3. Write the binary encoding for the following instructions. Clearly indicate the different
fields in the encoding.

add $s1,$s2,$s3

addi $s1, $s2,40

sub $s6,$s7,$t3

4. Translate the following high-level code into assembly language. Assume variables
a − c are held in registers $s0 − $s2 and f − j are in $s3 − $s7

a=b-c;
f=(g+h)-(i+j);

5. Write an assembly program to swap the contents of 2 variables stored in registers $4


and $5.
Computer Architecture and Design, PreLab 1 4

6. Read the tutorial on the SPIM tool. In lab we will be using QtSpim, which is an
updated version of PCSPIM. This tutorial can be found at http://pages.cs.wisc.
edu/~larus/PCSpim.pdf or in the CD-ROM that comes with your textbook. You
can install QtSpim on your computer to get better understanding of the simulator.
I have read the SPIM tutorial .
Computer Architecture and Design, PreLab 1 5

Anda mungkin juga menyukai