0% found this document useful (0 votes)
9 views52 pages

Instruction Set Design & Addressing Modes

designing the model

Uploaded by

vivuvimalwa2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views52 pages

Instruction Set Design & Addressing Modes

designing the model

Uploaded by

vivuvimalwa2000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

INSTRUCTION SET

DESIGN AND
ADDRESSING MODES
Contents
•Instruction set design is a crucial aspect of computer architecture.
•It defines the set of operations that a processor can perform and how
those operations are executed.
•The instruction set is a fundamental interface between the hardware
and software of a computer system.
•An instruction set is a collection of instructions that a processor can
execute.
•Each instruction specifies an operation to be performed, such as adding
two numbers, moving data between memory and registers, or branching
to a different part of a program.
•The instruction set architecture (ISA) specifies the format of each
instruction, including the number of operands, the type of operands
(e.g., integer or floating-point), and the addressing modes used to access
data.
• The design of an instruction set is important for several reasons.
i. It affects the performance and efficiency of the processor.
ii. Impacts the software ecosystem that supports the processor.
iii. May influence the overall system design, including the memory
hierarchy, cache design, and interconnects.
[Link]:
Let's consider an instruction set that includes a dedicated
instruction for performing matrix multiplication.
This instruction takes advantage of parallel processing capabilities
and reduces the number of instructions needed for matrix
multiplication compared to a generic instruction set.
As a result, a program that performs matrix multiplication can
execute much faster.
For example, if a generic instruction set takes 1000 clock cycles to
multiply two matrices, the specialized instruction set may reduce it
to 500 clock cycles, effectively doubling the performance.
2. Efficiency:
Consider an instruction set that includes instructions optimized for
bitwise operations commonly used in encryption algorithms.
These instructions can perform bitwise operations on multiple data
elements simultaneously.
As a result, encryption algorithms that heavily rely on bitwise
operations can be executed with fewer clock cycles, reducing power
consumption.
For example, an encryption algorithm that takes 1000 clock cycles
to execute on a generic instruction set may only require 500 clock
cycles on an instruction set that includes specialized bitwise
instructions, leading to improved energy efficiency.
3. Software Ecosystem:
Let's assume a processor has an instruction set designed
specifically for machine learning tasks, including instructions for
vectorized operations commonly used in neural networks.
In this case, software libraries and frameworks that support the
instruction set can provide optimized implementations of machine
learning algorithms.
For instance, a machine learning model training algorithm that
takes hours to execute on a generic instruction set may be
significantly accelerated, completing the task in minutes when
utilizing the specialized instructions and corresponding software
ecosystem.
4. System Design:
Consider an instruction set that incorporates instructions for
handling complex data structures efficiently, such as linked lists
or trees.
These instructions may include direct support for operations like
traversing linked lists or searching tree structures.
The processor's memory hierarchy and cache design can be
optimized to exploit the characteristics of these instructions.
For example, cache designs can be tailored to efficiently store
and access linked list nodes or tree nodes, reducing memory
access latency and improving overall system performance.
• Each instruction must contain the information required by the processor
for execution.
• A machine (computer) instruction typically consists of several elements
that collectively define the operation to be performed by the processor.
• Recall instruction execution cycle: Fetch  Decode  Execute  Store
Instruction Cycle State Diagram – pg 409 – Stallings 9 th edn.
•Opcode: The opcode (operation code) is a binary code that specifies the
type of operation to be performed, such as arithmetic, logical, data
movement, or control flow.
•Operands: Operands are the inputs to the instruction that determine the
specific data or memory locations involved in the operation. They can
be registers, immediate values (constants), memory addresses, or a
combination thereof.
• Registers: Machine instructions often involve the use of registers,
which are small storage locations within the processor. Registers may
hold source data, store results, or serve as temporary storage during
the execution of the instruction.
• Immediate Values: Immediate values are constants or literals that are
directly specified within the instruction itself. They can be used as
operands for arithmetic or logical operations.
•Memory Addresses: Instructions may require accessing data stored in
memory. Memory addresses are used to specify the location in memory
from which data should be fetched or to which data should be stored.
•Control Flow Elements: Some instructions deal with control flow
operations, such as branching or jumping to different parts of the
program based on specific conditions. These elements include branch
conditions, branch targets, and program counters.
•Flags: Instructions may modify status flags or condition codes within a
processor's flags register, which indicate the outcome of previous
operations. Flags are commonly used in conditional branching and
decision-making instructions.
•Prefixes or Modifiers: Some instruction sets allow the use of prefixes
or modifiers that alter the behavior or interpretation of an instruction.
These additional elements can modify the operand size, addressing
mode, or specify special handling.
•An instruction in computer architecture typically consists of two parts:
the opcode and the operands.
•The opcode (short for "operation code") is a binary code that specifies
the operation to be performed by the processor.
•It is the part of the instruction that tells the processor what to do.
•For example, an opcode might specify that the processor should
perform an addition operation, a subtraction operation, or a conditional
jump.
•Opcodes are represented by abbreviations called mnemonics that
indicate an operation e.g. ADD, SUB, MUL, DIV, LOAD, STOR etc.
•The operands are the values or memory addresses on which the
operation specified by the opcode is to be performed.
•They are the part of the instruction that tells the processor what to do
the operation on.
•For example, an instruction that adds two numbers together might have
two operands, which are the two numbers to be added.
•Operands are also represented symbolically: e.g. ADD R, X
•There are different ways in which operands can be specified in an instruction,
depending on the addressing mode used.
•Some examples of addressing modes include:
•Immediate addressing: The operand is a constant value that is part of the instruction
itself.
•Register addressing: The operand is a value stored in a register.
•Direct addressing: The operand is the value stored in a memory location specified
directly in the instruction.
•Indirect addressing: The operand is the value stored in a memory location pointed
to by a register or a memory location specified in the instruction.
•The number of operands and the format of the opcode and operands
depend on the instruction set architecture (ISA) of the processor.
•Different processors may have different ISAs, and thus different
opcodes and operand formats.
• Instructions can be categorized into 4 general categories
• Data processing instructions: Arithmetic and Logic instructions
• Data storage instructions: Movement of data into or out of register
and or memory locations
• Data Movement Instructions: I/O instructions
• Control instructions: Test and Branch instructions
•Memory addressing is the process of accessing data stored in memory
by specifying the memory address of the data.
•Memory addressing works by specifying the location of the data in
memory using an address.
•The address is a unique identifier for a specific location in memory,
much like a street address is a unique identifier for a specific location in
the physical world.
•When a program needs to access data stored in memory, it specifies the
memory address of the data.
•The processor uses the memory address to locate the data in memory
and retrieves the data from memory.
•The processor reads the instruction from memory and decodes the
instruction to determine the memory address of the data.
•The processor calculates the actual memory address of the data, based
on the addressing mode specified in the instruction.
•The processor sends the memory address to the memory controller,
which retrieves the data from memory and sends it back to the
processor.
•The processor performs the operation on the data and stores the result
back in memory if necessary.
•Memory addressing is a crucial aspect of computer architecture, as it
enables programs to store and retrieve data from memory.
•This is essential for program execution, as programs often need to store
and retrieve data during their execution.
•By using memory addressing, programs can store and retrieve data
quickly and efficiently.
• x86 architecture, which is widely used in modern desktop and server
computers, includes several registers that are used for various
purposes.
•General-Purpose Registers:
• EAX (Accumulator): Used for arithmetic and logical operations. It also stores function return
values.
• EBX (Base): Used as a base pointer for memory access.
• ECX (Counter): Primarily used for loop and string operations.
• EDX (Data): Used for arithmetic operations. It is also used in conjunction with EAX for
larger integer multiplication and division.
• ESI (Source Index): Used as a source index for string operations.
• EDI (Destination Index): Used as a destination index for string operations.
• EBP (Base Pointer): Typically used to point to the base of the stack frame.
• ESP (Stack Pointer): Points to the top of the stack.
•Segment Registers:
• CS (Code Segment): Points to the current code segment.
• DS (Data Segment): Points to the data segment.
• SS (Stack Segment): Points to the stack segment.
• ES (Extra Segment): An additional segment register that can be used for any
purpose.
• FS and GS (Additional Segment Registers): Additional segment registers
introduced in later x86 processors.
•Instruction Pointer:
• EIP (Instruction Pointer): Points to the memory address of the next instruction
to be executed.
•Flags Register:
• EFLAGS: Stores various flags that indicate the outcome of arithmetic and
logical operations. These flags include carry, zero, sign, overflow, and others.
Assembly program sections
• The .data section is used to declare and initialize data variables and constants.
Here, we have the variable1, variable2, variable3, and message variables declared
with different data types and initial values.
• The .bss (block started by symbol/storage) section is used to declare uninitialized
data variables. Here, we have the uninitialized variable declared as a byte and the
array declared as an array of 10 double word elements. The memory space is
reserved for these variables, but they are not initialized with specific values.
• The .text section contains the assembly instructions of the program. It starts with
the _start label, which marks the program's entry point. This is where the main
logic of the program would typically be placed.
• The program terminates using the exit system call. The necessary instructions and
values to perform the system call are not shown in this example.
• In assembly language, dd, dw, and db are directives used to declare
and define variables with specific data sizes.
• dd (Define Doubleword):
• dd is used to declare and define variables that occupy 4 bytes (32 bits) of
memory, typically referred to as a doubleword.
• It is commonly used to store integer values, memory addresses, or other 32-
bit data types.
• Example: variable dd 1000 declares and initializes a variable named "variable"
with the value 1000.
• dw (Define Word):
• dw is used to declare and define variables that occupy 2 bytes (16 bits) of memory,
typically referred to as a word.
• It is commonly used to store integer values or other 16-bit data types.
• Example: variable dw 100 declares and initializes a variable named "variable" with
the value 100.
• db (Define Byte):
• db is used to declare and define variables that occupy 1 byte (8 bits) of memory,
typically referred to as a byte.
• It is commonly used to store characters, ASCII values, or other 8-bit data types.
• Example: variable db 'A' declares and initializes a variable named "variable" with
the ASCII value of the character 'A'.
Immediate addressing:
• Advantages:
• Allows immediate values to be used directly in instructions,
enabling efficient computation of constant values.
• Provides flexibility in specifying immediate operands without
needing to store them in memory or registers.
• Disadvantages:
• Limited range of immediate values, typically constrained by
the number of bits available for the immediate field.
• Increases code size when large immediate values are used.
Direct addressing
• Advantages:
• Simple and straightforward, directly accessing memory
locations using fixed addresses.
• Efficient for accessing specific memory locations or variables
known at compile-time.
• Disadvantages:
• Lack of flexibility as memory addresses are hard-coded,
making it challenging to work with dynamically allocated
memory or variable-sized data structures.
• Prone to errors if memory addresses are not correctly
determined or updated.
Indirect addressing
• Advantages:
• Enables flexibility in accessing memory locations through a
register or a memory location pointed to by a register.
• Useful for iterating over arrays, accessing data structures, or
implementing pointers.
• Large address space
• Disadvantages:
• Requires additional instructions to load and update the
memory addresses stored in registers.
• Indirect addressing can introduce potential performance
overhead due to the extra memory access required.
Register addressing
• Advantages:
• Fast and efficient access to data stored in registers without
the need for memory access.
• Allows for quick computations and manipulation of data within
registers.
• Disadvantages:
• Limited number of available registers, which can restrict the
amount of data that can be stored and manipulated
simultaneously.
• Register spills may occur when there are insufficient registers
to hold all necessary variables.
Register indirect addressing
• Advantages of register indirect addressing:
[Link]: it allows for dynamic memory access by using
the value stored in a register as the memory address. This
enables efficient traversal of data structures, arrays, or
dynamically allocated memory.
[Link] pointer manipulation: therefore, it is commonly
used to implement pointers in programming languages,
allowing efficient manipulation of memory locations and
data structures.
[Link] memory access: it can minimize memory
accesses compared to other addressing modes, such as
direct addressing, as it avoids the need for explicit memory
address calculations or additional memory fetches.
• Disadvantages of register indirect addressing:
[Link] number of available registers: The number of available
registers is finite, and using registers for indirect addressing reduces
the number of registers available for other purposes, such as holding
variables or temporary values.
[Link] memory access overhead: it requires additional instructions to
load and update the memory address stored in the register, which can
introduce some performance overhead.
[Link] complexity: it can introduce additional complexity to the
code, as it involves managing the values stored in registers and
ensuring they correctly point to the desired memory locations.
Displacement addressing
• Advantages of displacement addressing:
[Link]: it allows for the efficient access of data
structures, arrays, and records by using a base address
combined with a fixed offset. This flexibility enables the
traversal and manipulation of structured data.
[Link] reusability: By using a base address and an offset, the
same code can be used to access different elements within a
data structure by simply modifying the offset value.
[Link] memory access: it avoids the need for additional
memory fetches or calculations, as the offset is added
directly to the base address.
• Disadvantages of displacement addressing:
[Link] range: The range of displacements may be restricted by
the number of bits available to represent the offset. This
limitation can result in the inability to address memory locations
beyond a certain range.
[Link] structure requirements: it assumes a fixed structure or
organization of data, as the offset is typically designed to access
specific fields or elements within a structure. If the structure
changes, the offsets may need to be adjusted accordingly.
[Link] waste: If the structure being accessed does not align
well with the offset values used in displacement addressing,
there can be memory waste due to unused or inefficiently utilized
memory space.
• Advantages:
• Facilitates dynamic memory allocation for local variables and
function calls.
• Provides a simple and efficient way to manage the stack,
especially for nested function calls and local variable storage.
• Disadvantages:
• Accessing stack memory can be slower compared to
accessing registers or directly addressed memory.
• Stack operations may need careful tracking and management
to prevent stack overflows or underflows.
What is the initial and final stack value?

You might also like