instruction sets: characteristics and functions
TRANSCRIPT
![Page 1: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/1.jpg)
Instruction Sets:
Characteristics and Functions
Zhao Fang
Computer Organization & Architecture
-for the college students
![Page 2: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/2.jpg)
Goal for Today
◼ Machine Instruction Characteristics
◼ Types of Operands(运算对象)
◼ Types of Operations
◼ Examples
![Page 3: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/3.jpg)
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
![Page 4: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/4.jpg)
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
![Page 5: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/5.jpg)
Machine Language and Assembly
Language
◼ Assembly language
❑ Represents machine-language instructions using
English-like abbreviations(缩略语)
❑ Assemblers convert assembly language to
machine language
![Page 6: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/6.jpg)
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
![Page 7: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/7.jpg)
Instruction Cycle State Diagram
![Page 8: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/8.jpg)
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...
![Page 9: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/9.jpg)
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
![Page 10: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/10.jpg)
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
![Page 11: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/11.jpg)
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
![Page 12: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/12.jpg)
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.
![Page 13: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/13.jpg)
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
![Page 14: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/14.jpg)
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
![Page 15: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/15.jpg)
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
![Page 16: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/16.jpg)
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
![Page 17: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/17.jpg)
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
![Page 18: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/18.jpg)
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
![Page 19: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/19.jpg)
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
![Page 20: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/20.jpg)
Design Decisions (2)
◼ Registers
❑ Number of CPU registers available
❑ Which operations can be performed on which
registers?
◼ Addressing modes (later…)
◼ RISC v CISC
![Page 21: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/21.jpg)
Types of Operand(操作数)
◼ Addresses
◼ Numbers
❑ Integer/floating point
◼ Characters
❑ ASCII etc.
◼ Logical Data
❑ Bits or flags
![Page 22: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/22.jpg)
Numbers
◼ Three types of numerical data are common in
computers:
❑ Binary integer or binary fixed point
❑ Binary floating point
❑ Decimal
◼ Packed decimal
![Page 23: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/23.jpg)
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(从右到左序,算数顺序)
![Page 24: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/24.jpg)
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
![Page 25: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/25.jpg)
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
![Page 26: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/26.jpg)
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
![Page 27: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/27.jpg)
Types of Operation
◼ Data Transfer
◼ Arithmetic
◼ Logical
◼ Conversion
◼ I/O
◼ System Control
◼ Transfer of Control
![Page 28: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/28.jpg)
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
![Page 29: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/29.jpg)
Common Data Transfer Instructions
![Page 30: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/30.jpg)
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:
![Page 31: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/31.jpg)
Logical
◼ Bitwise operations
◼ AND, OR, NOT
![Page 32: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/32.jpg)
Shift and Rotate(旋转) Operations
![Page 33: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/33.jpg)
Conversion
◼ E.g. Binary to Decimal
![Page 34: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/34.jpg)
Input/Output
◼ May be specific instructions
◼ May be done using data movement instructions
(memory mapped)
◼ May be done by a separate controller (DMA)
![Page 35: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/35.jpg)
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
![Page 36: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/36.jpg)
Transfer of Control
![Page 37: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/37.jpg)
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)
![Page 38: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/38.jpg)
Branch Instruction
![Page 39: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/39.jpg)
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
![Page 40: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/40.jpg)
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
![Page 41: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/41.jpg)
Nested Procedure Calls
![Page 42: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/42.jpg)
The Use of Stacks
![Page 43: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/43.jpg)
Stack Frame Growth
![Page 44: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/44.jpg)
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
![Page 45: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/45.jpg)
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.
![Page 46: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/46.jpg)
![Page 47: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/47.jpg)
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
![Page 48: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/48.jpg)
Stack Organization
High address
Low address
![Page 49: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/49.jpg)
Summary
◼ Machine Instruction Characteristics
◼ Types of Operands
◼ Pentium and PowerPC Data Types
◼ Types of Operations
![Page 50: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/50.jpg)
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
![Page 51: Instruction Sets: Characteristics and Functions](https://reader036.vdocuments.site/reader036/viewer/2022070314/62bfc4a1c7ce0529803c02ac/html5/thumbnails/51.jpg)
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