william stallings computer organization and architecture 6 th edition
DESCRIPTION
William Stallings Computer Organization and Architecture 6 th Edition. Chapter 10 Instruction Sets: Characteristics and Functions. What is an instruction set?. The complete collection of instructions that are understood by a CPU Machine Code Binary Usually represented by assembly codes. - PowerPoint PPT PresentationTRANSCRIPT
William Stallings Computer Organization and Architecture6th Edition
Chapter 10Instruction Sets:Characteristicsand Functions
What is an instruction set?
• The complete collection of instructions that are understood by a CPU
• Machine Code• Binary• Usually represented by assembly codes
Elements of an Instruction
• Operation code (Op code)—Specifies the operation to be performed.
• Source Operand reference—Input operands for the operation.
• Result Operand reference—Put the answer here
• Next Instruction Reference—Tell the CPU where to fetch the next
instruction after the execution of this instruction is complete.
Elements of an Instruction (cont.)
• Source and Result operands can be in one of three areas:—Main memory (or virtual memory or cache)—CPU register—I/O device
Instruction Cycle State Diagram
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
Simple Instruction Format
Instruction Types
• Data processing—Arithmetic and logic instructions
• Data storage (main memory)—Memory instruction
• Data movement (I/O)—I/O instruction are need to transfer programs
and data into memory and the results of computations back out to the user.
• Program flow control —Test and branch instruction—Test instructions are used to test the value of a
data word or the status of a computation.—Branch instructions are used to branch a
different set of instructions depending on the decision made.
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
Number of Addresses (d)
• 0 (zero) addresses—All addresses implicit—Uses a stack—e.g. push a— push b— add— pop c
—c = a + b
Utilization of instruction address
Example: Y=(A-B)/(C+D*E)
• Three-address instruction—SUB Y, A, B (Y=A-B)
MPY T, D, E (T=D*E)ADD T, T, C (T=T+C)DIV Y, Y, T (Y=Y/T)
• Two-address instruction—MOVE Y, A (Y=A)
SUB Y, B (Y=Y-B)MOVET, D (T=D)MPY T, E (T=T*E)ADD T, C (T=T+C)DIV Y, T (Y=Y/T)
Example: Y=(A-B)/(C+D*E)
• One-address instruction—LOADD (AC=D)
MPY E (AC=AC*E)ADD C (AC=AC+C)STOR Y (Y=AC)LOAD A (AC=A)SUB B (AC=AC-B)DIV Y (AC=AC/Y)STOR Y (Y=AC)
精選範例
精選範例 - 解答
How Many Addresses
• More addresses—More complex instructions—More registers
– Inter-register operations are quicker
—Fewer instructions per program
• Fewer addresses—Less complex instructions—More instructions per program—Faster fetch/execution of instructions
Design Decisions (1)
• Operation repertoire—How many ops?—What can they do?—How complex are they?
• Data types—The various types of data upon which
operations are performed.
• 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…)—The mode or modes by which the address of
an operand is specified.
• RISC v CISC
Types of Operand
• Machine instruction operate on data, the most important categories of data are—Addresses—Numbers
– Integer/floating point
—Characters– ASCII etc.
—Logical Data– Bits or flags
Types of Operand (cont.)
• Address—Addresses are a form of data.—Addresses can be considered to be unsigned
integers
• Numbers—There is a limit to the magnitude of numbers
representable on a machine.—In the FP numbers, a limit to their precision.—Three types of numerical data are common in
computer– Integer or fixed point– Floating point– Decimal
+ Binary/decimal converter
Types of Operand (cont.)
• Characters—A number of codes have been devised by
which characters are represented by a sequence of bits
—International Reference Alphabet (IRA)– American Standard Code for Information Interchange
(ASCII)+ 7 bit, 128 different characters, including some control
characters.
– IRA-encoded characters+ 8 bit+ The last bit is parity bit
– Extended Binary Coded Decimal Interchange Code (EBCDIC)
+ Used on IBM S/390 machines+ 8 bit
Types of Operand (cont.)
• Logical Data—To consider an n-bit unit as consisting of n 1-
bit items of data—Each item having the value 0 or 1
• The same data are treated sometimes as logical and other times as numerical or text.—The “type” of a unit of data is determined by
the operation being performed on it—It is almost always the case with machine
language.
Pentium Data Types
• 8 bit Byte• 16 bit word• 32 bit double word• 64 bit quad word• Addressing is by 8 bit unit• A 32 bit double word is read at addresses
divisible by 4• Little-endian style
—The least significant byte is stored in the lowest address.
Specific Data Types
• General - arbitrary binary contents• Integer - signed binary value (2s
complement)• Ordinal - unsigned integer• Unpacked BCD - One digit per byte• Packed BCD - 2 BCD digits per byte• Near Pointer - 32 bit offset within segment• Bit field• Byte String• Floating Point – IEEE 754 standard
Pentium Floating Point Data Types
PowerPC Data Types
• The PowerPC can deal with data type of—8 (byte), 16 (halfword), 32 (word) and 64
(doubleword) length data types
• Some instructions need operand aligned on 32 bit boundary
• Can be big- or little-endian• Fixed point processor recognises:
—Unsigned byte, unsigned halfword, signed halfword, unsigned word, signed word, unsigned doubleword, byte string (<128 bytes)
• Floating point—IEEE 754—Single or double precision
Types of Operation
• Data Transfer• Arithmetic• Logical• Conversion• I/O• System Control• Transfer of Control
Common Instruction Set Operation
Common Instruction Set Operation (cont.)
Common Instruction Set Operation (cont.)
Common Instruction Set Operation (cont.)
CPU actions for various types of operations
Data Transfer
• The data transfer instruction must specify the followings:—Source—Destination—Amount of data—The mode of addressing for each operand
• May be different instructions for different movements—e.g. IBM 370
• Or one instruction and different addresses—e.g. VAX
Example of IBM S/390 Data Transfer Operations
Data Transfer (cont.)
• CPU actions—If both source and destination are register, the
CPU transfer data from one register to another.—If one or both operands are in memory, the
CPU must perform some or all of the following actions
– Calculate the memory address– If the address refers to virtual memory, translate
from virtual to actual memory address.– Determine whether the addressed item is in cache– If not, issue a command to the memory module.
Arithmetic
• Most machine provide the basic arithmetic—Add, Subtract, Multiply, Divide
• These are always provided for signed integer (fixed-point) numbers.
• They are often provide floating point and packed decimal numbers.
• Other possible operations include—Absolute—Negate—Increment—Decrement
Logical• Bitwise operations• AND, OR, NOT
— The AND operation can be used as a mask that selects certain bits in a word and zeros out the remaining bits
• Logical shift— The bits of a word are shifted left or right— On one end, the bit shifted out is lost.— On the other end, a o is shifted in,
Logical: Shift and Rotate Operations
Logical (cont.)
• Arithmetic shift—The arithmetic shift operation treats the data
as a signed integer and does the sign bit.—A right arithmetic shift corresponds to a
division by 2—A left arithmetic shift corresponds to a
multiplication by 2
• Rotate—Preserve all of the bits being operated on.
Logical (cont.)
• Conversion—That change the format or operate on the
format of data—E.g. Binary to Decimal
Input/Output
• A variety of approaches—Isolated programmed I/O, memory-mapped
programmed I/O, DMA, and I/O processor
• May be specific instructions (Isolated)• May be done using data movement
instructions (memory mapped)• May be done by a separate controller
(DMA)
Systems Control
• System control—Can be executed only while the CPU is in a
certain privileged state or is executing a program in a special privileged area of memory.
• CPU needs to be in specific state —Ring 0 on 80386+—Kernel mode
• For operating systems use
Transfer of Control
• Branch—Jump instruction, has as one of its operands,
the address of the next instruction to be executed.
—Conditional branch– e.g. branch to x if result is zero
—User-visible register– Most machine provide a 1-bit or multiple-bit
condition code
• Skip—Includes an implied address, the address of
the next instruction plus one instruction-length—e.g. increment and skip if zero (ISZ)—ISZ Register1
Transfer of Control (cont.)
• Procedure Call instruction—The reasons for the use of procedures are
economy and modularity.—A procedure allows the same piece of code to
be used many times.—The procedure mechanism involves two basic
instructions– Call instruction– Return instruction
—A procedure can be called from more than one location
—A procedure call can appear in a procedure (nesting of procedures to an arbitrary depth)
—Each procedure call is matched by a return in the called program
Transfer of Control (cont.)
—There are three common places for storing the return address
– Register– Start of called procedure– Top of stack
—Reentrant procedure– A reentrant procedure is one in which it is possible to
have several calls open to it at the same time– Eg. Recursive procedure
Branch Instruction
Nested Procedure Calls
Use of Stack
Stack Frame Growth Using Sample Procedures P and Q
Assembly Language
• A CPU can understand and execute machine instructions
• Such instructions are simply binary numbers stored in computer
• For more improvement—Make use of the symbolic name or mnemonic
of each instruction—Symbolic program—Pseudo instruction
• Programs written in assembly language are translated into machine language by assembler
Stacks
• 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• The number of element in the stack is called
length• Stack is a pushdown list or a last-in-first-out list
Basic Stack Operation
Stack Implementation
• Because all of these operations refer to the top of the stack, the address of the operand or operands is implicit and need not be included in the instruction.
• Zero-address instruction• Three address are needed for proper
operation—Stack pointer
– Contains the address of the top of the stack
—Stack base– Contains the address of the bottom location in the
reserved block
—Stack limit– Contains the address of the other end of the reserved
block
Typical Stack Organizations
Expression Evaluation
• Reverse Polish (postfix)• The postfix is easily evaluated using a
stack• Algorithm
—If the element is a variable or constant, push it onto the stack
—If the element is an operator, – pop the top two items of the stack, – perform the operation, – and push the result.
Use of stack to compute f=(a-b)/(c+d*e)
Byte Order(A portion of chips?)
• What order do we read numbers that occupy more than one byte
• e.g. (numbers in hex to make it easy to read)
• 12345678 can be stored in 4x8bit locations as follows
Byte Order (example)
• Address Value (1) Value(2)• 184 12 78• 185 34 56• 186 56 34• 187 78 12
• i.e. read top down or bottom up?
Big endian最大有效位元由低位址往高位址方向存放
Little endian最小有效位元由低位址往高位址方向存放
Byte Order Names
• The problem is called Endian• The system on the left has the most
significant byte in the lowest address—This is called big-endian
• The system on the right has the least significant byte in the lowest address—This is called little-endian
Example of C Data Structure
Alternative View of Memory Map
Standard…What Standard?
• Pentium (80x86), VAX are little-endian• IBM 370, Moterola 680x0 (Mac), and most
RISC are big-endian• Internet is big-endian
—Makes writing Internet programs on PC more awkward!
—WinSock provides htoi and itoh (Host to Internet & Internet to Host) functions to convert