CTE 241 Lecture Notes
CTE 241 Lecture Notes
Lecture notes
0
National Diploma in Computer Engineering
Technology
Course: Introduction to Microprocessors & Assembly Language
Course Code: CTE 241
Semester: Four
Year: Two
Practical: 2 Hours
Theoretical: 1 Hour
Prerequisite: None
Goals
This course aims to equip students with foundational knowledge and skills in microprocessors and assembly
language programming.
General Objectives
1. Understand concepts of microprogramming and microprocessors.
2. Familiarize with basic terms in assembly language.
3. Understand different instruction formats.
4. Know representative groups of instructions in the instruction set.
5. Understand the process of running assembly language programs.
1
Week 1: Microprogramming Introduction
Lecture Outline
1. Introduction to Microprogramming
2. Definition of Microprogramming
3. Control Logic in Microprocessors
4. Microinstructions
5. Benefits of Microprogramming
6. Microprogramming vs. Hardwired Control
7. Conclusion
1. Introduction to Microprogramming
Microprogramming is a fundamental concept in computer architecture that allows the control unit of a
microprocessor to be programmed using a set of instructions called microinstructions. Understanding
microprogramming is essential as it forms the basis for how microprocessors execute higher-level machine
instructions.
In simple words, a Microprocessor is a digital device on a chip that can fetch instructions from memory,
decode and execute them, and give results. It is an important part of a computer architecture without which
you will not be able to perform anything on your computer.
www.geeksforgeeks.org/introduction-of-microprocessor/
2. Definition of Microprogramming
Microprogramming, process of writing microcode for a microprocessor. Microcode is low-level code
that defines how a microprocessor should function when it executes machine-language instructions.
Typically, one machine-language instruction translates into several microcode instructions.
2 www.britannica.com/technology/microprogramming
Fig. 2. Picture of a Microprocessor on a Motherboard of a Computer. techwalla.com
A Microprocessor takes a bunch of instructions in machine language and executes them, telling the
processor what it has to do. The microprocessor performs three basic things while executing the instruction:
• It performs some basic operations like addition, subtraction, multiplication, division, and some
logical operations using its Arithmetic and Logical Unit (ALU). New Microprocessors also perform
operations on floating-point numbers.
• Data in microprocessors can move from one location to another.
• It has a Program Counter (PC) register that stores the address of the next instruction based on the
value of the PC, Microprocessor jumps from one location to another and makes decisions.
3
Clock Speed of different Microprocessor:
8088: more than 5MHz INTEL 80486: 16MHz to 100MHz INTEL i7: 2.66GHz to 3.33GHz
Technical Note
We do not have any 128-bit Microprocessor at work at present one of the reasons for this is that we are a
long way from exhausting the 64-bit address space itself, we use it at a constant rate of roughly 2 bits every
3 years. At present we have only used 48 bits of 64 bits so why require 128-bit address space. Also, 128-bit
Microprocessor would be much slower than the 64 bit Microprocessor.
www.geeksforgeeks.org/introduction-of-microprocessor/
Microprogramming is a method for implementing the control logic of a microprocessor. Instead of using
fixed logic circuits (hardwired control), microprogramming uses a set of microinstructions stored in memory
that dictate the operations performed by the control unit.
Key Points:
• Control Logic: Refers to the circuitry that directs the operation of a microprocessor.
• Microinstructions: These are low-level instructions that define specific actions to be performed by
the microprocessor components.
4
3. Control Logic in Microprocessors
Control logic determines how a microprocessor responds to signals and executes instructions. It manages
tasks such as:
In computer architecture, the control unit is responsible for directing the flow of data and instructions
within the CPU. There are two main approaches to implementing a control unit: hardwired and
micro-programmed.
A hardwired control unit is a control unit that uses a fixed set of logic gates and circuits to execute
instructions. The control signals for each instruction are hardwired into the control unit, so the
control unit has a dedicated circuit for each possible instruction. Hardwired control units are simple
and fast, but they can be inflexible and difficult to modify.
On the other hand, a micro-programmed control unit is a control unit that uses a microcode to
execute instructions. The microcode is a set of instructions that can be modified or updated, allowing
for greater flexibility and ease of modification. The control signals for each instruction are generated
by a microprogram that is stored in memory, rather than being hardwired into the control unit.
5
If we talk about Micro-programmed control units, they are generally slower than hardwired control
units because they require an extra step of decoding the microcode to generate control signals, but
they are more flexible and easier to modify. They are commonly used in modern CPUs because they
allow for easier implementation of complex instruction sets and better support for instruction set
extensions.
To execute an instruction, the control unit of the CPU must generate the required control signal in the
proper sequence. There are two approaches used for generating the control signals in proper
sequence as Hardwired Control unit and the Micro-programmed control unit.
Hardwired Control Unit: The control hardware can be viewed as a state machine that changes from
one state to another in every clock cycle, depending on the contents of the instruction register, the
condition codes, and the external inputs. The outputs of the state machine are the control signals. The
sequence of the operation carried out by this machine is determined by the wiring of the logic
elements and hence named “hardwired”.
• Fixed logic circuits that correspond directly to the Boolean expressions are used to generate
the control signals.
• Hardwired control is faster than micro-programmed control.
• A controller that uses this approach can operate at high speed.
• RISC architecture is based on the hardwired control unit
Diagram of Hardwired Control Unit
6
Micro-programmed Control Unit -
• The control signals associated with operations are stored in special memory units inaccessible
by the programmer as Control Words.
• Control signals are generated by a program that is similar to machine language programs.
• The micro-programmed control unit is slower in speed because of the time it takes to fetch
microinstructions from the control memory.
1. Control Word: A control word is a word whose individual bits represent various control
signals.
2. Micro-routine: A sequence of control words corresponding to the control sequence of a
machine instruction constitutes the micro-routine for that instruction.
3. Micro-instruction: Individual control words in this micro-routine are referred to as
microinstructions.
4. Micro-program: A sequence of micro-instructions is called a micro-program, which is
stored in a ROM or RAM called a Control Memory (CM).
5. Control Store: the micro-routines for all instructions in the instruction set of a computer are
stored in a special memory called the Control Store.
Diagram of Micro-programmed Control Unit
7
4. Microinstructions
Microinstructions are the basic building blocks of microprogramming. Each microinstruction can specify:
Example:
5. Benefits of Microprogramming
Microprogramming offers several advantages:
8
6. Microprogramming vs. Hardwired Control
Hardwired Control:
Microprogrammed Control:
• Advantages: Easier to modify and expand, can implement complex instructions with fewer
hardware changes.
• Disadvantages: May be slower due to the overhead of fetching microinstructions.
9
The differences between hardwired and micro-programmed control units:
Table 1.1
Discussion Points:
10
Basic Structure of a Microprocessor and Characteristics
Explanation:
• Basic Structure:
o ALU: Handles all arithmetic and logic operations.
o Control Unit: Manages instruction execution.
o Registers: Temporary storage for data and instructions.
o Bus System: Allows data transfer between components.
Characteristics:
Explanation:
• Control Unit: Directs the operation of the processor and coordinates the activities of all other
components.
• Arithmetic Logic Unit (ALU): Performs arithmetic and logical operations.
• Registers: Small storage locations used to hold data temporarily during processing.
• Bus System: Facilitates communication between the processor, memory, and I/O devices.
11
7. Conclusion
In summary, microprogramming is a crucial technique for implementing control logic in microprocessors,
facilitating flexibility and ease of modification. Understanding this concept is essential for grasping how
modern processors operate.
Suggested Readings:
Weekly Assignments
Assignment: Write a 1-page essay defining microprocessors and their roles in computer systems. Include
examples of different microprocessors in use today.
12
Week 2: Microprocessor Functions
Lecture Outline
1. Introduction to Microprocessor Functions
2. Data Processing
3. Control Operations
4. Communication with Memory and I/O Devices
5. Conclusion
2. Data Processing
Data processing refers to the manipulation of data to produce meaningful information. This involves several
operations, including:
A. Arithmetic Operations
B. Logic Operations
• AND, OR, NOT, XOR: Logic operations are used to manipulate binary data and perform
comparisons.
• Example: Used in decision-making processes, such as conditional statements in programming.
C. Data Manipulation
• Shifting and Rotating: These operations adjust the position of bits in binary numbers, which can be
crucial for tasks like encryption and data compression.
• Example: Shifting bits to the left can effectively multiply a binary number by two.
• Registers: Microprocessors use registers to temporarily store data during processing. These are
small, fast storage locations within the CPU.
• Example: Data fetched from memory is loaded into registers for quick access during computation.
13
3. Control Operations
Control operations involve managing and directing the various components of a computer system. Key
aspects include:
A. Instruction Fetching
• Fetching Instructions: The microprocessor retrieves instructions from memory, which dictates what
operations to perform.
• Example: Fetching the next instruction in a program during execution.
B. Instruction Decoding
• Decoding Instructions: The microprocessor interprets the fetched instructions to understand what
actions are required.
• Example: Identifying whether the instruction is an arithmetic operation or a data transfer.
C. Execution Control
• Executing Instructions: After decoding, the microprocessor carries out the specified operations,
coordinating with other components as needed.
• Example: Executing a loop in a program that performs calculations repeatedly.
• Generating Control Signals: The control unit of the microprocessor generates signals to coordinate
the activities of the CPU, memory, and I/O devices.
• Example: Sending signals to memory to read or write data.
A. Memory Communication
• Read and Write Operations: The microprocessor sends addresses to memory to read data or store
results.
• Example: Loading a program into RAM from a storage device.
B. I/O Communication
• Interfacing with I/O Devices: Microprocessors communicate with peripherals like keyboards, mice,
printers, and displays.
• Example: Sending data from the CPU to a printer to produce a hard copy.
14
C. Buses
• Data, Address, and Control Buses: Microprocessors use buses to transfer data, addresses, and
control signals between components.
o Data Bus: Carries actual data.
o Address Bus: Specifies the memory location.
o Control Bus: Carries control signals.
D. Input/Output Techniques
• Polling and Interrupts: Two primary methodologies for managing I/O operations.
o Polling: The CPU repeatedly checks the status of I/O devices.
o Interrupts: Devices signal the CPU when they need attention, allowing for more efficient
processing.
Discussion Points:
5. Conclusion
In summary, microprocessors perform essential functions that enable them to process data, control
operations, and communicate with memory and I/O devices. Understanding these functions is crucial for
anyone studying computer architecture and engineering.
Suggested Readings:
This detailed lecture provides students with a comprehensive understanding of microprocessor functions,
preparing them for more advanced topics in computer engineering.
Week 2: Microprogramming
Assignment: Create a diagram illustrating the microprogramming process. Accompany the diagram with
a brief explanation (200 words) of why microprogramming is important in modern processors.
15
Week 3: Structure and Characteristics of a
Microprocessor
Lecture Outline
1. Introduction to Microprocessor Structure
2. Components of a Microprocessor
o Arithmetic Logic Unit (ALU)
o Control Unit (CU)
o Registers
o Bus System
3. Limitations of Hardwired Logic
o Inflexibility
o Complexity in Modifications
4. Conclusion
A microprocessor is the central processing unit (CPU) of a computer, integrated onto a single chip.
It’s a digital, clock-driven, register-based integrated circuit that process binary data according to the
instruction stored in memory, producing results as output. In essence, a microprocessor is the “brain” of a
computer, responsible for carrying out instructions and managing the flow of data within the system.
RISC (Reduced Instruction Set Computer) which employs smaller, simpler set of instructions that can be
executed faster. Typical examples are: IBM RS6000, MC88100, DEC Alpha 21064, etc.
CISC (Complex Instruction Set Computer) that uses a larger, more complex set of instructions that can
perform more work in a single instruction. Examples include: Intel (386, 486, etc.), Pentium (Pro, II, III,
etc.), Motorola (68000, 68020, etc.).
As a case study, we shall be exploring the Intel 8085 microprocessor’s block diagram in the figure below
where we would learn about its internal architecture, which consist of three main units: the Processing Unit,
the Instruction unit, and the Storage and Interface Unit.
16
Fig. 6. Microprocessor 8085 Block Diagram and Architecture.
17
2. Components of a Microprocessor
The Intel 8085 microprocessor's block diagram in the figure above shows its internal architecture, which
consists of three main units: the Processing Unit, the Instruction Unit, and the Storage and Interface Unit.
The Processing Unit includes the Arithmetic Logic Unit (ALU), accumulator, and flag registers. The
Instruction Unit contains the instruction register and decoder. The Storage and Interface Unit includes
registers, the program counter, stack pointer, and address/data latches.
1. Processing Unit:
Arithmetic Logic Unit (ALU): Performs arithmetic (addition, subtraction, etc.) and logical (AND, OR, NOT,
etc.) operations.
Accumulator: An 8-bit register used to store the results of ALU operations and as an operand for many
instructions.
Flag Register: A register that stores status flags (like zero, carry, sign, parity) indicating the outcome of ALU
operations.
2. Instruction Unit:
Instruction Register: Temporarily stores the current instruction fetched from memory.
Decoder: Interprets the instruction in the instruction register and sends control signals to other units to execute
the instruction.
3. Storage and Interface Unit:
Registers:
The 8085 has several registers for temporary storage of data and addresses, including:
General-purpose registers: B, C, D, E, H, and L. They can be used individually as 8-bit registers or paired
together as 16-bit registers (BC, DE, HL).
Program Counter (PC): A 16-bit register that holds the memory address of the next instruction to be
executed.
Stack Pointer (SP): A 16-bit register that points to the top of the stack, used for temporary data storage and
function calls.
Address and Data Buses:
Address Bus (16-bit): Carries the memory address to access data or instructions.
Data Bus (8-bit): Carries data between the microprocessor and memory or peripherals.
Interrupt Controller:
Manages interrupt requests from external devices, allowing the processor to respond to urgent events.
Serial I/O Control:
Handles serial data communication.
Timing and Control Unit:
Generates timing signals and control signals to synchronize and coordinate the operations of all the other units.
18
3. Limitations of Hardwired Logic
A. Inflexibility
• Definition: Hardwired logic is designed with fixed circuits that implement specific functions.
• Implications:
o Changes in instruction set or functionality require significant hardware redesign.
o Difficult to adapt to new processing requirements or technologies.
B. Complexity in Modifications
4. Conclusion
In summary, the structure of a microprocessor consists of several critical components, each playing a vital
role in processing and managing data. Understanding the functions of the ALU, Control Unit, registers, and
bus system is essential for comprehending how microprocessors operate. Additionally, recognizing the
limitations of hardwired logic highlights the advantages of microprogrammed control systems.
Discussion Points:
Suggested Readings:
This lecture provides a thorough understanding of the structure and characteristics of microprocessors,
equipping students with the knowledge necessary for advanced topics in computer engineering.
Assignment: Compile a list of at least 10 instructions from a specific microprocessor's instruction set
(e.g., x86). For each instruction, provide a brief description of its function and usage.
19
Week 4: Basics of Assembly Language
Lecture Outline
Definitions
Definitions
1. Operation Code (Opcode)
• Definition: The part of an instruction that specifies the operation to be performed (e.g., ADD, SUB).
• Example: In the instruction ADD R1, R2, the opcode is ADD.
2. Operand
3. Instruction
• Definition: A complete command given to the microprocessor, consisting of an opcode and its
operands.
• Example: ADD R1, R2 is an instruction that tells the processor to add the values in R1 and R2.
4. Registers
• Definition: Small, fast storage locations within the CPU that hold data temporarily during
processing.
• Examples:
o Accumulator (ACC): Used to store intermediate results.
o General Purpose Registers: Used for various operations as needed
20
Machine Instructions in Computer Systems
1. Definition and Structure of Machine Instructions
• Definition: Machine instructions are binary-coded commands that the CPU understands and
executes directly.
• Structure: Typically consists of an opcode followed by one or more operands.
o Example Structure: Opcode Operand1 Operand2
• Binary Representation:
o 00000001 00000010 could represent an instruction to add two numbers.
• Hexadecimal Representation:
o 0x01 0x02 represents the same instruction in a more readable format.
• Fetch-Decode-Execute Cycle:
o Fetch: Retrieve the instruction from memory.
o Decode: Interpret the instruction to determine the operation and operands.
o Execute: Perform the operation specified by the instruction.
21
Practical Session
Activity 1: Illustrating Examples of Machine Instructions
• Objective: Identify and categorize examples into machine language or assembly language.
• Task:
o Present students with a mix of machine and assembly language examples. Students must
categorize each correctly.
Assessment
Questions:
Practical Assignment
Instructions:
6. Convert the following arithmetic operations into their corresponding machine instructions:
o Add the values in registers R1 and R2, store the result in R3.
o Subtract the value in register R4 from the value in register R5, store the result in R6.
o Multiply the values in registers R7 and R8, store the result in R9.
22
Suggested Readings:
• "Programming from the Ground Up" by Jonathan Bartlett (2nd Edition, 2021)
• "Computer Systems: A Programmer's Perspective" by Bryant and O'Hallaron (4th Edition,
2020)
This detailed lecture plan for Week 4 provides a structured approach to teaching the basics of assembly
language, ensuring students gain a solid understanding of key concepts and practical skills.
Assignment: Write a simple assembly language program that prints "Hello, World!" to the console.
Comment each line to explain what it does.
4. Assessment Questions
5. Conclusion
Objective: Convert simple arithmetic operations into their corresponding machine instructions.
Instructions:
1. Given Operations:
o Add the values in registers R1 and R2, store the result in R3.
o Subtract the value in register R4 from the value in register R5, store the result in R6.
o Multiply the values in registers R7 and R8, store the result in R9.
2. Example Conversion:
o Operation: ADD R1, R2 → Machine Instruction: 00000001 R1 R2 R3
Objective: Identify and categorize given examples into either machine language or assembly language.
Instructions:
1. Examples to Categorize:
o ADD R1, R2
o 10110000 00000001
o MOV A, B
o 00000001 00000010
2. Categorization Table
24
4. Questions
1. Convert the following operations into machine instructions:
o Add the values in registers R2 and R3, store the result in R4.
o Divide the value in R6 by the value in R7, store the result in R5.
2. Categorize these examples:
o SUB R3, R1
o 11001100 10101010
o AND R4, R5
o 11110000 00000001
• Assignment:
o Submit a report that includes:
▪ Converted machine instructions for at least three arithmetic operations.
▪ A categorized list of machine and assembly language examples with justifications.
Discussion Points:
• What challenges did you face when converting operations to machine instructions?
• How does distinguishing between machine and assembly language help in programming?
5. Conclusion
In this practical session, you applied your knowledge by converting arithmetic operations into machine
instructions and distinguishing between machine and assembly languages. Understanding these concepts is
crucial for programming at a low level and grasping how CPUs execute tasks.
Assignment: Research and write a 2-page paper on the different types of registers in a CPU. Include their
functions and importance in processing data.
25
Weeks 6-8: Instruction Formats
Lecture Outline
1. Introduction to Instruction Formats
5. Addressing Modes
• Relative
• Absolute
• Register
• Immediate
• Indexed
6. Practical Application
7. Assessment Questions
8. Conclusion
Components:
26
Example Format: Opcode | Operand1 | Operand2 | ... |
binaryterms.com
Example:
Types of Registers:
1. General Purpose Registers (GPRs): Used for a variety of operations (e.g., R1, R2).
2. Special Purpose Registers:
o Accumulator (ACC): Stores intermediate results.
o Program Counter (PC): Holds the address of the next instruction.
o Instruction Register (IR): Holds the current instruction being executed.
o Stack Pointer (SP): Points to the current top of the stack.
Functions:
27
5. Addressing Modes
Addressing modes determine how the operand of an instruction is accessed.
It specifies the way; the effective address of an operand is represented in the instruction.
Effective Address (EA): Effective address is the address of the exact memory location where the value of
the operand is present.
Some addressing mode efficiently allows referring to a large range of area like a linear array of addresses
and list of addresses. Addressing mode describes a flexible and efficient way to define complex effective
address.
Generally, the programs are written in a high-level language, as it is a convenient way to define the variables
and operations that the programmer needs to perform on the variables. Later, this program is compiled to
generate the machine code. The machine code has low-level instructions.
The low-level instruction has opcode and operands. Addressing mode has nothing to do with the opcode
part. It focuses on presenting the operand’s address in the instructions.
We have the list below showing the various kind of addressing modes.
A. Relative Addressing
• Definition: The operand's address is specified as an offset from the current instruction address.
• Example: If the PC is at address 1000 and the offset is 20, the effective address is 1020.
X(PC)
EA = X + (PC)
As here the operand addresses are found relative to the program counter. That’s why it is referred to as
relative address mode.
28
B. Absolute Addressing
The direct addressing mode is also known as Absolute Addressing mode. Here, the instruction
contains the address of the location in memory where the value of the operand is stored.
EA = A
Add R2, A
Store R2, B
The Add instruction includes the memory location A which has the value to be added to the content of
register R2. Similarly, the Store instruction has the address of memory location B where the content of
register R2 will be stored. Below we have a figure showing the direct addressing of the operand A in the
Add instruction of the example above.
29
Direct Mode
C. Register Addressing
D. Immediate Addressing
In immediate addressing mode, the value of the operand is explicitly mentioned in the instruction. Here,
effective address is not required as the operand is explicitly defined in instruction.
The Add instruction, adds 100 to R2’s content. The # sign in front of the value indicates the immediate
value to be operated. If a value does not have # sign in front of it then it is the address of a memory
location.
The next instruction Store considers the immediate value 100H as address as it does not have # sign in
front of it. The Store instruction stores the content of R2 at memory location 100H. In the figure below
we have shown the Store instruction of the above examples.
30
Fig. 8. Diagram of Immediate Addressing Mode Illustration.
Advantage: In the immediate addressing mode the memory reference is not required as the value is
explicitly present in the instruction
Disadvantage: The instruction format provides a limited size for the operand. So, the immediate
addressing mode has limited space for immediate value.
E. Indexed Addressing
Index addressing mode is helpful when the instructions in the program are accessing the array or the
large range of memory addresses. In this mode, the effective address is generated by adding a constant
to the register’s content. The content of the register does not change.
X(R)
EA = X + (R)
31
For example, consider the instruction below:
Load R2, A
The above instructions will load the register R3, R4, R5, R6 with the contents, present at the successive
memory addresses from memory location A correspondingly.
32
6. Practical Application
Activity 1: Illustrating Different Types of Instructions
Objective: Students will illustrate various instruction formats by writing assembly instructions.
Example Instructions:
Objective: Write and execute assembly code demonstrating different addressing modes and instruction
formats.
Example
7. Assessment Questions
1. Explain the following terms:
o Opcode
o Operand
o Instruction Format
2. List and describe the different types of addressing modes.
3. Given the instruction LOAD R1, (R2 + 10), identify the addressing mode used and explain
why.
• Assignment:
o Submit a report that includes:
▪ A detailed explanation of instruction formats with examples.
▪ A list of addressing modes with specific examples illustrating each mode.
▪ Write assembly code demonstrating at least two different addressing modes.
Discussion Points:
8. Conclusion
33
In these weeks, we have covered the essential concepts of instruction formats, types of registers, and
addressing modes. Understanding these concepts is crucial for programming in assembly language and
optimizing the performance of microprocessors.
2. Groups of Instructions
• Arithmetic Instructions
• Logic Instructions
• Branch Instructions
• Bit Manipulation and MOV Instructions
3. Practical Application
4. Assessment Questions
5. Conclusion
34
2. Groups of Instructions
A. Arithmetic Instructions
B. Logic Instructions
C. Branch Instructions
35
D. Bit Manipulation and MOV Instructions
• Bit Manipulation Instructions: Used to manipulate specific bits within a byte or word.
o Examples: Shift left (SHL), shift right (SHR), rotate bits (ROL, ROR).
• MOV Instructions: Used to transfer data from one location to another.
o Example: MOV R1, R2 (Moves the contents of R2 into R1).
3. Practical Application
Activity 1: Writing Programming Code for Arithmetic and Logic Operations
Objective: Students will write assembly code to perform various arithmetic and logic operations.
Example
; Arithmetic Operations
ADD R1, R2 ; R1 = R1 + R2
SUB R3, R4 ; R3 = R3 - R4
MUL R5, R6 ; R5 = R5 * R6
; Logic Operations
AND R1, R2 ; R1 = R1 AND R2
OR R3, R4 ; R3 = R3 OR R4
NOT R5 ; R5 = NOT R5
XOR R1, R2 ; R1 = R1 XOR R2
Example
LABEL:
; Code to execute if R1 == R2
END:
; Program ends here
36
4. Questions
1. Define the following terms:
o Instruction Set
o Arithmetic Instructions
o Logic Instructions
2. Write assembly code for the following operations:
o Add two registers and store the result in a third register.
o Perform a bitwise AND operation on two registers.
3. Explain the difference between conditional and unconditional branch instructions.
• Assignment:
o Submit a report that includes:
▪ A detailed explanation of instruction groups with examples.
▪ Write assembly code demonstrating at least one arithmetic operation, one logic
operation, and one branch instruction.
Discussion Points:
5. Conclusion
In these weeks, we explored various instruction sets and their groups, including arithmetic, logic, and branch
instructions. Understanding these concepts is fundamental for writing efficient assembly language programs.
3. Practical Application
37
• Demonstrating Running Assembly Programs with String Operations
4. Assessment Questions
5. Conclusion
Example Operations:
1. Copying a String:
3. Practical Application
Activity: Demonstrating Running Assembly Programs with String Operations
Objective: Students will write and execute assembly programs that utilize string operations.
section .data
source db 'Hello, World!', 0 ; Null-terminated string
destination db 20 dup(0) ; Allocate space for the copied string
section .text
global _start
_start:
; Copy string
MOV SI, source ; Source Index
MOV DI, destination ; Destination Index
MOV CX, 14 ; Length of the string including null terminator
REP MOVSB ; Copy the string byte by byte
39
4. Questions
1. Define string operations in the context of assembly language.
2. List common string operations and provide a brief description of each.
3. Write assembly code to copy a string from one location to another.
4. Explain how string comparison works in assembly language.
• Assignment:
o Submit a report that includes:
▪ A detailed explanation of string operations with examples.
▪ Write assembly code demonstrating at least one string operation (copying,
concatenating, or searching).
Discussion Points:
5. Conclusion
In these weeks, we focused on running assembly programs and performing string operations. Understanding
how to manipulate strings is essential for effectively handling text data in assembly language.
40
Weekly Assignments
Assignment: Write an assembly language program that performs basic arithmetic operations (addition,
subtraction, multiplication, division) on user-provided inputs. Include input/output handling.
Assignment: Implement a program that demonstrates the use of logical instructions (AND, OR, NOT) in
assembly language. Include examples of each operation and comment on their results.
Assignment: Create a table comparing different instruction formats (fixed vs. variable length) used in
assembly language. Provide examples of each format.
Assignment: Write a report (1-2 pages) on different addressing modes (immediate, direct, indirect,
indexed). Include examples of assembly language instructions that use these modes.
Assignment: Develop an assembly language program that performs string manipulation operations, such as
searching for a substring and replacing it. Document the code with comments explaining its functionality.
Assignment: Create a program that demonstrates input/output operations in assembly language. Include
error handling for invalid input and document the program's flow.
Assignment: Write an assembly program that uses conditional and unconditional branching. Create a
flowchart that illustrates the program's logic and branching decisions.
Assignment: Implement a program that utilizes procedures and macros to perform repetitive tasks. Explain
the benefits of using procedures and macros in your code documentation.
Assignment: Develop a program that implements advanced string operations, such as concatenation and
reversing a string. Comment your code thoroughly.
Assignment: Prepare a capstone project that combines multiple concepts learned throughout the course.
This could be a complex program that incorporates arithmetic operations, string manipulation, and
branching. Include a 2-page report summarizing your project, the challenges faced, and what you learned.
41
Reference
Textbooks
Computer Organization and Design: The Hardware/Software Interface by David A. Patterson and John L.
Hennessy (5th Edition, 2020)
Research Papers
Online Resources
• What are Addressing Modes? Types, Effective Address, Advantages and Disadvantages - Binary Terms
• https://binaryterms.com/addressing-modes-and-its-types.html
• https://www.geeksforgeeks.org/computer-organization-hardwired-vs-micro-programmed-control-
unit/
John O A Otaru
42