ch2 PDF
ch2 PDF
Instructions: Language
of the Computer
HW#1:
1.3 all, 1.4 all, 1.6.1, 1.14.4, 1.14.5, 1.14.6, 1.15.1, and 1.15.4
Due date: one week.
Practice:
1.5 all, 1.6 all, 1.10 all, 1.11 all, 1.14 all, and1.15 all
§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
op rs rt rd sa funct R format
op rs rt immediate I format
0 17 18 8 0 0x22
35 19 8 2410
Memory
2410 + $s3 = 0xf f f f f f f f
0x120040ac
0x0000000c
0x00000008
0x00000004
0x00000000
Dr. Yahya Tashtoush
data word address (hex)
Byte Addresses
Since 8-bit bytes are so useful, most architectures
address individual bytes in memory
Alignment restriction - the memory address of a
1011 1101 -3
0101
1110 -2
and add a 1 1111 -1
and add a 1
0000 0
1010 0001 1
0110
0010 2
complement all the bits 0011 3
0100 4
0101 5
0110 6
23 - 1 = 0111 7
2s-Complement Signed Integers
Given an n-bit number
n1 n2
x xn12 x n 2 2 x12 x0 2
1 0
x x 1111...1112 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
lhi $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
Dr. Yahya Tashtoush
Jump Control Flow Instructions
MIPS also has an unconditional branch instruction or
jump instruction:
j label #go to label
00
32
4
PC 32
Static linking