Instruction Sets:
Characteristics and Functions
Zhao Fang
Computer Organization & Architecture
-for the college students
Goal for Today
◼ Machine Instruction Characteristics
◼ Types of Operands(运算对象)
◼ Types of Operations
◼ Examples
Programming language
◼ Classification of programming language:
❑ Machine language
❑ Assembly language
❑ High-level language
◼ Compiler
❑ Translation program that converts high-
level/assembly language programs into machine
language
Machine Language and Assembly
Language
◼ Machine language
❑ Defined by the computer’s hardware design
❑ Consists of streams of numbers (1s and 0s) that
instruct computers how to perform elementary
operations
❑ A computer can understand only its own machine
language
Machine Language and Assembly
Language
◼ Assembly language
❑ Represents machine-language instructions using
English-like abbreviations(缩略语)
❑ Assemblers convert assembly language to
machine language
What is an Instruction Set?
◼ The complete collection of instructions that
are understood by a CPU
◼ Machine Code
◼ Binary
◼ Usually represented by assembly codes
Instruction set
Software, compiler
hardware
Instruction Cycle State Diagram
Elements of an Instruction
◼ Operation code (Op code)
❑ Do this
◼ Source Operand reference
❑ From this
◼ Result Operand reference
❑ Put the answer here
◼ Next Instruction Reference
❑ When you have done that, do this...
Instruction Representation
◼ A simple instruction format
Source and result operands can be in one of the following areas:
Memory, CPU registers, Immediate, I/O devices
Instruction Representation
◼ In machine code each instruction has a
unique bit pattern
◼ For human consumption (well, programmers
anyway) a symbolic representation is used
❑ e.g. ADD, SUB, LOAD
◼ Operands can also be represented in this
way
❑ ADD A,B
Instruction Types
◼ The instructions can be categorized into four
types:
❑ Data processing: arithmetic and logic instructions
❑ Data storage: memory instructions
❑ Data movement: I/O instructions
❑ Control: test and branch instructions
Instruction Types
◼ Arithmetic instructions
◼ Logic (Boolean) instructions
◼ Memory instructions: moving data between memory and the registers.
◼ I/O instructions
◼ Test instructions: used to test the value of a data word or the status of a computation.
◼ Branch instructions: used to branch to a different set of instructions.
Number of Addresses (a)
◼ 3 addresses
❑ Operand 1, Operand 2, Result
❑ a = b + c;
❑ May be a forth - next instruction (usually implicit)
❑ Not common
❑ Needs very long words to hold everything
Number of Addresses (b)
◼ 2 addresses
❑ One address doubles as operand and result
❑ a = a + b
❑ Reduces length of instruction
❑ Requires some extra work
◼ Temporary storage to hold some results
Number of Addresses (c)
◼ 1 address
❑ Implicit second address
❑ Usually a register (accumulator累加器)
❑ Common on early machines
◼ LOAD A ;AC ← A
◼ SUB B ;AC ← AC – B
◼ STORE Y ;Y ← AC
Number of Addresses (d)
◼ 0 (zero) addresses: All addresses implicit
❑ Usually use stack to imply the operands
◼ e.g. push a
◼ push b
◼ add
◼ pop c
◼ c = a + b
How Many Addresses
◼ More addresses
❑ More complex (powerful?) instructions
❑ More registers
◼ Inter-register operations are quicker
❑ Fewer instructions per program
◼ Fewer addresses
❑ Less complex (powerful?) instructions
❑ More instructions per program
❑ Faster fetch/execution of instructions
Instruction set design
◼ The most important of the fundamental design issues include the following:
❑ Operation repertoire: how many and which operations to provides, and how complex operations should be
❑ Data types: the operands types
❑ Instruction format: instruction length, number of addresses…
❑ Registers: how many registers can be used by the instructions
❑ Addressing: how to access a memory location, how many modes can be used
Design Decisions (1)
◼ Operation repertoire(计算机指令系统)
❑ How many ops?
❑ What can they do?
❑ How complex are they?
◼ Data types
◼ Instruction formats
❑ Length of op code field
❑ Number of addresses
Design Decisions (2)
◼ Registers
❑ Number of CPU registers available
❑ Which operations can be performed on which
registers?
◼ Addressing modes (later…)
◼ RISC v CISC
Types of Operand(操作数)
◼ Addresses
◼ Numbers
❑ Integer/floating point
◼ Characters
❑ ASCII etc.
◼ Logical Data
❑ Bits or flags
Numbers
◼ Three types of numerical data are common in
computers:
❑ Binary integer or binary fixed point
❑ Binary floating point
❑ Decimal
◼ Packed decimal
Little-, Big-, Bi- Endian
◼ The byte ordering:
❑ The memory unit: byte
❑ The data type: 8 bits, 16 bits, 32 bits …
❑ How are these data stored in memory?
◼ There are two ways to store the values
❑ Big endian: the most significant byte is stored in
the lowest byte address(从左到右序,西方书写模式)
❑ Little endian: the least significant byte is stored in
the lowest byte address(从右到左序,算数顺序)
Little-, Big-, Bi- Endian
◼ Suppose we want to store a 32-bit hex value
12345678 to address 184
Address Value
184 12
185 34
186 56
187 78
Address Value
184 78
185 56
186 34
187 12
Big endian Little endian
Characters
◼ A common form of data is text or character strings.
◼ The earliest common example:
❑ Morse code(摩斯码)
◼ The most commonly used:
❑ International Reference Alphabet (IRA)
◼ United States as the American Standard Code for
Information Interchange (ASCII)
◼ Extended Binary Coded Decimal Interchange Code
(EBCDIC)
❑ Used on IBM mainframes
Logical Data
◼ Boolean or binary data items
❑ Each item can take on only the values 1 (true) and
0 (false)
◼ There are occasions when we wish to
manipulate the bits of a data item
Example
Types of Operation
◼ Data Transfer
◼ Arithmetic
◼ Logical
◼ Conversion
◼ I/O
◼ System Control
◼ Transfer of Control
Data Transfer
◼ Location of source and destination must be
specified:
❑ Memory
❑ Register
❑ Top of the stack
◼ For the memory access, addressing mode
must be specified – the memory address
format
◼ The length of the operands must be specified
Common Data Transfer Instructions
Arithmetic
◼ Add, subtract, multiply, divide, absolute, negate,
increment, decrement
◼ The operands are
❑ Signed integer (fixed point) numbers
❑ Floating-point numbers
❑ Packed decimal numbers
◼ CPU actions:
Logical
◼ Bitwise operations
◼ AND, OR, NOT
Shift and Rotate(旋转) Operations
Conversion
◼ E.g. Binary to Decimal
Input/Output
◼ May be specific instructions
◼ May be done using data movement instructions
(memory mapped)
◼ May be done by a separate controller (DMA)
Systems Control
◼ Privileged instructions(特权指令)
◼ CPU needs to be in specific state
❑ Kernel mode
◼ For operating systems use
◼ Examples:
❑ Read or write a control register
❑ Read or write a storage protection key
❑ Access to process control blocks in a
multiprogramming system
Transfer of Control
Branch Instructions
◼ Also called jump instructions
◼ The operands involve the address of the next
instruction to be executed
◼ For conditional branch instructions, the
branch is made only if a certain condition is
met
❑ Otherwise, executes next instruction in sequence
◼ Usually the condition is taken as a result of
an operation (arithmetic or logic)
Branch Instruction
Skip Instructions
◼ The skip instruction includes an implied address
◼ The skip implies that one instruction be skipped
❑ The implied address equals the address of the next
instruction plus one instruction-length
301
…
309 ISZ R1
310 BR 301
311 …
ISZ: increment and skip if zero
Procedure Call Instructions
◼ A procedure is a subroutine
◼ It is invoked by a calling instruction and returned by a return instruction
❑ A procedure call can appear in a procedure – nested
❑ Each procedure call is matched by a return in the called program
◼ The CPU must save the returning address in one of the following
❑ Register
❑ Start of called procedure
❑ Top of stack
Nested Procedure Calls
The Use of Stacks
Stack Frame Growth
Passing Parameters
◼ Pass parameters is important to the
procedure call.
◼ Using registers :
❑ Must assure that the registers are used properly
◼ Using memory cells:
❑ It is difficult to exchange the variables
Passing Parameters
◼ Using stack is more flexible: when a
procedure is called
❑ Stack the return address
❑ Stack parameters to be passed to the called
procedure
❑ When return, the return parameters can also be
placed on the stack
◼ All above stacked info for the procedure is
called a stack frame.
Stack Operation
◼ A stack is an ordered set of elements, only one
of which can be accessed at a time.
◼ The point of access is called the top of the stack
◼ It is a last in first out (LIFO) list
Stack Organization
High address
Low address
Summary
◼ Machine Instruction Characteristics
◼ Types of Operands
◼ Pentium and PowerPC Data Types
◼ Types of Operations
Key Terms
Address Conditional
branch
Machine
instruction
Procedu
re return
stack
Arithmetic
shift
Instruction
set
operand Push
Bi-endian Jump Operation Reentrant
procedure
Big endian Little
endian
Pop Rotate
branch Logical
shift
Procedure
call
Skip
Assignment
◼ Review questions:
❑ 12.1 12.2 12.3 12.5 12.6 12.9 12.11 12.12
◼ Problems:
❑ 12.1 12.2 12.3 12.4 12.6 12.8 12.16 12.17 12.18
12.19
Top Related