8/7/2019 Basics of the Instruction Set Architecture
1/21
BasicsInstruction Set Architecture
Panickos Neophytou
Recitation 1 09/07/2005
09/12/2005
CS0447: Computer Organization and
Assembly
Link for this presentation:
www.cs.pitt.edu/~panickos/classes/cs0447/Basics.ppt
8/7/2019 Basics of the Instruction Set Architecture
2/21
Contact info
Panickos Neophytou
Office 6514 Sennott Square Office Hours: Monday 2:30-5:30 & Tuesday 3:45-6:45
Email [email protected] (use cs0447 anywhere in the
subject to get my attention) TAs course web page
www.cs.pitt.edu/~panickos/classes/cs0447 (underconstruction BUT available)
8/7/2019 Basics of the Instruction Set Architecture
3/21
Outline
Decimal to Binary conversions
Binary to Hexadecimal conversions Instruction Set Architecture
SPIM
8/7/2019 Basics of the Instruction Set Architecture
4/21
Decimal to Binary conversions
Example 1 - (Convert Decimal 44 to Binary)
8/7/2019 Basics of the Instruction Set Architecture
5/21
Decimal to Binary conversions
Example 2 - (Convert Decimal 15 to Binary)
8/7/2019 Basics of the Instruction Set Architecture
6/21
Decimal to Binary conversions
Example 3 - (Convert Decimal 62 to Binary)
8/7/2019 Basics of the Instruction Set Architecture
7/21
Binary to Hexadecimal conversions
In the Hexadecimal
system you have 16symbols to representnatural numbers.
Dec. Hex Dec. Hex
0 0 8 81 1 9 9
2 2 10 A
3 3 11 B
4 4 12 C
5 5 13 D
6 6 14 E
7 7 15 F
8/7/2019 Basics of the Instruction Set Architecture
8/21
Binary to Hexadecimal conversions
Convert the following Hex number to Binary:
286F A3E1
Convert the following Binary number to
Hexadecimal: 0101 0011 1111 0110 1011 1010 0001 1100
8/7/2019 Basics of the Instruction Set Architecture
9/21
Instruction Set Architecture
op Operation code
rs First source register operand
rt Second source register operand
rd Destination register operand
shamt Shift amount - used in shift instructions
funct Select the variant of the operation in the op code field
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
8/7/2019 Basics of the Instruction Set Architecture
10/21
Instruction Set Architecture
Specific Instruction Formats
Format 6 bits 5 bits 5 bits 5 bits 5 bits 6 bits Comments
R op rs rt rd shamt funct Arithmetic
I op rs rt address/immediateTransfer,
branch,immediate
J op target address Jump
8/7/2019 Basics of the Instruction Set Architecture
11/21
Instruction Set Architecture
Arithmetic Instructions
Instruction Example Meaning Comments
add add $1,$2,$3 $1=$2+$3 Always 3 operands
subtract sub $1,$2,$3 $1=$2-$3 Always 3 operands
add immediate addi $1,$2,10 $1=$2+10 add constant
add unsigned addu $1,$2,$3 $1=$2+$3 Always 3 operations
subtract unsigned subu $1,$2,$3 $1=$2-$3 Always 3 operations
add immed.unsigned addiu $1,$2,10 $1=$2+10 Always 3 operations
8/7/2019 Basics of the Instruction Set Architecture
12/21
Instruction Set Architecture
Logical
Instruction Example Meaning Comments
and and $1,$2,$3 $1=$2&$3 3 register operands
or or $1,$2,$3 $1=$2|$3 3 register operands
and immediate andi $1,$2,10 $1=$2&10 AND constant
or immediate or $1,$2,10 $1=$2|10 OR constant
shift left logical sll $1,$2,10 $1=$210 Shift right by constant
8/7/2019 Basics of the Instruction Set Architecture
13/21
Instruction Set Architecture
Data Transfer
Instruction Example Meaning Comments
load word lw $1,10($2) $1=Memory[$2+10] memory to register
store word sw $1,10($2) Memory[$2+10]=$1 register to memory
load upperimmed.
lui $1,10 $1=10x2^16load constant into upper16 bits
8/7/2019 Basics of the Instruction Set Architecture
14/21
Instruction Set Architecture
Conditional Branch
Instruction Example Meaning Comments
branch on equal beq $1,$2,10if($1==$2)go toPC+4+10
Equal test
branch on notequal bne $1,$2,10
if($1!=$2)go toPC+4+10 Not equal test
set on less then slt $1,$2,$3if($2
8/7/2019 Basics of the Instruction Set Architecture
15/21
Instruction Set Architecture
Unconditional Jump
Instruction Example Meaning Comments
jump j 1000 go to 1000 Jump to target address
jump register jr $31 go to $31 For switch, procedure return
jump and link jal 1000 $31=PC+4;go to 1000 For procedure call
8/7/2019 Basics of the Instruction Set Architecture
16/21
SPIM
Spim is a self-contained simulator that will
run MIPS32 assembly language programs. Freeware
Can be downloaded and installed ontoWindows or Unix based machines from:
http://www.cs.wisc.edu/~larus/spim.html
Will be used for assignments
8/7/2019 Basics of the Instruction Set Architecture
17/21
SPIM
Registers
Instructions
LoadedData
Output
8/7/2019 Basics of the Instruction Set Architecture
18/21
SPIM -Assembler Syntax
Program includes .data and .text
Comments begin with #. Rest of line is ignored.
Identifier names are sequence of letters, numbers, underbars (_) and dots (.).
Labels are declared by putting them at beginning of line followed by colon. Uselabels for variables and code locations.
Instruction format: op field followed by one or more operands: addi $t0, $t0, 1
Operands may be literal values or registers.
Register is hardware primitive, can stored 32-bit value: $s0
Numbers are base 10 by default. 0x prefix indicates hexadecimal.
Strings are enclosed in quotes. May include \n=newline or \t=tab. Used for prompts.
8/7/2019 Basics of the Instruction Set Architecture
19/21
SPIM
Simple Example:
# SPIM Code to print hello world# a comment starts with a till the end of the line
.data # start putting stuff in the data segment
greet: .asciiz Hello world\n # declare greet to be the string
.text # start putting stuff in the text segment
main: # main is a label here. Names a function
li $v0, 4 # system call code for print_str
la $a0, greet # address of string to printsyscall # print the stringjr $ra # return from main
# here li is load immediate into an integer register
# la is load computed address into an integer register
# jr is standard return from function call...$ra contains return address
8/7/2019 Basics of the Instruction Set Architecture
20/21
SPIM
Modify the program by adding these
instructions: addi $10, $10, 4
addi $11, $11, 28
add $12, $10, $11
Use the step option (from the Simulatormenu) of SPIM to watch your programsexecution step-by-step.
8/7/2019 Basics of the Instruction Set Architecture
21/21
MIPS Basics
Implementing Conditional Statements
if ( i == j )
i++;
j--;
bne $r1, $r2, L1 # branch if ! ( i == j )
addi $r1, $r1, 1 # i++
L1: addi $r2, $r2, -1 # j--
if ( i == j )
i++;
elsej--;
j += i ;
bne $r1, $r2, ELSE #branch if !( i == j )
addi $r1, $r1, 1 # i++
j L1 # jump over elseELSE: addi $r2, $r2, -1 # j
L1: add $r2, $r2, $r1 # j += i
Top Related