Chapter - 02 - 123
Chapter - 02 - 123
5
Edition
th
Chapter 2
Instructions: Language of
the Computer
§2.1 Introduction
Instruction Set
The repertoire of instructions of a
computer
Different computers have different
instruction sets
But with many aspects in common
Early computers had very simple
instruction sets
Simplified implementation
Many modern computers also have simple
instruction sets
Chapter 2 — Instructions: Language of the Computer — 2
The MIPS Instruction Set
Used as the example throughout the book
Stanford MIPS commercialized by MIPS
Technologies (www.mips.com)
MIPS – Microprocessor without Interlocked
Pipeline Stages
Large share of embedded core market
Applications in consumer electronics, network/storage
equipment, cameras, printers, …
Typical of many modern ISAs
x x 1111...111 2 1
x 1 x
Example: negate +2
+2 = 0000 0000 … 00102
–2 = 1111 1111 … 11012 + 1
= 1111 1111 … 11102
Instruction fields
op: operation code (opcode)
rs: first source register number
rt: second source register number
rd: destination register number
shamt: shift amount (00000 for now)
funct: function code (extends opcode)
0 17 18 8 0 32
000000100011001001000000001000002 = 0232402016
k -s0
v[0] -s1
e.g., for case/switch statements
Result in $v0
Result in $v0
https://medium.com/@williambdale/recursion-the-pros-and-cons-76d32d75973a
Non-Leaf Procedure Example
MIPS code:
fact:
addi $sp, $sp, -8 # adjust stack for 2 items
sw $ra, 4($sp) # save return address
sw $a0, 0($sp) # save argument
slti $t0, $a0, 1 # test for n < 1
beq $t0, $zero, L1
addi $v0, $zero, 1 # if so, result is 1
addi $sp, $sp, 8 # pop 2 items from stack
jr $ra # and return
L1: addi $a0, $a0, -1 # else decrement n
jal fact # recursive call
lw $a0, 0($sp) # restore original n
lw $ra, 4($sp) # and return address
addi $sp, $sp, 8 # pop 2 items from stack
mul $v0, $a0, $v0 # multiply to get result
jr $ra # and return
i in $s0
lui $s0, 61 0000 0000 0111 1101 0000 0000 0000 0000
ori $s0, $s0, 2304 0000 0000 0111 1101 0000 1001 0000 0000
op rs rt constant or address
6 bits 5 bits 5 bits 16 bits
PC-relative addressing
Target address = PC + offset × 4
PC already incremented by 4 by this time
Chapter 2 — Instructions: Language of the Computer — 55
Jump Addressing
Jump (j and jal) targets could be
anywhere in text segment
Encode full address in instruction
op address
6 bits 26 bits
Reference: https://homepage.divms.uiowa.edu/~ghosh/4-27-06.pdf
MIPS register conventions
Static linking
Indirection table
Linker/loader code
Dynamically
mapped code
Simple portable
instruction set for
the JVM
Compiles
Interprets
bytecodes of
bytecodes
“hot” methods
into native
code for host
machine
1.5
0.5
0
C/ none C/ O1 C/ O2 C/ O3 J ava/ int J ava/ J IT
1.5
0.5
0
C/ none C/ O1 C/ O2 C/ O3 J ava/ int J ava/ J IT
2000
1500
1000
500
0
C/ none C/ O1 C/ O2 C/ O3 J ava/ int J ava/ J IT