Computer Architecture
Lecture 9.
. Instruction Sets:
Characteristics and Functions.
Instructors
Elena Boldyreva, Associate Professor [email protected]
GOALS OF THIS LECTURE: PLAN:
1. get terminology about 1. Machine instruction characteristics
instruction sets 2. Instruction set design
2. get understanding of 3. Types of operands and operations
machine instruction 4. Intel x86 and ARM instruction sets
characteristics
3. more details about its
hardware realization
©. Stallings, William. Computer organization and architecture : designing for performance
2
What is an Instruction Set?
• The complete collection of instructions that are understood by a CPU
• Machine Code
• Binary
• Usually represented by assembly codes
3
Elements of a Machine Instruction
Operation code (opcode)
• Specifies the operation to be performed. The operation is specified
by a binary code, known as the operation code, or opcode
Source operand reference
• The operation may involve one or more source operands, that is,
operands that are inputs for the operation
Result operand reference
• The operation may produce a result
Next instruction reference
• This tells the processor where to fetch the next instruction after the
execution of this instruction is complete
4
Instruction Cycle State Diagram
5
Source and result operands
can be in one of four areas:
1) Main or virtual memory 3) Processor register
• As with next instruction references, • A processor contains one or more registers
the main or virtual memory address that may be referenced by machine
must be supplied
instructions.
2) I/O device • If more than one register exists each
• The instruction must specify the I/O register is assigned a unique name or
module and device for the number and the instruction must contain
operation. If memory-mapped I/O is
the number of the desired register
used, this is just another main or
virtual memory address
4) Immediate
• The value of the operand is
contained in a field in the instruction
being executed
6
Instruction Representation
• Within the computer each instruction is represented by a sequence
of bits
• The instruction is divided into fields, corresponding to the
constituent elements of the instruction
7
Instruction Types
• Arithmetic instructions provide
computational capabilities for
processing numeric data
• Movement of data into
• Logic (Boolean) instructions or out of register and or
operate on the bits of a word as memory locations
bits rather than as numbers,
thus they provide capabilities
for processing any other type of Data Data
data the user may wish to
employ processing storage
Data
Control
• Test instructions are used to test the movement
value of a data word or the status of a
computation • I/O instructions are needed to
• Branch instructions are used to branch transfer programs and data into
to a different set of instructions memory and the results of
depending on the decision made computations back out to the
user
8
Number of Addresses
9
Instruction Addresses
Table 12.1
Utilization of Instruction Addresses (Nonbranching Instructions)
10
Types of Operands
Addresses
Numbers
Characters
Logical Data
11
Numbers
• All machine languages include numeric data types
• Numbers stored in a computer are limited:
• Limit to the magnitude of numbers representable on a machine
• In the case of floating-point numbers, a limit to their precision
• Three types of numerical data are common in computers:
• Binary integer or binary fixed point
• Binary floating point
• Decimal
• Packed decimal
• Each decimal digit is represented by a 4-bit code with two digits
stored per byte
• To form numbers 4-bit codes are strung together, usually in
multiples of 8 bits
12
Characters
• A common form of data is text or character strings
• Textual data in character form cannot be easily stored or transmitted by
data processing and communications systems because they are designed for
binary data
• Most commonly used character code is the International Reference
Alphabet (IRA)
• Referred to in the United States as the American Standard Code for
Information Interchange (ASCII)
• Another code used to encode characters is the Extended Binary Coded
Decimal Interchange Code (EBCDIC)
• EBCDIC is used on IBM mainframes
13
Logical Data
• An n-bit unit consisting of n 1-bit items of data, each item having the value 0 or 1
• Two advantages to bit-oriented view:
• Memory can be used most efficiently for storing an array of Boolean or binary
data items in which each item can take on only the values 1 (true) and 0
(false)
• To manipulate the bits of a data item
• If floating-point operations are implemented in software, we need to be
able to shift significant bits in some operations
• To convert from IRA to packed decimal, we need to extract the rightmost
4 bits of each byte
14
x86 Data Types
Table 12.2
x86 Data Types
15
x86 Numeric Data Formats
16
Single-Instruction-Multiple-Data (SIMD)
Data Types
• Introduced to the x86 architecture as part of the extensions of the
instruction set to optimize performance of multimedia applications
• These extensions include MMX (multimedia extensions) and SSE
(streaming SIMD extensions)
• Data types:
• Packed byte and packed byte integer
• Packed word and packed word integer
• Packed doubleword and packed doubleword integer
• Packed quadword and packed quadword integer
• Packed single-precision floating-point and packed double-
precision floating-point
17
ARM Data Types
ARM processors support data types of:
• 8 (byte)
• 16 (halfword)
• 32 (word) bits in length
Alignment checking
All three data types can also be • When the appropriate control bit is set,
used for twos complement a data abort signal indicates an
signed integers alignment fault for attempting
unaligned access
For all three data types an Unaligned access
unsigned interpretation is
• When this option is enabled, the processor
supported in which the uses one or more memory accesses to
value represents an generate the required transfer of adjacent
unsigned, nonnegative bytes transparently to the programmer
integer
18
ARM Endian Support
19
Processor Actions
Table 12.4
Processor Actions for Various Types of Operations
20
Data Transfer
Must specify:
Most fundamental • Location of the source and
destination operands
type of machine • The length of data to be
instruction transferred must be indicated
• The mode of addressing for each
operand must be specified
21
Table 12.5
Examples of IBM EAS/390 Data Transfer
Operations
22
Arithmetic
❑ Most machines provide the basic arithmetic operations of add, subtract,
multiply, and divide
❑ These are provided for signed integer (fixed-point) numbers
❑ Often they are also provided for floating-point and packed decimal numbers
❑ Other possible operations include a variety of single-operand instructions:
❑ Absolute
❑ Take the absolute value of the operand
❑ Negate
❑ Negate the operand
❑ Increment
❑ Add 1 to the operand
❑ Decrement
❑ Subtract 1 from the operand
23
Logical
Table 12.6 Basic Logical Operations
24
Shift and Rotate Operations
Table 12.7
Examples of Shift and Rotate Operations
25
Input/Output
• Variety of approaches taken:
• Isolated programmed I/O
• Memory-mapped programmed I/O
• DMA
• Use of an I/O processor
• Many implementations provide only a few I/O instructions, with the specific
actions specified by parameters, codes, or command words
26
System Control
Instructions that can be executed only while the processor is in a certain
privileged state or is executing a program in a special privileged area of
memory
Typically these instructions are reserved for the use of the
operating system
Examples of system control operations:
A system control An instruction to read or Access to process control
instruction may read or modify a storage blocks in a
alter a control register protection key multiprogramming system
27
Transfer of Control
• Reasons why transfer-of-control operations are required:
• It is essential to be able to execute each instruction more than once
• Virtually all programs involve some decision making
• It helps if there are mechanisms for breaking the task up into smaller pieces
that can be worked on one at a time
• Most common transfer-of-control operations found in instruction sets:
• Branch
• Skip
• Procedure call
28
Branch Instruction
29
Procedure Call Instructions
• Self-contained computer program that is incorporated into a larger
program
• At any point in the program the procedure may be invoked, or called
• Processor is instructed to go and execute the entire procedure and
then return to the point from which the call took place
• Two principal reasons for use of procedures:
• Economy
• A procedure allows the same piece of code to be used many times
• Modularity
• Involves two basic instructions:
• A call instruction that branches from the present location to the
procedure
• Return instruction that returns from the procedure to the place from
which it was called
30
Nested
Procedures
31
Use of Stack to Implement Nested
Procedures
32
Stack Frame Growth
33
X86 Operation Types
Table 12.8
x86
Operation Types (With
Examples of Typical
Operations)
(page 1 of 2)
34
X86 Operation Types
Table 12.8
x86
Operation Types (With
Examples of Typical
Operations)
(page 2 of 2)
35
Call/Return Instructions
• The x86 provides four instructions to support procedure call/return:
• CALL
• ENTER
• LEAVE
• RETURN
• Common means of implementing the procedure is via the use of stack frames
• The CALL instruction pushes the current instruction pointer value onto the stack and
causes a jump to the entry point of the procedure by placing the address of the entry
point in the instruction pointer
• The ENTER instruction was added to the instruction set to provide direct support for the
compiler
36
x86 Status Flags
37
X86 Condition Codes
Table 12.10
x86
Condition Codes for
Conditional Jump
and SETcc
Instructions
38
x86 Single-Instruction, Multiple-Data
(SIMD) Instructions
• 1996 Intel introduced MMX technology into its Pentium product line
• MMX is a set of highly optimized instructions for multimedia tasks
• Video and audio data are typically composed of large arrays of small data types
• Three new data types are defined in MMX
• Packed byte
• Packed word
• Packed doubleword
• Each data type is 64 bits in length and consists of multiple smaller data fields,
each of which holds a fixed-point integer
39
MMX Instruction Set
Note: If an instruction supports multiple data types [byte (B), word (W), doubleword (D), quadword (Q)], the data types are indicated in brackets. 40
Conclusion
• Machine instruction • Intel x86 and ARM data types
characteristics
• Elements of a machine • Types of operations
instruction • Data transfer
• Instruction representation • Arithmetic
• Instruction types • Logical
• Number of addresses • Conversion
• Instruction set design • Input/output
• Types of operands • System control
• Numbers • Transfer of control
• Characters • Intel x86 and ARM operation
• Logical data types
41
Questions
1. What are the typical elements of a machine instruction?
2. What types of locations can hold source and destination operands?
3. If an instruction contains four addresses, what might be the purpose of each address?
4. What types of operands are typical in machine instruction set?
5. What is the difference between an arithmetic shift and a logic shift?
6. What is the difference between assembly language and machine language
7. What is the difference between big endian and little endian?
8 List three places for storing the return address for a procedure return.
42
Answers
1 Operation code, source operand reference, result operand reference and next
instruction reference.
2 Register and memory.
3 Two operands, one result, and the address of the next instruction.
4 Address, character, numbers and logical data.
5 In logical shift, the bits of word are shifted left or right. Arithmetic shift treats the
data as a signed integer and does not shift the sign bit.
43
Answers (cont.)
6 Assemble language uses symbolic names for addresses that are not fixed to specific
physical address; this is not the case with machine language.
7 A multibyte numerical value stored with the most significant byte in the lowest
numerical address. A multibyte numerical value stored with the most significant byte
in the highest numerical address.
8 Register, start of procedure, top of stack
44