MIPS Instructions: Operations, Operands, and Examples, Lab Reports of Computer Science

The basics of mips instructions, focusing on operations and operands. It covers various types of mips operations, such as arithmetic, logical, shift, compare, load/stores, and branch/jump operations. Additionally, it discusses mips operands, including general-purpose registers, fixed registers, memory locations, and immediate values. The document also includes examples and exercises to help students understand the concepts.

Typology: Lab Reports

Pre 2010

Uploaded on 09/02/2009

koofers-user-4ho-1
koofers-user-4ho-1 🇺🇸

9 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
1
MIPS Operations/Operands
“Operation” (instruction) – Produces a value from one or more input values
“Operand” -Input or Output values for an operation
MIPS operations
Arithmetic operations (integer/floating-point) (add, sub,…)
Logical operations (and, or,…)
Shift operations (shift a certain number of bits to the left or right)
Compare operations (do something if one operand is less than another,…)
Load/stores to transfer data from/to memory
Branch/jump operations
System control operations/coprocessor operations
Question: Check on the green card. What is the mnemonic for a shift
logical left instruction? ___sll_____
MIPS operands
General-purpose registers: Question: name 2 of these_____$t0, $s3_____
Fixed registers, e.g., HI/LO registers
Memory location
Immediate value
Question: we saw this instruction in lecture: addi $t3,$zero,4. $t3 is the
destination. addi is the mnemonic for the instruction. $zero is an operand,
and 4 is an operand. What type of operand is $zero? (pick from the above
list):__Fixed register, since it always contains 0_ What type of operand is
4?__immediate__ What do you think “i” stands for in “addi”?_immediate_
2
MIPS Arithmetic
Arithmetic Type Instruction:
<op> <rdestination> <rsource1> <rsource2>
All arithmetic instructions have 3 operands
Operand order is fixed: destination first
32 registers (page 2 of green card)
Question: What number is $t3?__11_ What number is $s3?__19___
Examples
add $t0, $s0, $s2 # $t0 = $s0 + $s2
sub $s0, $t0, $t1 # $s0 = $t0 – $t1
Question: In the sub instruction, which register is rd?_$s0_ Which
register is rs?__$t0___ Which register is rt?__$t1___
rd rs rt
rd rs rtrd rs rt
rd rs rt
Operands
pf3
pf4
pf5

Partial preview of the text

Download MIPS Instructions: Operations, Operands, and Examples and more Lab Reports Computer Science in PDF only on Docsity!

1

MIPS Operations/Operands

  • “Operation” (instruction) – Produces a value from one or more input values
  • “Operand” -Input or Output values for an operation
  • MIPS operations
    • Arithmetic operations (integer/floating-point) (add, sub,…)
    • Logical operations (and, or,…)
    • Shift operations (shift a certain number of bits to the left or right)
    • Compare operations (do something if one operand is less than another,…)
    • Load/stores to transfer data from/to memory
    • Branch/jump operations
    • System control operations/coprocessor operations
  • Question: Check on the green card. What is the mnemonic for a shift logical left instruction? ___sll_____
  • MIPS operands
    • General-purpose registers: Question: name 2 of these_____$t0, $s3_____
    • Fixed registers, e.g., HI/LO registers
    • Memory location
    • Immediate value
    • Question: we saw this instruction in lecture: addi $t3,$zero,4. $t3 is the destination. addi is the mnemonic for the instruction. $zero is an operand, and 4 is an operand. What type of operand is $zero? (pick from the above list):_Fixed register, since it always contains 0 What type of operand is 4?immediate What do you think “i” stands for in “addi”?immediate

2

MIPS Arithmetic

• Arithmetic Type Instruction:

• All arithmetic instructions have 3 operands

  • Operand order is fixed: destination first
  • 32 registers (page 2 of green card)
  • Question: What number is $t3?__ 11 _ What number is $s3?__ 19 ___

• Examples

  • add $t0, $s0, $s2 # $t0 = $s0 + $s
  • sub $s0, $t0, $t1 # $s0 = $t0 – $t
  • Question: In the sub instruction, which register is rd?$s0 Which register is rs?$t0_ Which register is rt?$t1_

rdrdrdrd rsrsrsrs rtrtrtrt

Operands

3

General-Purpose Registers

  • GPR: all can be used as operands in instructions
  • Still, conventions and limitations exist to keep GPRs from being

used arbitrarily

  • r0, termed $zero, always has a value “0”
  • r31, termed $ra (return address), is reserved for subroutine call/return
  • Etc. (we’ll see other conventions/limitations later)
  • Register usage and related software conventions are summarized in “application binary interface” (ABI), which is important when writing system software such as an assembler and a compiler
  • Question: Check the green card: what is the calling convention for

$t0-$t7?__Temporaries _ Note that these conventions are part of

the ABI mentioned above. What does ABI stand for?__Application

Binary Interface__

4

Question: R-Format Example

• add $8,$9,$

Translate the above instruction.Specifically: Look up “add” on

green card. As you can see, “add” is R format.

Look up the R format and the opcode/funct values for add.

Then, fill in the tables and the underline below.

Binary number per field representation (use the right

# of bits!):

Decimal number per field representation:

hex representation: __0x012A

0 1 2 A 4 0 2 0

Answer: Exercise

Which instruction has same representation as 35ten?

A. add $0, $0, $

B. subu $s0,$s0,$s

C. lw $0, 0($0)

D. addi $0, $0, 35

E. subu $0, $0, $

F. Trick question! Instructions are not numbers.

(yes they are!!!)

Answer is E. Note: Registers numbers and names: 0: $0, 8: $t0, 9:$t1, …,16: $s0, 17: $s1, …, Note: Opcodes and function fields add: opcode = 0, function field = 32 subu: opcode = 0, function field = 35 addi: opcode = 8 lw: opcode = 35

Answer: Exercise

• What values are placed into $t0, $t1, $t5 and

$t4 by the following pieces of code?

addi $t0,$0,0xA23 $t0=

addi $t1,$0,0x80001B42 $t1=

and $t4,$t0,$t1 $t4=

or $t5,$t0,$t1 $t5=

9

.data # sample0.asm .word c: 3 k: 5 .text la $t0,c # address of c la $t1,k # address of k lw $s0,0($t0) # load the contents of c lw $s1,0($t1) # load the contents of k slt $s3,$s0,$s1 # if $s0 < $s1 then $s3 = 1; else $s3 = 0 beq $s3,$0,notless #if $s3 == 0: go to notless; o/w just go to the next instruction sw $s0,0($t1) #store contents of c into k sw $s1,0($t0) #store the contents of k into c notless:

the end of the code; we just stop here

QUESTION : So, what did we do in this program?

If c < k then we swapped their values. If not, we just left them alone.

Sample Program