Instruction Set
Architecture
Instructions and
Format
Introduction
• A program is written and submitted for execution to the
computer.
• Mostly, the programmer or a student wishing to execute
a program works in the IDE (Integrated Development
Environment) of the Language Compiler.
• The sequence of steps is the program is compiled,
linked, loaded, and executed.
• The Linker output is machine code.
• The loader loads the program machine code in Main
Memory from a particular address.
What is a linker?
• A linker is a computer program that combines object
files into a single executable file, library file, or another
object file. It's a crucial part of the compilation process
for a program.
• A linker's responsible for;
i. Combining object files: Taking object code generated by a
compiler and combining it with other modules and libraries
ii. Resolving references: Ensuring that all the necessary functions
and variables from different modules are connected correctly
iii. Allocating memory: Locating all the object files into memory
iv. Using a linker script: Understanding the memory map of the
microcontroller being used.
• The CPU executes the machine code from the starting
address in a sequential manner following the flow of the
code.
• To put it harshly, CPU obeys the sequence of
instructions that makes up the code for the program; it
does not understand the program as a whole.
• For this reason, computers are said to be "Garbage In
Garbage Out".
Programming Computer
Languages
• A programming language is an artificial language that can
control the behavior of a machine, specifically in computers.
• Programming language like natural languages is defined by
syntactic and semantic rules defining their structure and
meaning.
• Syntactic/Syntax- Just a set of rules that define how to
write valid code in a programming language
• Sematic- is the mathematical study of the meaning of a
programming language.
• It's a way to model the computational meaning of a
program, or what happens when it's executed on a computer
Programs
• Computer programs are instructions for a computer.
• A computer needs programs to function, generally
executing the program’s instructions in the main
processor.
• The program has an executable form that the computer
can use directly to execute the instructions.
• Equivalent program in its human-readable source
program form, from which executable programs are
changed (for example, compiled) allows a programmer
to study and develop the algorithm.
Subroutine
• A subroutine or subprogram (also known as a
procedure, method, function, or routine) is an allocation
of code within a larger program, which implements a
definite task and is associatively independent of the
remaining code.
• A subroutine is regularly coded so that it can be started
(called) multiple times and from multiple places during
an individual execution of the program, involving other
subroutines, and branch back (return) to the point after
the call, once the task is completed.
Statement
• In computer programming, a statement can be thought
of as the smallest standalone element of an imperative
programming language.
• A program is assembled by a sequence of one or more
statements.
• A statement will have internal components such as
expressions.
Expression
• An expression in a programming language is a
sequence of values, variables, operators, and functions
that are interpreted (evaluated) according to the
specific rules of precedence and of association for a
specific programming language, which evaluates and
then makes (returns in a stateful environment) another
value.
• The expression has computed that value.
Values
• In computer science, a value is a sequence of bits that
is interpreted according to various data types.
• The same sequence of bits can have several values,
depending on the type can interpret its meaning.
• For instance, the value can be an integer or floating-
point value, or string.
Variable
• In computer programming, a variable is an identifier
(generally a letter, word, or phrase) that is connected to
a value saved in the system’s memory or an expression
that can be computed.
• Operator − Programming languages generally provide
a set of operators that are equivalent to operators in
mathematics. A language can include a fixed number of
built-in operators such as +,-,*, = in C and C++.
Hierarchy of Computer
Languages
Machine Language
• Machine language is the native language of the CPU
that it understands. In the hierarchy of computer
languages, machine language is at the lowest level and
closest to the hardware.
• Machine language is unique to each CPU and partly
generic to the family of the CPU (Ex. Intel series).
• A program converted into an executable file (.exe) on a
CPU is not executable in another brand of CPU.
• For example, an executable file generated in an Intel
CPU will not run on another CPU like AMD or so. The
program will have to be recompiled on the other system
and the executable code to be regenerated.
• Machine language is in binary form.
• This is nothing but the CPU instructions in the
instruction format of the CPU as defined by the
Instruction Set Architecture (ISA).
Instructions
• An instruction details the CPU of "What to Execute?",
"Where to Execute?" and "How to Execute?".
• For example, a code written by the programmer
as TOTAL = TOTAL + SUBTOTAL is converted as an
instruction(s) that tells the CPU to add the contents of
the two memory locations where the variables TOTAL
and SUBTOTAL are stored and put the result in location
TOTAL.
• Every CPU has an Instruction Set and format for the
instructions.
• Essentially an instruction consists of a minimum of two
components i.e. the instruction code (opcode) and the
operand for the instruction as in Figure.
• Opcode: Specifies the type of operation to be
performed.
• Operand: Provides information on the data needed for
the instruction execution.
Instruction Set Classification
• The instruction set of any processor broadly fits into the
categories as in the figure below along with examples.
• The first five categories are mandatory while the next
four are generally available in advanced or new-
generation processors.
• The Instruction set is part of the Instruction Set
Architecture( ISA).
• Therefore the Data path, the Registers, the Memory,
Interface, and the Instruction set, altogether ensure the
design of the CPU and its best utilization.
• The number of instructions for a processor may range
from less than 100 to few hundred plus.
• It is noteworthy, that a large number of instructions
does not imply that the processor is powerful.
• More often, to provide downward compatibility within
the processor family variants of each instruction add up
to the list, making the set larger.
• Note that programs created in 8086 CPU get executed
in today’s Intel Processors.
Data Movement Instructions
• These support the movement of data between registers,
registers to memory, and memory to register.
• Few CPUs support memory-to-memory movement of
data too. Data movement instructions are named as
either “Move” or Load/Store” instructions.
• This category is most frequently used by CPU while
executing program code. For example:
Move R1, Total: copies the contents of R1 into Total
Move Total, R1
Load R1, Total
Store R1, Total
• MOV R0, R1: Copies the contents of register R0 into
R1
• MOV 1000, A: Moves the value in A to 1000H
• MOV @ R1, A: Copies the contents of memory whose
address is in R1 to the accumulator
Move Instructions
• A move instruction copies data from a source to a
destination, leaving the source unchanged:
• MOV
• Copies a data file word to a destination. The MOV
instruction in x86 assembly copies data from a second
operand to a first operand. The second operand can be
a register, memory, or constant value, while the first
operand can be a register or memory.
Load Instruction
• A load instruction is a processor instruction that moves
data from a memory location into a register (before
operation)
• A register is a small, fast storage unit within the
processor that temporarily holds data for processing.
• Load instructions typically have two operands:
• Source operand: Specifies the memory address to
read from
• Destination operand: Specifies the register to store
the data in
Store instruction
• A store instruction is an instruction that tells the processor
to transfer data from a register to a specific memory
location.
• A store instruction usually has two operands:
• The source operand, which specifies the register to read
from, and the
• Destination operand, which specifies the memory address
to write to. Example
• str R1, [R2 + R3]: Stores the value in register R1 to memory
at address (location) given by R2+R3. (R1 is the destination
register.
• str r1, [r2 + #N]: Store the value in register R1 to memory
at address (location) given by R2+N (N is a constant)
Why load and store instructions?
• Load and store instructions are important because they
enable the processor to access and manipulate data in
memory, which is essential for running programs and
performing computations.
• However, load and store instructions also have some
drawbacks and challenges.
i. Memory is slower than registers, so loading and storing
data can take more time and reduce the processor's
speed.
ii. Also memory is shared by multiple processes and
devices, so loading and storing data can cause conflicts
and errors.
• Therefore, computer hardware designers have to find
ways to optimize and manage load and store instructions
How to optimize and manage load and
store instructions
• One way to optimize and manage load and store
instructions is to use a cache.
• A cache is a small and fast memory unit that is closer to
the processor than the main memory.
• The cache stores copies of frequently accessed or recently
used data from the main memory, so that the processor
can load and store data faster and more efficiently
• The cache also handles the synchronization and
coherence of data between the main memory and the
processor, so that the processor can access the most up-
to-date and consistent data.
• However, the cache also has some limitations and trade-
offs or incompactibility.
• For example, the cache has a limited size and capacity,
so it cannot store all the data from the main memory.
• The cache also has to deal with cache misses, which
occur when the processor requests data that is not in
the cache, and cache hits, which occur when the
processor requests data that is in the cache.
Arithmetic and Logical
Instructions
• This category of instructions carries out calculations.
The minimum in this category is ADD, SUB, AND, OR,
XOR, SHIFT.
• Multiply and Divide can always be emulated using
successive or repeated addition or subtraction.
• Repeated addition: A method of combining equal
groups. For example, 5 + 5 = 10. while 3+3+3=9
• Repeated subtraction: A method of subtracting the
same number multiple times from a larger number until
the remainder is zero or smaller than the number being
subtracted. For example, 25 - 5 = 20, 20 - 5 = 15, 15 - 5
= 10, 10 - 5 = 5, 5 - 5 = 0. This process is also known as
division.
• This was the case in very early systems. However,
today MULTIPLY and DIV are part of the instruction set
as hardware execution is more efficient than emulation.
• Few CPUs have CMP (Compare) instruction.
• The logical instructions are required to implement the
condition checking of "For Loops, While Loops, IF, etc.,".
• At the end of execution of arithmetic and logical
instructions, depending on the result in Accumulator,
Condition Codes (Zero, Sign, Overflow, Carry – ZSOC) are
set, implying the outcome of the instruction execution.
• Generally, these flags are useful in controlling the flow of
the program. For example:
ADD R1, TOTAL //
ADD R1, R2, R3
XOR R4, TOTAL
MUL R4, MARKS
What are flags?
• Flags are variables that store a binary value, either true or false,
used to indicate if a condition has been met or an event has
occurred.
• How do flags work?
• Flags are assigned a value based on conditions in the
program. Other parts of the program can then check the flag's
value to determine if the condition was met and react accordingly.
• What do flags do?
i. Flags can be used to: Control the flow of a program by
enabling or disabling blocks of code
ii. Trigger specific actions
iii. Maintain the program's state
iv. Communicate information between different parts of a
program
Transfer or Control Instructions
• This category of instructions facilitate change in program
flow described by the control structures in the high-level
language.
• BRANCH or JMP instructions along with Condition Code
flags achieve the requirement. Subroutine CALLS,
RETURNS are categorized here. For example:
JMP LABLE1 Jump
JNZ LABLE1 Jump on Not Zero
BZ LABLE2 Branch on Zero
BNE LABLE3 Branch on Not Equal
Input/Output Instructions
• There are two ways of doing Input/Output operations.
• Intel family uses In and Out Instructions on the I/O registers
for communication or data transfer with I/O devices.
• These I/O registers are numbered as Ports.
• Motorola family uses Data movement instructions
assigning memory addresses to I/O registers.
• The former is called I/O mapped I/O whereas the later is
called Memory-mapped I/O. For example:
IN Port#232
OUT Port#234
Move R1, #FFEEEE
Miscellaneous Instructions
• NOP (No Operation) is a famous dummy instruction but a
very useful one in this category. Some of the CPUs allow
user-defined interrupt.
• These interrupts can be activated using Instructions.
• HALT is another very important instruction which brings
the system to halt when "Shutdown".
• System Control is either grouped here or as Control
Instructions. For example:
HALT
NOP
INT // used to generate software interrupt.
Floating Point Instructions
• For efficient Floating-point operations, specialised
hardware is required
• This hardware works independently of the CPU.
• Floating-Point Arithmetic instructions with unique
opcode are helpful.
FLD FP Load
FST FP Store
FADD FP ADD
FSUB FP Subtract
FMUL FP Multiply