Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

MIPS Instruction Set: Decisions and Logical Operations, Study notes of Computer Science

An overview of various decisions and logical operations in the mips instruction set. Topics include shifting and branching, logical operations such as and, or, and not, and data transfer instructions. The document also discusses the use of constant values and the lack of a not operation, as well as conditional branches and compiling if-then-else and while loops.

Typology: Study notes

Pre 2010

Uploaded on 08/19/2009

koofers-user-fs2
koofers-user-fs2 🇺🇸

10 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS240 Computer Organization
Department of Computer Science
Wellesley College
Decisions
Shifting and branching
Programmer’s cheer
Shift to the left
Shift to the right
Pop up
Push down
Byte, byte, byte
3-2 Decisions
pf3
pf4
pf5

Partial preview of the text

Download MIPS Instruction Set: Decisions and Logical Operations and more Study notes Computer Science in PDF only on Docsity!

CS240 Computer Organization

Department of Computer Science

Wellesley College

Decisions

Shifting and branching

Programmer’s cheer

Shift to the left

Shift to the right

Pop up

Push down

Byte, byte, byte

Decisions 3-

Logical operations

add add $s1,$s2,$s3 $s1=$s2 + $s

Arithmetic subtract sub $s1,$s2,$s3 $s1=$s2 - $s

add immediate addi $s1,$s2,100 $s1=$s2 + 100

and and $s1,$s2,$s3 $s1=$s2 & $ s

or or $s1,$s2,$s3 $s1=$s2 | $s

nor nor $s1,$s2,$s3 $s1=~($s2 | $s3)

Logical and immediate andi $s1,$s2,100 $s1=$s2 & 100

or immediate ori $s1,$s2,100 $s1=$s2 | 100

sll sll $s1,$s2,10 $s1=$s2 << 10

srl srl $s1,$s2,10 $s1=$s2 >> 10

Data transfer load word lw $s1,100($s2) $s1=Mem[$s2+100]

store word sw $s1, 100($s2) Mem[$s2+100]=$s

Decisions 3-

sll $t2, $s0, 4

op rs rt rd shamt funct

000000 00000 10000 01010 00100 00000

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

*R-type (for register) or R-format.

Decisions 3-

Alas, no NOT

o In keeping with the two-operand format, the

designers of MIPS decided against a NOT

operation.

o A NOR operation is offered in consolation.*

nor $t0, $t1, $t2 # $t0 = ~($t1 | $t3)

*How does this help?

Decisions 3-

Conditional branches

o MIPS includes two decision-making instructions

similar to the infamous “if with goto”.

o Branch if equal:

beq register1, register2, label

o Branch if not equal:

beq register1, register2, label

Decisions 3-

Compiling if-then-else clauses

o Let’s try an easy one

if (i == j)

f = g + h;

else

f = g - h;

o We assume variable f to j

correspond to registers

$s0 to $s4.

i==j?

i=j

i≠j

Else:

f=g-h f=g+h

Exit:

Decisions 3-

Compiling while loops

o One only slightly harder

while (save[i] == k)

i += 1;

o We assume that i and k

correspond to registers

$s3 and $r5 and the base

address of save is in $s6.

$t1==k?

$t1=k

$t1≠k

i+=

Exit:

calc addr

of save[i]

ld to $t

Loop:

Decisions 3-