Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
93 views43 pages

CTE 241 Lecture Notes

The document outlines the course CTE 241: Introduction to Microprocessors & Assembly Language at the College of Agriculture Science and Technology, focusing on foundational knowledge in microprocessors and assembly language programming. It covers key concepts such as microprogramming, control logic, and the structure of microprocessors, along with their functions in data processing and communication with memory and I/O devices. The course aims to equip students with essential skills for understanding and working with microprocessors in computer systems.

Uploaded by

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

CTE 241 Lecture Notes

The document outlines the course CTE 241: Introduction to Microprocessors & Assembly Language at the College of Agriculture Science and Technology, focusing on foundational knowledge in microprocessors and assembly language programming. It covers key concepts such as microprogramming, control logic, and the structure of microprocessors, along with their functions in data processing and communication with memory and I/O devices. The course aims to equip students with essential skills for understanding and working with microprocessors in computer systems.

Uploaded by

Omokoje
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 43

College of Agriculture Science and Technology, Lafia, Nasarawa State .

Department of Computer Engineering Technology

CTE 241: Introduction to Microprocessors & Assembly Language

Lecture notes

Prepared by John O A Otaru

0
National Diploma in Computer Engineering
Technology
Course: Introduction to Microprocessors & Assembly Language
Course Code: CTE 241

Contact Hours: 45 Hours

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.

Fig1. Picture of a Microprocessor Chip. boxofnotes.com

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

Block Diagram of a Microprocessor

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.

A typical Microprocessor structure looks like this.

Fig. 3. Structure of a Microprocessor. www.geeksforgeeks.org/introduction-of-microprocessor/

3
Clock Speed of different Microprocessor:

16-bit Microprocessor 32-bit Microprocessor 64-bit Microprocessor


8086: 4.7MHz, 8MHz, 10MHz INTEL 80386: 16MHz to 33MHz INTEL CORE-2: 1.2GHz to 3GHz

8088: more than 5MHz INTEL 80486: 16MHz to 100MHz INTEL i7: 2.66GHz to 3.33GHz

80186/80188: 6MHz PENTIUM: 66MHz INTEL i5: 2.4GHz to 3.6GHz

80286: 8MHz INTEL i3: 2.93GHz 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:

• Fetching instructions from memory


• Decoding instructions
• Executing operations

Fig. 4. Fetch Decode Execute Cycle. SlideServe

Types of Control Logic:

1. Hardwired Control: Uses fixed logic circuits. It is fast but inflexible.


2. Microprogrammed Control: Uses programmable memory to store control sequences, allowing for
easier modifications and enhancements.

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

Fig. 5. 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.

Some Important Terms

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

Fig. 5. Diagram of Micro-programmed Control Unit.

7
4. Microinstructions
Microinstructions are the basic building blocks of microprogramming. Each microinstruction can specify:

• Operations to be performed (e.g., loading data into registers)


• Timing and sequencing of operations
• Status flags and control signals

Example:

Consider the microinstruction for an addition operation:

• Load first operand from memory to register A


• Load second operand from memory to register B
• Execute the addition and store the result in register C

5. Benefits of Microprogramming
Microprogramming offers several advantages:

• Flexibility: Changes in instruction sets or functionalities can be easily implemented by modifying


microinstructions.
• Simplicity: Simplifies the design of control units compared to complex hardwired systems.
• Maintainability: Easier to update and maintain microprogrammed control systems.

8
6. Microprogramming vs. Hardwired Control
Hardwired Control:

• Advantages: Faster execution, less memory usage.


• Disadvantages: Inflexible, difficult to modify, and requires complex circuitry.

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.

Limitations of Hardwired Logic and Justification for Microprocessors

• Limitations of Hardwired Logic:

o Lack of flexibility: Modifications require physical changes to the circuitry.

o Increased complexity in design as the instruction set grows.

• Justification for Using Microprocessors:

o Easier to update and modify instruction sets through software changes.

o More efficient in handling complex tasks due to microprogramming capabilities.

9
The differences between hardwired and micro-programmed control units:

Micro-programmed Control Unit


Hardwired Control Unit

Fixed set of logic gates and Microcode stored in memory


Implementation
circuits

Less flexible, difficult to More flexible, easier to modify


Flexibility
modify

Supports limited instruction Supports complex instruction sets


Instruction Set
sets

Complex design, more difficult to


Simple design, easy to
Complexity of Design implement
implement

Slower operation due to microcode


Speed Fast operation decoding

Easier to debug and test


Debugging and Testing Difficult to debug and test

Larger size, higher cost


Size and Cost Smaller size, lower cost

Maintenance and Difficult to upgrade and


Easier to upgrade and maintain
Upgradability maintain

Table 1.1

Discussion Points:

• How does microprogramming enhance processor capabilities?


• What are some real-world examples of microprogrammed control units?

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:

• Speed: Determines how fast the processor can execute instructions.


• Word Length: The number of bits processed at one time (e.g., 8-bit, 16-bit).
• Instruction Set: The set of operations the microprocessor can perform.

Functions of a Microprocessor in a Computer System

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:

• "Computer Organization and Design" by Patterson and Hennessy


• Recent research papers on microprogramming techniques in IEEE Transactions.

This lecture provides a comprehensive introduction to microprogramming, offering students a foundational


understanding necessary for further study in computer architecture.

Weekly Assignments

Week 1: Introduction to Microprocessors

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

1. Introduction to Microprocessor Functions


Microprocessors are the heart of computing systems, responsible for executing instructions and performing
calculations. Understanding the core functions of a microprocessor is essential for grasping how computers
operate. In this lecture, we will discuss three primary functions: data processing, control operations, and
communication with memory and I/O devices.

2. Data Processing
Data processing refers to the manipulation of data to produce meaningful information. This involves several
operations, including:

A. Arithmetic Operations

• Addition, Subtraction, Multiplication, Division: These are fundamental operations that


microprocessors perform on numerical data.
• Example: Performing calculations in spreadsheets or executing complex algorithms in software.

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.

D. Data Storage and Retrieval

• 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.

D. Status and Control Signals

• 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.

4. Communication with Memory and I/O Devices


Microprocessors must communicate effectively with both memory and input/output (I/O) devices to function
properly.

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:

• Why is data processing critical in modern computing?


• How do control operations enhance the efficiency of a microprocessor?

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:

• "Computer Architecture: A Quantitative Approach" by Hennessy and Patterson


• Recent articles on microprocessor architecture in journals like IEEE Transactions on
Computers.

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

1. Introduction to Microprocessor Structure


Understanding the structure of a microprocessor is fundamental to grasping how it operates and processes
information. A microprocessor consists of several key components that work together to execute instructions
and manage data. This lecture will explore these components and discuss the limitations of hardwired logic.

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.

Two types of microprocessors are common:

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

• Definition: Modifying hardwired logic can be complex and time-consuming.


• Implications:
o Any alteration may necessitate a complete redesign of the circuit, making it costly and
inefficient.
o Maintenance and upgrades become challenging, leading to increased downtime.

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:

• How do the components of a microprocessor work together to execute instructions?


• In what scenarios might a microprocessor benefit from a microprogrammed control system over
hardwired logic?

Suggested Readings:

• "Computer Organization and Design: The Hardware/Software Interface" by Patterson and


Hennessy
• Research articles on microprocessor architecture and design in journals like IEEE
Transactions on Computers.

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.

Week 3: Instruction Sets

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

1. Operation Code (Opcode)


2. Operand
3. Instruction
4. Registers

Machine Instructions in Computer Systems

1. Definition and Structure of Machine Instructions


2. Examples of Machine Instructions
3. Execution of Machine Instructions

Differences Between Machine Language and Assembly Language

1. Characteristics of Machine Language


2. Characteristics of Assembly Language
3. Comparison and Use Cases

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

• Definition: The data or address used by the operation code.


• Example: In ADD R1, R2, the operands are R1 and R2.

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

2. Examples of Machine Instructions

• 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.

3. Execution of Machine Instructions

• 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.

Differences Between Machine Language and Assembly Language


1. Characteristics of Machine Language

• Nature: Binary code that is hard for humans to read.


• Directly Executable: The CPU can execute it without further translation.
• Example: 10110000 could represent an instruction in machine language.

2. Characteristics of Assembly Language

• Nature: Uses mnemonics and symbolic representations for instructions.


• Requires Assembler: Needs a program (assembler) to convert it to machine language.
• Example: MOV A, B is a more human-readable form of instruction.

4. Comparison and Use Cases

Feature Machine Language Assembly Language


Readability Hard to read Easier to read
Execution Directly executable by CPU Needs an assembler
More flexible and easier to
Flexibility Inflexible
modify
System programming and
Use Case Low-level programming
embedded systems
Table 1.2

21
Practical Session
Activity 1: Illustrating Examples of Machine Instructions

• Objective: Convert simple arithmetic operations into machine instructions.


• Task:
o Students will write the machine code for given operations (e.g., ADD, SUB) and represent their
binary forms.

Activity 2: Distinguishing Machine Language from Assembly Language

• 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:

1. Define the following terms:


o a. Operation Code (Opcode)
o b. Operand
o c. Instruction
o d. Register
2. Multiple Choice: What is the main purpose of an opcode?
o A) To specify the data to be processed
o B) To specify the operation to be performed
o C) To store temporary data
o D) To convert assembly language to machine language
3. True/False: Assembly language is directly executable by the CPU.
o True
o False
4. Fill in the blanks: The instruction ADD R1, R2 has an opcode of __________ and operands of
__________ and __________.
5. Short Answer: What is the difference between machine language and assembly language?

Practical Assignment

Objective: Convert a list of arithmetic operations into machine instructions.

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.

Week 4: Assembly Language Basics

Assignment: Write a simple assembly language program that prints "Hello, World!" to the console.
Comment each line to explain what it does.

Week 5: Practical Application of Assembly


Language
Lecture Outline
1. Introduction to Practical Applications

2. Illustrating Examples of Machine Instructions

3. Distinguishing Machine Language from Assembly Language

4. Assessment Questions

5. Conclusion

1. Introduction to Practical Applications


In this session, we will focus on applying the concepts learned in previous weeks regarding assembly
language and machine instructions. Students will engage in hands-on activities to convert arithmetic
operations into machine instructions and distinguish between machine and assembly languages.
23
2. Illustrating Examples of Machine Instructions
Activity 1: Convert Arithmetic Operations

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

Example Conversion Table

Operation Machine Instruction


Add R1, R2 to R3 00000001 R1 R2 R3
Sub R4 from R5 to R6 00000010 R4 R5 R6
Multiply R7 and R8 to R9 00000011 R7 R8 R9

3. Distinguishing Machine Language from Assembly Language


Activity 2: Categorizing Examples

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

Example Type Justification


ADD R1, R2 Assembly Language Uses mnemonics, human-readable
10110000 00000001 Machine Language Binary code directly executable by the CPU
MOV A, B Assembly Language Mnemonic representation for a data move operation
00000001 00000010 Machine Language Binary code directly executable by the CPU
Table 1.3

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.

Week 5: Data Types and Registers

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

2. Explanation of Instruction Formats

3. Fields of Instruction Formats

4. Types and Functions of Registers

5. Addressing Modes

• Relative
• Absolute
• Register
• Immediate
• Indexed

6. Practical Application

• Illustrating Different Types of Instructions


• Demonstrating Using Assembly Code

7. Assessment Questions

8. Conclusion

1. Introduction to Instruction Formats


In these weeks, we will explore instruction formats, which are critical for understanding how instructions are
structured and executed in a microprocessor. We'll also cover the types of registers and addressing modes
used to access data.

2. Explanation of Instruction Formats


Instruction Format: The way in which the components of an instruction are organized in a binary
representation. This typically includes the opcode and its operands.

Components:

• Opcode: Specifies the operation to be performed.


• Operands: Specify the data or addresses involved in the operation.

26
Example Format: Opcode | Operand1 | Operand2 | ... |

binaryterms.com

3. Fields of Instruction Formats


Instruction formats can be classified based on the number of fields they contain, typically including:

1. Opcode Field: Specifies the operation.


2. Address Field(s): Specifies the location(s) of the operands.
3. Mode Field (optional): Indicates the addressing mode.

Example:

• Format with One Operand:


o Opcode Operand
• Format with Two Operands:
o Opcode Operand1 Operand2

4. Types and Functions of Registers


Registers are small, fast storage locations within the CPU used for temporary data storage during instruction
execution.

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:

• Temporary data storage.


• Fast access for the CPU during operations.
• Managing control flow (e.g., PC for instruction sequencing).

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.

The symbolic representation of relative address mode is

X(PC)

The effective address for it would be:

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.

Advantage: Relative addressing mode doesn’t require memory references.

Disadvantage: Relative addressing mode doesn’t have any disadvantage as such.

28
B. Absolute Addressing

• Definition: The operand's address is given directly in the instruction.


• Example: LOAD A, 5000 means load data from memory address 5000.

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.

Here, the effective address is the address of memory location.

EA = A

For example, observe the examples below:

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.

Fig. 7. Diagram of Absolute (Direct) Addressing Mode Illustration.

29
Direct Mode

Advantage: Direct addressing mode is the simplest of all addressing mode.

Disadvantage: Direct addressing mode provides a limited address space.

C. Register Addressing

• Definition: The operand is located in a register.


• Example: ADD R1, R2 means add the contents of R1 and R2.

D. Immediate Addressing

• Definition: The operand is specified directly in the instruction.


• Example: MOV R1, 10 means move the value 10 into register R1.

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.

Let us see the example of immediate addressing mode:

Add R2, #100

Store R2, 100H

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

• Definition: Combines a base address from a register and an offset.


• Example: LOAD R1, (R2 + 10) means load the value at the address in R2 plus 10 into R1.

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.

The symbolic representation of index addressing mode is denoted as:

X(R)

And the effective address is denoted by

EA = X + (R)
31
For example, consider the instruction below:

Load R2, A

Load R3, (R2)

Load R4, 4(R2)

Load R5, 8(R2)

Load R6, 12(R2)

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.

Fig. 9. Diagram of Index Addressing Mode Illustration.

32
6. Practical Application
Activity 1: Illustrating Different Types of Instructions

Objective: Students will illustrate various instruction formats by writing assembly instructions.

Example Instructions:

• ADD R1, R2 (Register Addressing)


• LOAD R1, 5000 (Absolute Addressing)
• MOV R1, #10 (Immediate Addressing)

Activity 2: Demonstrating Using Assembly Code

Objective: Write and execute assembly code demonstrating different addressing modes and instruction
formats.

Example

MOV R1, #10 ; Immediate Addressing


LOAD R2, 5000 ; Absolute Addressing
ADD R3, R1 ; Register Addressing

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:

• How do instruction formats impact the efficiency of assembly language programs?


• Why is it important to understand different addressing modes when writing assembly code?

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.

Weeks 9-13: Instruction Set Groups


Lecture Outline
1. Definition of Instruction Set

2. Groups of Instructions

• Arithmetic Instructions
• Logic Instructions
• Branch Instructions
• Bit Manipulation and MOV Instructions

3. Practical Application

• Writing Programming Code for Arithmetic and Logic Operations


• Implementing Branch Instructions

4. Assessment Questions

5. Conclusion

1. Definition of Instruction Set


Instruction Set: An instruction set is a collection of machine-level instructions that a microprocessor can
execute. It defines the operations, data types, registers, addressing modes, and memory architecture.

Components of an Instruction Set:

• Types of Instructions: Arithmetic, logic, control, data movement, etc.


• Instruction Formats: The structure of how instructions are represented in binary.

34
2. Groups of Instructions
A. Arithmetic Instructions

• Definition: Instructions that perform arithmetic operations on data.


• Common Operations:
o Addition: ADD R1, R2 (Adds the values in R1 and R2)
o Subtraction: SUB R1, R2 (Subtracts the value in R2 from R1)
o Multiplication: MUL R1, R2 (Multiplies the values in R1 and R2)
o Division: DIV R1, R2 (Divides the value in R1 by that in R2)

B. Logic Instructions

• Definition: Instructions that perform logical operations on binary data.


• Common Operations:
o AND: AND R1, R2 (Performs a bitwise AND operation)
o OR: OR R1, R2 (Performs a bitwise OR operation)
o NOT: NOT R1 (Inverts the bits in R1)
o XOR: XOR R1, R2 (Performs a bitwise exclusive OR operation)

C. Branch Instructions

• Definition: Instructions that change the flow of control in a program.


• Types:
o Conditional Branch: Executes if a condition is met (e.g., BEQ - branch if equal).
o Unconditional Branch: Always executes (e.g., JMP - jump to a specified address).

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

Activity 2: Implementing Branch Instructions

Objective: Students will implement branch instructions in their assembly code.

Example

; Conditional Branch Example


CMP R1, R2 ; Compare R1 and R2
BEQ LABEL ; Branch to LABEL if R1 == R2

; Unconditional Branch Example


JMP END ; Jump to END unconditionally

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:

• How do different instruction types affect program performance?


• What are the practical applications of branch instructions in programming?

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.

Weeks 14-15: Running Assembly Programs


Lecture Outline
1. Description of String Operations

2. Writing Assembly Code Using String Operations

3. Practical Application
37
• Demonstrating Running Assembly Programs with String Operations

4. Assessment Questions

5. Conclusion

1. Description of String Operations


String Operations: String operations involve manipulating sequences of characters in memory. These
operations are crucial for handling text data in assembly language programs.

Common String Operations:

• Copying Strings: Duplicating one string into another location.


• Concatenation: Joining two or more strings together.
• Comparison: Checking if two strings are identical.
• Searching: Finding a specific character or substring within a string.

Example Operations:

• Copy: Moving the contents of one string to another.


• Length Calculation: Determining the number of characters in a string.
• Substrings: Extracting part of a string based on defined indices.

2. Writing Assembly Code Using String Operations


When working with strings in assembly language, you typically use specific instructions or a combination of
instructions to perform operations.

Example Assembly Instructions for String Operations:

1. Copying a String:

; Assume DS points to the source string and DX points to the destination


MOV SI, DS ; Source Index
MOV DI, DX ; Destination Index
MOV CX, length ; Length of the string
REP MOVSB ; Repeat Move String Byte

2. Concatenating Two Strings:


o First, move the first string to a destination.
38
oThen, append the second string after it.
3. Comparing Two Strings:

; Assume SI and DI point to the two strings


MOV CX, length ; Length of the strings
CLD ; Clear Direction Flag
REP CMPSB ; Compare String Byte by Byte
JZ strings_equal ; Jump if strings are equal

4. Searching for a Character:

; Assume SI points to the string and AL contains the character to search


MOV CX, length ; Length of the string
CLD ; Clear Direction Flag
REP SCASB ; Scan for the byte in AL
JZ found ; Jump if found

3. Practical Application
Activity: Demonstrating Running Assembly Programs with String Operations

Objective: Students will write and execute assembly programs that utilize string operations.

Example Program: Copying a String

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

; Terminate the program


MOV AX, 60 ; Exit system call
XOR BX, BX ; Return code 0
INT 0x80 ; Call kernel

Running the Program

• Assemble the program using an assembler (e.g., NASM).


• Link the object file to create an executable.
• Run the executable to observe the result.

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:

• Why is it important to handle strings properly in assembly language?


• What challenges might arise when working with strings in low-level programming?

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

Week 6: Arithmetic Instructions

Assignment: Write an assembly language program that performs basic arithmetic operations (addition,
subtraction, multiplication, division) on user-provided inputs. Include input/output handling.

Week 7: Logical Instructions

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.

Week 8: Instruction Formats

Assignment: Create a table comparing different instruction formats (fixed vs. variable length) used in
assembly language. Provide examples of each format.

Week 9: Addressing Modes

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.

Week 10: String Operations

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.

Week 11: Input/Output Operations

Assignment: Create a program that demonstrates input/output operations in assembly language. Include
error handling for invalid input and document the program's flow.

Week 12: Branching Instructions

Assignment: Write an assembly program that uses conditional and unconditional branching. Create a
flowchart that illustrates the program's logic and branching decisions.

Week 13: Procedures and Macros

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.

Week 14: Advanced String Operations

Assignment: Develop a program that implements advanced string operations, such as concatenation and
reversing a string. Comment your code thoroughly.

Week 15: Review and Capstone Project

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)

Microprocessor Architecture: From Fundamentals to 64-bit Processing by Jean-Loup Baer (2021)

Research Papers

• Microprogramming: An Overview - Journal of Computer Science and Technology (Recent Issue,


2022).
• The Transition from Hardwired to Microprogrammed Control - IEEE Transactions on
Computers (2023).

Online Resources

• What are Addressing Modes? Types, Effective Address, Advantages and Disadvantages - Binary Terms

• https://binaryterms.com/addressing-modes-and-its-types.html

• Computer Organization | Hardwired v/s Micro-programmed Control Unit - GeeksforGeeks

• https://www.geeksforgeeks.org/computer-organization-hardwired-vs-micro-programmed-control-

unit/

John O A Otaru

Department of Computer Engineering Technology

College of Agriculture, Science & Technology, Lafia, Nasarawa State.

42

You might also like