Computer Organizatin - MIPS Assembly Part 2
Computer Organizatin - MIPS Assembly Part 2
Computer Organizatin - MIPS Assembly Part 2
Tags
1. Chapter Goals
Objectives:
2. Introduction to Instructions
Definition:
The instruction set is the complete list of commands that a computer can
execute.
MIPS Architecture:
Example: add $t0, $t1, $t2 adds the values in $t1 and $t2 and stores the
result in $t0 .
If $t1 = 5 and $t2 = 3 , then after executing add $t0, $t1, $t2 , $t0 will
be 8 .
Comments:
Example: add $t0, $t1, $t2 # Adds $t1 and $t2, stores the result in $t0 .
4. Operands
Registers in MIPS:
Example:
To add two numbers stored in registers: add $s0, $t1, $t2 adds the values
in $t1 and $t2 and stores the result in $s0 .
Having fewer registers can speed up access time. For example, with 32
registers, the design is simpler than architectures with more registers,
such as 64 or 128.
5. Memory Organization
Linear Addressing:
Byte Addressing:
Each memory address points to a single byte. To access a 32-bit word, the
address must be a multiple of 4 (word alignment).
Example:
If you want to access the third word (starting at byte 8), its address must
be 8, 12, 16, etc.
Endianness:
Big-Endian (MIPS): Stores the most significant byte at the lowest address.
Example: lw $t0, 4($s1) loads the word from the address at $s1 + 4 into
$t0 .
Example: sw $t0, 8($s1) stores the value in $t0 to the address at $s1 +
8.
Load/Store Architecture:
MIPS only accesses memory through load and store instructions; all
arithmetic is performed on data in registers.
The base register holds the starting address, and the offset specifies the
distance from that base.
Example: addi $t1, $t2, 10 adds 10 to the value in $t2 and stores the result
in $t1 .
Sign Extension:
AND ( and $t0, $t1, $t2 ): Performs a bitwise AND on $t1 and $t2 , storing
the result in $t0 .
NOR ( nor $t0, $t1, $t2 ): Performs a bitwise NOR (NOT OR).
Shift Operations:
Shift Left Logical ( sll $t0, $t1, 4 ): Shifts $t1 left by 4 bits, filling with
zeroes.
Shift Right Logical ( srl $t0, $t1, 4 ): Shifts $t1 right by 4 bits, filling
with zeroes.
Shift Right Arithmetic ( sra $t0, $t1, 4 ): Shifts right, filling with the sign
bit.
Example:
To clear the least significant 4 bits of a register, use andi $t0, $t1, 0xFFF0 .
9. Instruction Formats
Types of Formats:
R-Format Fields:
op : Opcode (6 bits).
Different formats allow efficient encoding and flexibility while keeping the
instruction length fixed.
Unconditional Branches:
Basic Blocks: