Screenshot 2025-05-14 at 6.32.49 PM
Screenshot 2025-05-14 at 6.32.49 PM
FROM
HARDWARE ESSENTIALS
TO
WEB DESIGN
MODULE 2
SYLLABUS
MODULE SUB TOPIC No.of Level CO
MODULE Hours
2 2.1 Number systems 1 L2 CO2
2 2.2 Binary representation of data and numbers, 1 L2 CO2
2 2.3 Integer representation 1 L2 CO2
2 2.4 Data Storage units - bits, bytes, kilobytes, etc. ASCII 2 L2 CO2
and unicodes
2 2.5 Basic CPU architecture 1 L2 CO2
2 2.6 ALU, registers, control unit 1 L2 CO2
2 2.7 Instruction format and assembly language (basics 1 L2 CO2
only)
2 2.8 Fetch - execute cycle and instruction execution 1 L2 CO2
How Computers Represent Data
From a very early age, we arc introduced to the concept of numbers and counting.
Toddlers learn early that they can carry two cookies, one in each hand. Kinder partners
start counting by twos and fives. Invariably, we use the decimal number system. Our
number system is based on 10, most likely because we have 10 fingers. A number system is
simply a manner of counting. Many different number systems exist. Consider a clock.
Clocks have 24 hours, each composed of 60 minutes. Each minute is composed of 60
seconds. When we time a race, we count in seconds and minutes.
Computers, like clocks, have their own numbering system, the binary number
system.
Number Systems
If base or radix of a number system is ‘r’, then the numbers present in that number system are
ranging from zero to r-1. The total numbers present in that number system is ‘r’.
● All digital circuits and systems use this binary number system.
● The base or radix of this number system is 2.
● The numbers 0 and 1 are used in this number system.
● The part of the number, which lies to the left of the binary point is known as integer
part.
● The part of the number, which lies to the right of the binary point is known as
fractional part.
Octal Number System
• Introduction
Computers store and process information using the binary numbering system.
Unlike humans, who use decimal (base-10), computers use binary (base-2) for
internal data storage.
Binary Representation of Numeric and Textual Information
1. How Humans Represent Information:
1.Decimal Digits (0-9) – Used for numeric values (e.g., 459).
2.Sign/Magnitude Notation – A sign (+/-) placed before numbers (e.g., -131, +2789).
3.Decimal Notation for Real Numbers – A decimal point separates whole and fractional
parts (e.g., 12.34).
4.Alphabets and Symbols – A-Z, a-z, and punctuation marks for text representation.
2. How Computers Represent Information:
•Externally, computers use decimal digits, alphabets, and symbols.
•Internally, all data—numbers, text, images, and sound—are stored using the binary
numbering system.
Binary Numbering System
The bits present in the un-signed binary number holds the magnitude of a number. That means, if the un-signed
binary number contains ‘N’ bits, then all N bits represent the magnitude of the number, since it doesn’t have any sign bit.
10810 = 11011002 It is having 7 bits. These 7 bits represent the magnitude of the number 108.
Representation of Signed Binary Numbers
The Most Significant Bit MSB of signed binary numbers is used to indicate the sign of the numbers. Hence, it is also
called as sign bit. The positive sign is represented by placing ‘0’ in the sign bit. Similarly, the negative sign is
represented by placing ‘1’ in the sign bit. If the signed binary number contains ‘N’ bits, then N−1 bits only represent
the magnitude of the number since one-bit MSB is reserved for representing sign of the number.
● Sign-Magnitude form
● 1’s complement form
● 2’s complement form
Representation of a positive number in all these 3 forms is same. But, only the representation of negative number
will differ in each form.
Example
Consider the positive decimal number +108. The binary equivalent of magnitude of this number is 1101100. These 7
bits represent the magnitude of the number 108. Since it is positive number, consider the sign bit as zero, which is
placed on left most side of magnitude.
+10810 = 011011002
Therefore, the signed binary representation of positive decimal number +108 is 01101100. So, the same
representation is valid in sign-magnitude form, 1’s complement form and 2’s complement form for positive decimal
number +108.
Sign-Magnitude form
In sign-magnitude form, the MSB is used for representing sign of the number and the remaining bits represent the
magnitude of the number. So, just include sign bit at the left most side of unsigned binary number. This
representation is similar to the signed decimal numbers representation.
– The most significant bit (MSB) indicates sign (0: positive, 1: negative).
+0 0000 -0 1000
+1 0001 -1 1001
+2 0010 -2 1010
+3 0011 -3 1011
+4 0100 -4 1100
+5 0101 -5 1101
+6 0110 -6 1110
+7 0111 -7 1111
Note: A problem- Two different representations for zero.
Example
Consider the negative decimal number -108. The magnitude of this number is 108. We
know the unsigned binary representation of 108 is 1101100. It is having 7 bits. All these
bits represent the magnitude. Since the given number is negative, consider the sign bit as
one, which is placed on left most side of magnitude. −10810 = 111011002.
The 1’s complement of a number is obtained by complementing all the bits of signed
binary number. So, 1’s complement of positive number gives a negative number.
Similarly, 1’s complement of negative number gives a positive number. That means, if you
perform two times 1’s complement of a binary number including sign bit, then you will get
the original signed binary number.
Basic idea:
– Positive numbers are represented exactly as in sign-magnitude form.
– Negative numbers are represented in 1’s complement form.
● How to compute the 1’s complement of a number?
– Complement every bit of the number (1 to 0, and 0 to 1).
– Most Significant Bit (MSB) will indicate the sign of the number (0: positive,
1: negative).
Decimal 1’s complement Decimal 1’s complement
representation in 4 representation in 4
bits bits
+0 0000 -0 1111
+1 0001 -1 1110
+2 0010 -2 1101
+3 0011 -3 1100
+4 0100 -4 1011
+5 0101 -5 1010
+6 0110 -6 1001
+7 0111 -7 1000
Note: A problem- Two different representations for zero. Advantage of 1’s complement
representation: – Subtraction can be done using addition. – Leads to substantial saving in
circuitry.
Example Consider the negative decimal number -108.
The 2’s complement of a binary number is obtained by adding one to the 1’s complement of
signed binary number. So, 2’s complement of positive number gives a negative number.
Similarly, 2’s complement of negative number gives a positive number.
That means, if you perform two times 2’s complement of a binary number including sign
bit, then you will get the original signed binary number.
Basic idea:
– Positive numbers are represented exactly as in sign-magnitude form.
– Negative numbers are represented in 2’s complement form.
– Complement every bit of the number (1 to 0 and 0 to 1), and then add one to the
resulting number.
– MSB will indicate the sign of the number (0: positive, 1: negative).
Decimal 2’s complement Decimal 2’s complement
representation in 4 representation in 4
bits bits
+0 0000 -0 -
+1 0001 -1 1111
+2 0010 -2 1110
+3 0011 -3 1101
+4 0100 -4 1100
+5 0101 -5 1011
+6 0110 -6 1010
+7 0111 -7 1001
Note: Unique representations for zero.
Advantage of 2’ s complement representation:
– Unique representation of zero.
– Subtraction can be done using addition.
– Leads to substantial saving in circuitry.
Example Consider the negative decimal number -108.
● A kilobyte is often referred to as 1,000 bytes in the decimal system, commonly used in marketing.
● In computing, a kilobyte is typically 1,024 bytes, based on the binary system (2^10=1,024).
● This difference exists because computers operate on binary principles, while the decimal system is
more familiar to consumers.
Unit Shortened Capacity
Byte B 8 bits
The two-character encoding schemes that are currently most widely utilized around the
world are Unicode and ASCII. As opposed to ASCII, which is used to represent text in
computers as symbols, characters, and numbers, Unicode is a character encoding that may
be used to process, store, and exchange text data in any language.
ASCII
○ ASCII (pronounced AS-key) stands for the American Standard Code for
Information Interchange. Today, the ASCII character set is by far the most
commonly used in computers of all types. Tabic 4A.3 shows the 128 ASCII
codes. ASCII is an eight-bit code that specifics characters for values from 0
to 127.
○ Extended ASCII- Extended ASCII is an eight-bit code that specifies the
characters for values from 128 to 255. The first 40 symbols represent
pronunciation and special punctuation. The remaining symbols are graphic
symbols.
For Example:
Dollar $ 36 24
Asterisk * 42 2A
Minus sign/Hyphen - 45 2D
Decimal Point . 46 2E
Unicode
● The Unicode Worldwide Character Standard provides up to four bytes—32 bits—to represent each
letter; number, or symbol. W ith four bytes, enough Unicode codes can be created to represent
more than 4 billion different characters or symbols.
● This total is enough for every unique character and symbol in the world, induding the vast Chinese,
Korean, and Japanese character sets and those found in known classical and historical texts.
● In addition to world letters, special mathematical and scientific symbols are represented in
Unicode.
● One major advantage that Unicode has over other text code systems is its compatibility with ASCII
codcs.
● The first 256 codes in Unicode are identical to the 256 codes used by the ASCII and Extended
ASCII systems.
ASCII VS UNICODE
Let us now see some of the main differences between
ASCII and UNICODE:
ASCII UNICODE
Lowercase letters (a-z), uppercase letters (A- A wider range of characters than ASCII is
Z), numerals (0-9), and symbols like represented by Unicode, including letters
parenthesis, dollars, the ampersand, and from languages like English, Arabic, Greek,
others are represented by the ASCII code. and others, mathematical symbols, historical
scripts, and emoji.
Only 128 different characters can be Unicode encrypts 154 written scripts.
encoded using ASCII using a 7-bit range.
• Key Feature:
○ Code-morphing layer translates instructions from other CPUs and optimizes execution by resolving data
dependencies.
Figure shows an example of a typical molecule.
EPIC Architecture
• Registers:
○ 128 general-purpose 64-bit registers.
○ 128 82-bit floating-point registers.
• Stored-program concept: Program instructions and data are stored in the same
memory.
.
• The computer unit is made up conceptually of three major components, the arithmetic/logic unit
(ALU), the control unit (CU), and memory.
• The ALU and CU together are known as the central processing unit (CPU).
• An input/output (I/O) interface is also included in the diagram.
• The I/O interface corresponds in function roughly to the input and output baskets, although its
implementation and operation differ from that of the Little Man Computer in many respects.
• The arithmetic/logic unit is the component of the CPU where data is held temporarily and where
calculations take place.
• It corresponds directly to the calculator in the Little Man Computer.
• The control unit controls and interprets the execution of instructions.
• It does so by following a sequence of actions that correspond to the fetch–execute instruction
cycle.
• Most of these actions are retrievals of instructions from memory followed by movements of
data or addresses from one part of the CPU to another.
• The control unit determines the particular instruction to be executed by reading the
contents of a program counter (PC), sometimes called an instruction pointer (IP), which is a
part of the control unit.
• Like the Little Man’s location counter, the program counter contains the address of the
current instruction or the next instruction to be executed.
• Normally, instructions are executed sequentially.
• The sequence of instructions is modified by executing instructions that change the contents
of the program counter.
• The Little Man branch instructions are examples of such instructions.
• A memory management unit within the control unit supervises the fetching of instructions
and data from memory.
• The I/O interface is also part of the control unit.
• In some CPUs, these two functions are combined into a single bus interface unit.
• The program counter in the CPU obviously corresponds to the location counter in the Little
Man Computer, and the control unit itself corresponds to the Little Man.
• Memory, of course, corresponds directly to the mailboxes in the LMC.
The Concept of Registers
•A register is a single, permanent storage location within the CPU used for a particular,
defined purpose.
•A register is used to hold a binary value temporarily for storage, for manipulation, and/or for
simple calculations.
•Each register is wired within the CPU to perform its specific role.
•That is, unlike memory, where every address is just like every other address, each register
serves a particular purpose.
•The register’s size, the way it is wired, and even the operations that take place in the register
reflect the specific function that the register performs in the computer.
•Registers also differ from memory in that they are not addressed as a memory location would
be, but instead are manipulated directly by the control unit during the execution of
instructions.
•Registers may be as small as a single bit or as wide as several bytes, ranging usually from 1
to 128 bits.
•Registers are used in many different ways in a computer.
•Depending on the particular use of a register, a register may hold data being processed, an
instruction being executed, a memory or I/O address to be accessed, or even special binary
codes used for some other purpose, such as codes that keep track of the status of the
computer or the conditions of calculations that may be used for conditional branch
instructions.
•Some registers serve many different purposes, while others are designed to perform a
single, specialised task.
•There are even registers specifically designed to hold a number in floating point format, or
a set of related values representing a list or vector, such as multiple pixels in an image.
• Registers are basic working components of the CPU.
• In the CPU, the equivalent to the calculator is known as an accumulator.
• Modern CPUs provide several accumulators; these are often known as general-purpose registers.
• Some vendors also refer to general-purpose registers as user-visible or program-visible registers to
indicate that they may be accessed by the instructions in user programs.
• Groups of similar registers are also sometimes referred to collectively as a register file.
• General-purpose registers or accumulators are usually considered to be a part of the
arithmetic/logic unit, although some computer manufacturers prefer to consider them as a
separate register unit.
• As in the Little Man Computer, accumulator or general-purpose registers hold the data that are
used for arithmetic operations as well as the results.
• In most computers, these registers are also used to transfer data between different memory
locations, and between I/O and memory, again similar to the LMC.
•The control unit contains several important registers.
•The program counter register (PC or IP) holds the address of the current instruction being
executed.
• The instruction register (IR) holds the actual instruction being executed currently by the
computer. In the Little Man Computer, this register was not used; the Little Man himself
remembered the instruction he was executing. In a sense, his brain served the function of the
instruction register.
• The memory address register (MAR) holds the address of a memory location.
•The memory data register (MDR), sometimes known as the memory buffer register, will hold
a data value that is being stored to or retrieved from the memory location currently
addressed by the memory address register.
• Although the memory address register and memory data register are part of the CPU,
operationally these two registers are more closely associated with memory itself.
• The control unit will also contain several 1-bit registers, sometimes known as flags, that are
used to allow the computer to keep track of special conditions such as arithmetic carry and
overflow, power failure, and internal computer error.
• Usually, several flags are grouped into one or more status registers.
• In addition, our typical CPU will contain an I/O interface that will handle input and out- put
data as it passes between the CPU and various input and output devices, much like the LMC
in and out baskets.
• For simplification, we will view the I/O interface as a pair of I/O registers, one to hold an I/O
address that addresses a particular I/O device, the other to hold the I/O data.
• These registers operate similarly to the memory address and data registers.
• Most instructions are executed by the sequenced movement of data between the different
registers in the ALU and the control unit. each instruction has its own sequence.
Most registers support four primary types of operations:
1. Registers can be loaded with values from other locations, in particular from other registers or
from memory locations. This operation destroys the previous value stored in the destination
register, but the source register or memory location remains unchanged.
2. data from another location can be added to or subtracted from the value previously stored in a
register, leaving the sum or difference in the register.
3. data in a register can be shifted or rotated right or left by one or more bits. This operation is
important in the implementation of multiplication and division.
4. The value of data in a register can be tested for certain conditions, such as zero, positive,
negative, or too large to fit in the register.
Instruction Format
and
Assembly Language
Instruction Format
Classification of Instructions
• There may be many different addressing modes available within a single computer.
• Additionally, variations on these instructions are frequently used to handle different data sizes.
Data Size Variations:
• Load Byte (1 byte)
• Load Half-Word (2 bytes)
• Load Word (4 bytes)
• Load Double Word (8 bytes)
• Incidentally, the concept of a “word” is not consistent between manufacturers.
Word Size Variations
• The Little Man load and store instructions are simple, though adequate, examples of move
instructions.
•The major limitation of the Little Man load and store instructions is the fact that they
are designed to operate with a single accumulator.
When More Registers are Added:
• Instructions need to specify which register to use
• 4 bits required for each register (e.g., for 16 registers)
• Instruction Size Decreases if registers store memory addresses
•Additionally, it is desirable to have the capability to move data directly between
registers, since such moves do not require memory access and are therefore faster to
execute.
•In fact, some modern CPUs, including the ARM and Oracle SPARC architectures,
provide only a minimal set of load/store or move instructions for moving data between
the CPU and memory.
•All other instructions in these CPUs move and manipulate data only between registers.
•This allows the instruction set to be executed much more rapidly.
1. LOAD Instruction:
The LOAD instruction is used to transfer data from memory into a register. In other words, it loads the
contents of a memory location into a processor register for further operations.
• Syntax Example:
LOAD R1, [Address]
• This instruction means: load the data from the memory location specified by Address into register R1.
• Function: The LOAD instruction typically involves fetching data from a specific address in memory
(RAM) and placing it into a register so that the processor can perform computations on it.
• Use Case: Whenever the processor needs data that is stored in memory, it issues a LOAD instruction to
bring that data into a register. This is a crucial step before performing any computation or modification
on that data.
2. STORE Instruction:
The STORE instruction is used to transfer data from a register to a memory location. It stores the contents of a register into a specified
memory address.
• Syntax Example:
STORE [Address], R1
• This instruction means: store the data from register R1 into the memory location specified by Address.
• Function: The STORE instruction takes the data in a register and writes it into a memory location. This is typically used to save the
results of computations or to store data temporarily for future use.
• Use Case: After performing operations on data, the processor might use the STORE instruction to save the results back to memory. This is
essential for persisting results, especially when working with large datasets or needing to share data between different parts of a program.
• Types of Operands:
◦ Register + Register
◦ Register + Memory
◦ Memory + Register
• Implementation:
◦ Most CPUs use binary addition (1 + 1 = 0, carry 1).
◦ Can handle signed or unsigned integers.
• Common Use:
◦ Arithmetic calculations
◦ Loop counters
◦ Array indexing
◦ Pointer arithmetic
Subtraction Instruction (SUB)
• Purpose:
◦ Subtracts one value from another.
• Types of Operands:
◦ Register - Register
◦ Register - Memory
◦ Memory - Register
• Implementation:
◦ Uses binary subtraction with borrowing (just like in elementary subtraction).
◦ For signed integers, the two's complement method is typically used to handle negative results.
• Common Use:
◦ Finding differences
◦ Adjusting values
◦ Decrementing loop counters
Boolean Logic Instructions: AND, OR,
• Most modern instruction sets provide instructions for performing Boolean algebra.
• AND and OR are fundamental instructions for bitwise logic operations in digital circuits and CPU computations.
Operation:
• 1 AND 1 = 1
• 1 AND 0 = 0
• 0 AND 1 = 0 Eg: AND R0, R1, R2
• 0 AND 0 = 0
R0 = R1 AND R2
Example:
• A = 1101 (binary)
• B = 1011 (binary)
• A AND B = 1001 (binary)
OR Instruction (Bitwise OR)
• Purpose:
◦ Performs a bitwise OR between two operands.
◦ Each corresponding bit in the operands is compared, and the result is 1 if at least one of the bits is 1.
Operation:
• 1 OR 1 = 1
• 1 OR 0 = 1
• 0 OR 1 = 1
• 0 OR 0 = 0
Example : OR R0, R1, R2
R0 = R1 OR R2
Example:
• A = 1101 (binary)
• B = 1011 (binary)
• A OR B = 1111 (binary)
Single Operand Instructions: Increment, Decrement
• Most commonly, the instruction set will contain instructions for negating a value, for incrementing a value, for
decrementing a value, and for setting a register to zero.
• On some computers, the increment or decrement instruction causes a branch to occur automatically when zero is
reached; this simplifies the design of loops by allowing the programmer to combine the test and branch into a single
instruction.
• Purpose:
• Modify the value of a single operand by either adding 1 (increment) or subtracting 1 (decrement).
Increment Instruction (INCR)
• Increments (adds 1) to the value of the operand.
Operation:
• Operand = Operand + 1
Example:
• If A = 5, after incrementing:
◦ A = A + 1→A = 6
• INCR R0 ; R0 = R0 + 1
Operation:
• Operand = Operand - 1
Example:
• If B = 10, after decrementing:
◦ B = B - 1→B = 9
• DECR R1 ; R1 = R1 - 1
Shift and Rotate Instructions
• Shift instructions move the data bits left or right one or more bits.
• Rotate instructions also shift the data bits left or right, but the bit that is shifted out of the end is placed into the
vacated space at the other end.
• depending on the design of the particular instruction set, bits shifted out the end of the word may be shifted into a
different register or into the carry or overflow flag bit, or they may simply “fall off the end” and be lost.
• Rotate instructions can be used to process data one bit at a time and are also used in many encryption algorithms.
• There are two types of shifts: Logical Shifts and Arithmetic Shifts.
• Both types shift data left or right but differ in how they handle the shifted-out bits, particularly when dealing with
signed numbers.
Rotate Operations:
• Rotate instructions involve shifting data and wrapping the bits around to the other end.
Logical Shifts
◦ Shifts bits left or right.
◦ Vacated bit positions are filled with zeros.
Example:
• 1010 (binary) → Logical Left Shift → 0100 (binary)
Arithmetic Shifts
◦ Designed to maintain the sign of a signed number when shifting.
Example:
• Left Shift:
◦ 1100 (binary) → Left Arithmetic Shift → 1000 (binary) (doubles the value).
• Right Shift:
◦ 1100 (binary) → Right Arithmetic Shift → 1110 (binary) (halves the value).
Rotate Instructions
• Rotate operations shift bits left or right, and the bits that are shifted out are inserted back into the other end of the word.
Left Rotate (ROL):
• Shifts bits left.
• The leftmost bit that is shifted out is placed into the rightmost position.
• Example:
◦ Rotate 16-bit word by 8 bits to exchange 2 bytes.
◦ Rotating a 32-bit word to exchange lower and upper 16 bits.
FIGURE : Typical Register Shifts and Rotates
Example:
Rotate Left:
Rotate Right:
• The address field was used in various ways: for most instructions, the address field contained the two-digit address
where data for the instruction could be found (e.g., load) or was to be placed (store).
• Memory Address: Specifies where data can be found or stored.
• Branching Instructions: The address field holds the address of the next instruction.
• I/O Instructions: The address field defines the I/O device address (e.g., 01 for input, 02 for output).
Example : LDA 05: Load data from memory location 05 into the accumulator.
• Instruction word can be divided into an opcode and zero or more address fields.
• A simple 32-bit instruction format with one address field are divided into :
Address Field:
• Address can refer to either a memory address or a general-purpose register.
• We’ll use "address" to refer to both types of data locations, and specify memory address when referring specifically to memory.
Example:
• A typical instruction might look like:
◦ Opcode (8 bits) | Address (24 bits)
Explicit Address:
• The address field directly specifies the location of data.
• In the Little Man Computer, an instruction like Load uses an explicit memory address (e.g., LDA 05).
Implicit Address:
• The destination may be implicit in certain instructions.
• For example, in the Little Man Computer, the accumulator is always the destination in load and
arithmetic operations.
Example:
• LDA 05 – Data is loaded from memory location 05 into the accumulator (implicit destination).
Add/Subtract Instructions:
• Require two source addresses:
◦ Source 1: Explicitly defined by the instruction.
◦ Source 2: Implicitly the accumulator.
• The result is placed in the accumulator (implicit destination).
Move Instructions:
• For moving data between registers or memory, two explicit addresses are required.
◦ Source Address: The data’s current location.
◦ Destination Address: The location where data will be moved.
◦ Example:
• A move instruction from register 5 to register 10:
◦ MOV R5, R10: Move data from register 5 to register 10.
Register-to-Register Moves
Example:
• MOV R5, R10: Moves data from register 5 to register 10.
Instruction Example:
• Memory to Register:
◦ LDA R5, 02: Load data from memory location 02 into register 5.
• Register to Register:
• MOV R1, R2: Move data from register 1 to register 2.
Operands:
• The source and destination of data in an instruction.
• These can be explicit (clearly stated in the instruction) or implicit (assumed based on the instruction’s definition).
Types of Instructions:
Operand Fields:
• These are the address fields in the instruction that specify where the data is located or where it will go.
Operand Types:
• Source Operand: The location where data is being taken from.
• Destination Operand: The location where the result of the operation will be placed.
Example:
• Load Instruction:
◦ Source Operand: Memory location (where data is loaded from).
◦ Destination Operand: Accumulator (implicitly used as the destination)
Address Fields:
• Instructions commonly have explicit address fields to specify source and destination locations.
Implicit Addressing:
• The address is not explicitly stated in the instruction. For example, the accumulator is often implicitly used in
load, add, or subtract operations.
Explicit Addressing:
• The address is clearly specified in the instruction (e.g., moving data between registers, memory addresses).
• Unary Instruction:
◦ One operand field.
◦ Example: Increment, Complement (operates on a single operand).
INC R1
• Operand: Register 1 (incremented in place).
• Binary Instruction:
◦ Two operand fields.
◦ Example: Move, Add, Subtract (requires two data locations).
MOV R1, R2
• Source Operand: Register 2
• Destination Operand: Register 1
• Ternary Instruction:
◦ Three operand fields.
◦ Example: Multiply, Divide (operates on three operands, two sources and one destination).
ADD R1, R2, R3
• Source Operand 1: Register 1
• Source Operand 2: Register 2
• Destination Operand: Register 3
Assembly Language
The Role of Assembly Language
• Second-Generation Language: Marked a significant step in programming evolution.
• Closer to Machine Language: Each assembly instruction directly maps to a machine language instruction.
• Still Low-Level: It’s a low-level language, meaning it’s closer to hardware but easier to work with than raw machine code.
Ease of Use Difficult to read, write, modify Easier to understand and use
Machine Instructions 1 instruction = 1 machine 1 instruction = many machine
command commands
Portability Machine-specific Portable across different systems
Syntax Symbols and mnemonics Closer to natural language
Continuum of Programming Languages
• Machine Language (binary)
• Assembly Language (low-level)
• High-Level Languages (e.g., C++, Python)
• Natural Languages (e.g., English)
• Machine languages are the most primitive, and high-level languages are farthest from the hardware.
Why Assembly Language Matters Today
• First Time Questioning Usability: The first programming language to consider the user’s experience.
• Legacy: Set the foundation for creating more accessible programming languages.
• Modern Relevance: The question of making machines easier to use is still at the heart of modern programming language
development.
• The source program needs to be translated into machine language (object program).
• Symbolic Memory Addresses: Use human-readable names instead of numeric (binary) addresses.
• Pseudo-operations: Provide helpful user-oriented services like data generation and easier debugging.
LOAD: MOV A, 1000 -- Load the value at memory address 1000 into register A
• Example:
◦ Assembly Instruction: MOV A, 1000
◦ Translates to Machine Code: 1010 0001 0000 0000 (hypothetical binary representation).
Key Benefits of Assembly Language
• Symbolic Operation Codes: Easier to remember and understand than binary opcodes.
• Symbolic Memory Addresses: Can refer to memory locations by meaningful names instead of numbers.
• Pseudo-operations: Enhance the programmer’s productivity with data generation and other tools.
• Assembly language uses symbolic mnemonics (e.g., LOAD, ADD, STORE) instead of binary opcodes.
• Provides human-readable instructions instead of obscure binary codes like 0000, 0011, etc.
• Helps bridge the gap between high-level programming languages and machine code.
Symbolic Labels in Assembly
• Labels make programs more readable and maintainable.
• Labeling instructions like LOOPSTART: LOAD X provides a permanent reference to an instruction.
• Benefits:
◦ Clarity: Names like LOOPSTART carry meaning, unlike numeric addresses.
◦ Maintainability: Addresses don't need to be manually updated when instructions are added or removed.
Example : LOAD X
.DATA +1
The .DATA +1 could be misinterpreted as an instruction by the CPU.
Avoiding Data/Instruction Confusion
• Ensure data is placed in memory areas that cannot be interpreted as instructions (e.g., after a HALT instruction).
• This prevents data from accidentally being executed.
1. Opcode (Operation Code): The operation to be performed (e.g., MOV, ADD, SUB).
3. Operand(s): The data to be used or manipulated by the instruction (e.g., register, memory address).
5. Addressing Mode: The method by which the operand is located (e.g., direct, indirect, immediate).
Example:
● MOV AX, 5
• Opcode: MOV (Move data)
• Operand: AX (destination register), 5 (source value)
Components of an Assembly Instruction
1. Opcode: The command that tells the CPU what to do (e.g., ADD, SUB).
2. Source Operand: The data or register used in the operation.
3. Destination Operand: Where the result of the operation is stored.
4. Addressing Mode: Specifies how operands are accessed (e.g., register, immediate, direct).
● ADD AX, BX
• Opcode: ADD (Add values)
• Source Operand: BX (Second operand)
• Destination Operand: AX (First operand)
Example of an Assembly Instruction
● MOV AX, [2000h] ; Load value from memory address 2000h into AX
● ADD AX, BX ; Add value in BX to AX
● MOV [3000h], AX ; Store value in AX to memory address 3000h
Explanation:
• MOV AX, [2000h]: The value from memory at address 2000h is moved into the register
AX.
• ADD AX, BX: The value in register BX is added to the value in register AX.
• The fetch-execute instruction cycle is the core process for executing every instruction in
a CPU.
• The cycle involves moving data between registers (e.g., A, GR, PC, IR, MAR, MDR)
and performing basic operations like moving, adding, shifting, or testing data.
• Instruction Register (IR): Holds the instruction while it’s being executed.
• Memory Data Register (MDR): Holds the data fetched from memory.
• Memory Address Register (MAR) & Memory Data Register (MdR): Access memory
Steps in the Fetch-Execute Cycle
Phase 1: Fetch
• Transfer value from PC to MAR
• Fetch instruction from memory to MDR
• Transfer instruction from MDR to IR
Phase 2: Execute
• The CPU decodes and performs the instruction based on what’s in the IR.
• Example: Load instruction, store instruction, add instruction – all follow a similar structure but vary in specific data movement.
Fetch-Execute Cycle for a LOAD Instruction
• Step 1: PC → MAR
○ The value in PC (the current instruction address) is transferred to MAR.
• Step 2: MDR → IR
○ The instruction at the address specified in MAR is fetched from memory and loaded into IR.
Step 3: IR[address] → MAR
○ The address part of the LOAD instruction in IR is transferred to MAR to access the data.
••
Step 4: MDR → A
○ The data from MDR is loaded into the Accumulator (A).
• Step 5: PC + 1 → PC
○ Increment PC to point to the next instruction.
Fetch-Execute Cycle for a STORE Instruction
• Step 1: PC → MAR
○ The value in PC is transferred to MAR.
Step 2: MDR → IR
○ The instruction is fetched from memory and loaded into IR.
• Step 3: IR[address] → MAR
○ The address part of the STORE instruction in IR is transferred to MAR.
•• Step 4: A → MDR
○ The value in Accumulator (A) is stored into MDR to be written back to memory.
• Step 5: PC + 1 → PC
○ Increment PC to the next instruction.
Fetch-Execute Cycle for an ADD Instruction
Step 1: PC → MAR
○ The value in PC is transferred to MAR.
• Step 2: MDR → IR
• ○ The instruction is fetched from memory and loaded into IR.
Step 3: IR[address] → MAR
○ The address part of the ADD instruction in IR is transferred to MAR.
• Step 4: A + MDR → A
• ○ The value in A is added to the value in MDR, and the result is stored back in A.
• Step 5: PC + 1 → PC
○ Increment PC to the next instruction.
Elegance of the Cycle
• Only 5 steps for the load instruction
• 4 steps involve data movement between registers
• The 5th step is an addition (increment PC by 1)
• Simplicity and efficiency of the instruction cycle
• Program Segment:
1. LOAD 90
2. ADD 92
3. STORE 90
• Initial Values:
1. PC = 65
2. Memory:
65: 590 (LOAD 90)
66: 192 (ADD 92)
67: 390 (STORE 90)
90: 111
92: 222
• Each instruction is processed step-by-step through its fetch-execute cycle.
Program Execution Step-by-Step
1. LOAD 90:
○ PC → MAR, fetch instruction, IR → MAR, load MDR → A.
2. ADD 92:
○ PC → MAR, fetch instruction, IR → MAR, A + MDR → A.
3. STORE 90:
○ PC → MAR, fetch instruction, IR → MAR, A → MDR, store back to
memory.