Académique Documents
Professionnel Documents
Culture Documents
Febrero 2013
Tek
Instructions: Language of the Computer
Introduction
Application
programs
Software
• Architecture:
the programmer’s view of the Operating
device drivers
Systems
computer
instructions
– Defined by instructions (operations) Architecture
registers
and operand locations
Micro- datapaths
architecture controllers
adders
Logic
memories
Analog amplifiers
Circuits filters
transistors
Devices
diodes
Physics electrons
Instructions: Language of the Computer
Overview
# Exit
Program Termination
• Unlike the high-level languages you are accustomed to,
assembly does not include a block syntax to indicate the
program termination.
# Program ends
.end #
• MIPS assemblers support standard symbolic names for the general-purpose registers:
<opcode> <dest>, <leftopnd>, <rightopnd>
Example:
C code: a = b + c;
C code: a = b + c + d;
• Why?
Instructions: Language of the Computer
Immediates
addi $s0, $s1, 42 # note the opcode
li $s0, 42 # actually a pseudoinstruction
lui $at, 0xFEDC
ori $s0, $at, 0x8765
Instructions: Language of the Computer
MIPS Logical Instructions
<opcode> <dest>, <leftopnd>, <rightopnd>
• Examples:
and $s0, $s1, $s2 # bitwise AND
andi $s0, $s1, 42
or $s0, $s1, $s2 # bitwise OR
ori $s0, $s1, 42
nor $s0, $s1, $s2 # bitwise NOR (i.e., NOT OR)
sll $s0, $s1, 10 # logical shift left
srl $s0, $s1, 0x0A # logical shift right
Instructions: Language of the Computer
Registers vs. Memory
Control Input
Memory
Datapath Output
Processor I/O
Instructions: Language of the Computer
Memory Organization
0 8 bits of data
1 8 bits of data
2 8 bits of data
3 8 bits of data
4 8 bits of data
5 8 bits of data
6 8 bits of data
.
.
.
Instructions: Language of the Computer
Memory Organization
• Bytes are nice, but most data items use larger words
• For MIPS, a word is 32 bits or 4 bytes.
0 32 bits of data
4 32 bits of data
Registers hold 32 bits of data
8 32 bits of data
12 32 bits of data
.
.
.
• 232 bytes with byte addresses from 0 to 232-1
• 230 words with byte addresses 0, 4, 8, ... 232-4
• Words are aligned
– i.e., what are the least 2 significant bits of a word address?
Instructions: Language of the Computer
MIPS Load and Store Instructions
Example:
C code: A[12] = h + A[8];
lw $t0, ($s3)
lw $t0, 0 # almost always a bad idea
• In base + register mode the address is the sum of an immediate and the value in a
register:
lw $t0, 100($s3)
lw $t0, absval
lw $t0, absval + 100
lw $t0, absval + 100($s3)
Instructions: Language of the Computer
Addressing Modes
Instructions: Language of the Computer
Branching
• Types of branches:
– Conditional branches
• branch if equal (beq)
• branch if not equal (bne)
– Unconditional branches
• jump (j)
• jump register (jr)
• jump and link (jal)
• These are useful for building loops and conditional control structures.
Instructions: Language of the Computer
Instruction Formats
R-Type
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
I-Type
op rs rt imm
6 bits 5 bits 5 bits 16 bits
J-Type
op addr
6 bits 26 bits
Instructions: Language of the Computer
The Power of the Stored Program
Stored Program
Address Instructions
0040000C 0 1 6 D4 0 2 2
00400008 2 2 6 8 F F F 4
00400004 0 2 3 2 8 0 2 0
00400000 8 C0 A0 0 2 0 PC
Main Memory
Further Reading
• PATTERSON, David A.; HENNESSY, John L. Computer
Organization and Design: The Hardware/Software Interface.
Fourth Edition, Revised Printing. Morgan Kaufmann, 2011.
Chapter 2.