MICROPROCESSOR
MICROPROCESSOR
4. What is an assembler?
1.Translation from Assembly Language to Machine Code 2. Symbolic Name Resolution 3. Macro
Expansion 4. Error checking 5. Object code generation 6. Handling directives.
9. Find the physical address when the respective content of CS and IP register are 34BA and
4214.
(1 Mark)
4. Distinguish between linker and loader.
Purpose:
The linker is responsible for combining code and preparing the executable file.
The loader ensures the executable file is loaded into memory and ready to execute.
Timing:
The linker works during the build process (before execution).
The loader works during the runtime process (just before execution). (1 ½ Marks)
Output:
The linker produces an executable file.
The loader ensures the program runs by placing it in memory. (1 ½ Marks)
Library Handling:
The linker integrates static libraries into the executable or prepares dynamic libraries for
runtime linking.
The loader dynamically links and loads libraries if needed during execution.
5. Explain the various interruption pins in the 8086 microprocessor and how they are
triggered.
The 8086 microprocessor has five primary interrupt-related pins:
NMI (Non-Maskable Interrupt), INTR (Interrupt Request), INTA (Interrupt Acknowledge),
RESET
HOLD. (2 Marks)
The interrupt system of the 8086 microprocessor allows it to handle external events efficiently
and react promptly to various system conditions. INTR and INT are used for general interrupts,
NMI is for critical, non-maskable interrupts, and RESET ensures that the processor can be
reinitialized. HOLD/HLDA facilitates DMA, enabling faster data transfer without processor
involvement. Together, these interrupt pins provide the microprocessor with flexibility in
managing hardware interactions, critical system errors, and real-time operations.
(1 Mark)
6. Discuss the maximum mode operation using read and write control signals in the 8086
microprocessors.
In the 8086 microprocessor, maximum mode is a specific mode of operation that allows the 8086
to work with external components like memory and I/O devices using additional support chips.
This mode is primarily used for multiprocessor systems or systems with external memory that
require complex control signals. In maximum mode, the 8086 microprocessor needs external
support for generating various control signals, which it cannot generate on its own in this mode.
(2 Marks)
Status Signals (S2, S1, S0), Control Signals Generated by the 8288 Bus Controller, Address
Latch Enable (ALE), Data Transfer Synchronization.
(1 Mark)
7. Dramatize read and write operations using memory and I/O devices.
8086 microprocessor handles the basic tasks of reading and writing data both to memory and I/O
devices. The process involves precise coordination using the address bus, data bus, and control
signals like ALE, RD, WR, M/IO, and DEN. (1 Mark)
Memory operations involve fetching or storing data in RAM, with address and data buses
actively involved.
I/O operations are similar, but the microprocessor interacts with external devices like
sensors, displays, or keyboards using specific I/O ports. (1 Mark)
The Memory Read Operation, the Memory Write Operation, the I/O Read Operation, the I/O
Write Operation. (1 Mark)
8. Interpret the function and importance of the status pins in the 8086 microprocessors.
Function of the Status Pins (S2, S1, and S0): (1 ½ Marks)
The S2, S1, and S0 pins form a 3-bit status code that provides the current state of the processor.
The status code is used primarily to indicate the type of bus cycle or operation being executed
by the 8086, which helps external devices (memory, I/O controllers) determine whether the
operation is related to memory, I/O, or another process.
(1 ½ Marks)
Importance of the Status Pins:
1. Communication with External Devices, 2. Coordination of Data Transfers, 3. Interrupt
Handling, 4. Debugging and Testing, 5.System Efficiency and Control.
9. Illustate the process of troubleshooting in 8086 microprocessors.
Troubleshooting the 8086 microprocessor involves a systematic approach to diagnosing and
resolving issues in its operation.
Define the Problem, Preliminary Checks, Test Hardware Components, Debug Software, Use
Diagnostic Tools, Analyze Timing, Test Communication, Isolate and Rectify the Fault.
(2 Marks)
Importance of Troubleshooting
1. Reliability: Ensures that the 8086 system functions as expected under various conditions.
2. Efficiency: Identifies and resolves bottlenecks or malfunctions that hinder performance.
3. Longevity: Prevents long-term hardware damage and extends the system’s lifespan.
4. Debugging Skills: Enhances understanding of the microprocessor's operation, aiding in
the development of robust systems.
(1 Mark)
10. Explain briefly about END, ENDP and ENDS.
The assembler directives END, ENDP, and ENDS are used to mark the end of certain sections
of code or procedures.
END (End of Program)
(1 Mark)
Purpose: The END directive marks the end of the entire assembly language program.
ENDP (End of Procedure)
(1 Mark)
Purpose: The ENDP directive marks the end of a procedure in the assembly code.
ENDS (End of Segment)
(1 Mark)
Purpose: The ENDS directive is used to mark the end of a segment in the assembly code.
Five marks Questions
1. Explain the role of microprocessors in electronic world. Discuss how the changes in
microprocessor technology influenced the development of computing over time.
A microprocessor is an integrated circuit (IC) that contains the central processing unit (CPU),
which is responsible for executing instructions and managing the flow of data within a system.
1. The Early Days (1970s - 1980s) (2
Marks)
Key Milestones:
First Microprocessors (1971): The Intel 4004, released in 1971, was the first
commercially available microprocessor. It was a 4-bit processor capable of executing
simple instructions.
Introduction of 8-bit Microprocessors (1972 - 1980): The Intel 8080 and the Zilog Z80
(1976) were popular 8-bit processors that spurred the development of personal computers
(PCs), allowing for the first commercial microcomputers.
Intel 8086 and 8088 (1978-1979): The 8086 was a 16-bit processor and one of the first
to adopt the x86 architecture, which remains the foundation for modern PC processors.
This chip introduced the concept of segmentation, which allowed computers to access
more memory than the simple 64KB limit of previous microprocessors.
2. The Rise of 16-bit and 32-bit (1980s - 1990s) (1
Mark)
Key Milestones:
Intel 80386 (1985): The 80386 was Intel's first 32-bit processor, which allowed for a
larger memory address space (4GB) and improved multitasking.
Increased Clock Speeds and Processing Power: The 80386 introduced significant
performance improvements over its predecessors, with the introduction of protected
mode and support for larger, more sophisticated operating systems such as Windows and
UNIX.
Motorola 68000: Competing with Intel, the Motorola 68000 (1984) used a 32-bit
architecture internally but had a 16-bit external data bus. This processor powered several
early Macintosh computers.
(2 Marks)
Key Components and Organization of the 8086 Microprocessor Architecture
1. ALU (Arithmetic Logic Unit):
The ALU is responsible for performing all arithmetic and logical operations, including
addition, subtraction, logical AND, OR, NOT, and comparison operations. It receives
data from the registers and performs the operation, sending the result back to the
appropriate register or memory location.
2. Registers:
The 8086 microprocessor contains a range of registers that serve different purposes, including
holding data, addresses, and control information. These are grouped into various categories:
General Purpose Registers:
o AX (Accumulator Register): Used for arithmetic, logic, and I/O operations.
o BX (Base Register): Primarily used for addressing data.
o CX (Count Register): Used for loop operations (e.g., with LOOP instruction).
o DX (Data Register): Used in I/O operations, and as an extension of AX for
multiplication and division.
Segment Registers:
o CS (Code Segment): Points to the code segment (memory area where the
program is loaded).
o DS (Data Segment): Points to the data segment (where data is stored).
o SS (Stack Segment): Points to the stack segment (used for function calls and
returns).
o ES (Extra Segment): Used in string and memory operations.
Pointer and Index Registers:
o SP (Stack Pointer): Points to the top of the stack in the stack segment.
o BP (Base Pointer): Used in referencing data on the stack.
o SI (Source Index): Used for string operations.
o DI (Destination Index): Used for string operations.
Flag Register:
o The Flag Register (also known as Status Register) contains individual flags that
are set or cleared based on the result of the most recent operation. The key flags
include:
Carry Flag (CF): Indicates an overflow or underflow in arithmetic
operations.
Zero Flag (ZF): Indicates if the result of the operation is zero.
Sign Flag (SF): Indicates if the result is negative.
Overflow Flag (OF): Indicates if there was an overflow in a signed
operation.
Direction Flag (DF): Controls string operations.
Parity Flag (PF): Indicates if the number of set bits in the result is even
or odd.
Auxiliary Carry Flag (AF): Used in BCD arithmetic operations.
3. Bus Interface Unit (BIU):
The BIU handles communication between the microprocessor and memory or I/O devices. It is
responsible for managing the address bus, data bus, and control signals.
Instruction Queue: The 8086 has a 6-byte instruction queue that fetches instructions in
advance from memory. This allows for pipelining, where the next instruction can be
fetched while the current instruction is being decoded and executed, improving
processing speed.
Address Bus: The 8086 has a 20-bit address bus that can address up to 1MB of
memory.
Data Bus: The 16-bit data bus allows data to be transferred in 16-bit chunks.
Control Signals: The BIU generates control signals for reading from and writing to
memory or I/O ports, as well as controlling other parts of the system, such as interrupt
handling.
4. Execution Unit (EU):
The EU is responsible for decoding and executing instructions. It operates closely with the
ALU to perform operations.
Instruction Decoder: Decodes the binary instruction fetched by the BIU.
Control Unit: Coordinates the execution of instructions, managing how and when
different components of the microprocessor are activated. It handles instruction fetches,
decodes, and control signals for execution.
ALU: Executes the arithmetic and logical operations.
5. Memory Organization:
The 8086 utilizes a segmented memory model, which divides the memory into smaller
segments, allowing more efficient use of available memory.
Code Segment (CS): Contains the executable instructions of the program.
Data Segment (DS): Stores variables, constants, and other data used by the program.
Stack Segment (SS): Stores data related to the stack, such as function return addresses,
local variables, and intermediate data.
Extra Segment (ES): An additional segment used for memory manipulation and string
operations.
The segment registers (CS, DS, SS, ES) provide a 16-bit offset into these segments, and the 20-
bit address bus allows accessing 1MB of memory by combining the 16-bit segment base
address with the 16-bit offset.
(3 Marks)
3. Discuss the different levels of programming languages utilized in microprocessor systems.
8086 microprocessor programming is typically done at different levels, ranging from low-level
machine language to high-level languages. These different levels of programming languages
offer varying degrees of abstraction from the hardware, providing a balance between efficiency
and ease of use. Below is a discussion of the different levels of programming languages
utilized in microprocessor systems, specifically focusing on the 8086 microprocessor:
1. Machine Language (Low-Level) (1 ½
Mark)
Description:
Machine language is the most basic level of programming, where instructions are
written in binary or hexadecimal code. These instructions are directly executed by the
microprocessor without any translation or interpretation. Each instruction corresponds
to a specific operation on the hardware, such as adding two numbers, storing data in a
register, or jumping to a different part of memory.
Characteristics:
Binary/Hexadecimal Format: Instructions are written as binary or hexadecimal codes
(e.g., 10110000, 0xB0).
Processor-Specific: Machine language is tailored to the architecture of the specific
microprocessor. In the case of the 8086, machine instructions correspond directly to its
opcode set (operations like MOV, ADD, etc.).
No Abstraction: There is no abstraction, meaning the programmer must be familiar with
the hardware and instruction set.
2. Assembly Language (Low-Level) (2 Mark)
Description:
Assembly language is a step above machine language, where mnemonics (human-
readable instructions) are used to represent machine instructions. Each mnemonic
corresponds to a machine language opcode. Assembly language is specific to the
microprocessor architecture, and for the 8086, it follows the 8086 instruction set.
In assembly language, programmers can use symbols and labels for memory addresses,
registers, and constants, making the code easier to read and write compared to raw
binary.
Characteristics:
Mnemonics: Instructions are written using mnemonics like MOV, ADD, SUB, CMP,
etc., which represent specific machine operations.
Assembler: An assembler program is used to translate assembly language into machine
code (binary).
Direct Access: Assembly provides direct control over system hardware (registers,
memory, etc.).
Architecture-Specific: Assembly language is processor-specific. The 8086's assembly
language uses the x86 instruction set.
3. High-Level Languages (HLLs) (1 ½
Marks)
Description:
High-level languages provide a greater level of abstraction from the hardware. These languages
are more similar to human language and are designed to be easier to read and write. High-level
languages abstract away the details of hardware management and allow the programmer to
focus on logic and problem-solving. In the context of the 8086 microprocessor, several high-
level languages could be used, including C, Pascal, and FORTRAN.
High-level languages require a compiler or interpreter to translate the program into machine
code. The resulting machine code is then executed by the 8086 microprocessor.
Characteristics:
Abstraction: These languages abstract hardware details, allowing programmers to write
code without worrying about the underlying hardware.
Portability: Programs written in high-level languages can often be compiled to run on
different hardware architectures with minimal changes.
Ease of Use: These languages are easier to read, write, and maintain compared to
assembly or machine language.
4. Generalize the key tools used in microprocessor programming, and how do they help in
debugging and simulation.
Below are the key tools used in 8086 microprocessor programming, along with their role in
debugging and simulation: (Each tool
carries 1 mark=5 marks)
1. Assembler: An assembler is a tool that translates assembly language code into machine code
(binary code) that can be executed by the 8086 microprocessor. The assembler reads the source
code written in mnemonics (human-readable instructions) and converts them into
corresponding machine instructions.
Error Checking: During the assembly process, the assembler detects syntax errors,
undefined labels, or incorrect instructions, making it easier for the programmer to fix
issues before execution.
Code Optimization: Some assemblers offer optimization features that help in improving
the efficiency of the generated machine code.
Symbol Table Generation: The assembler generates a symbol table that helps track the
usage of labels and variables in the code, which can be used for debugging.
2. Debugger: A debugger is a program used to identify and fix errors (bugs) in the source code.
It allows you to step through the code, examine the contents of registers, memory, and flags,
and track the flow of execution. Debuggers are crucial in 8086 assembly language
programming as they help pinpoint logic errors and unexpected behaviour.
Step-by-Step Execution: Debuggers allow the user to step through the program one
instruction at a time, helping to identify the exact point where the program deviates
from the expected behaviour.
Breakpoints: Programmers can set breakpoints to pause the program at specific
instructions or memory addresses, allowing for in-depth examination of the program’s
state at that point.
Register and Memory Inspection: Debuggers enable users to view the contents of
various 8086 registers (like AX, BX, CX, DX) and memory locations during execution.
This allows the programmer to verify if the program is manipulating data correctly.
Flag Monitoring: They also help in monitoring the status flags (like Carry Flag, Zero
Flag, Overflow Flag) to verify the outcomes of arithmetic operations.
3. Simulator: A simulator is a tool that emulates the 8086 microprocessor's behavior on a host
machine, allowing developers to simulate how their program will execute on actual hardware
without needing the physical microprocessor.
Emulation of Hardware: The simulator mimics the 8086’s CPU, memory, and other
hardware features, enabling programmers to test programs in a virtual environment.
Instruction-level Simulation: It simulates the execution of each instruction and the
manipulation of registers and flags, helping the programmer understand the precise
behavior of the program.
Memory and I/O Simulation: Simulators allow the programmer to simulate the reading
and writing of data from/to memory and I/O ports, even when actual hardware is not
available.
Error Detection: Simulators can identify potential issues, such as invalid memory
accesses or improper instruction sequences, and provide feedback for fixing these
issues.
4. Integrated Development Environment (IDE): An IDE is a software application that provides
comprehensive facilities for software development. It typically includes a code editor,
compiler/assembler, debugger, and other tools in one unified interface. Some IDEs are
specifically designed for assembly language programming and microprocessor simulation.
Code Editing: IDEs provide syntax highlighting, code completion, and error warnings,
which help developers write error-free code.
Built-in Debugger: Most modern IDEs come with an integrated debugger that allows
step-by-step execution and real-time inspection of registers, flags, and memory.
Simulation and Testing: Some IDEs offer built-in simulators that emulate the behavior
of the 8086 processor, allowing the programmer to test the code without the need for
actual hardware.
Error Detection: The IDE typically highlights syntax and logical errors, and some
advanced IDEs offer real-time debugging assistance by pointing to problematic sections
of code.
5. Emulator: An emulator is similar to a simulator but typically refers to a tool that mimics the
entire hardware environment (including the microprocessor, memory, I/O devices, etc.) of a
system. Emulators are used to replicate the behaviour of the 8086-microprocessor system for
development and testing.
Hardware Emulation: Emulators replicate the 8086 microprocessor’s actual hardware,
allowing programmers to run their programs as if they were running on real hardware.
Execution Trace: Emulators often provide a detailed trace of the program's execution,
which helps in diagnosing and debugging issues such as incorrect program flow or
memory management errors.
Peripheral Emulation: Some emulators simulate the connected I/O devices, helping test
programs that rely on external hardware interaction.
6. Disassembler: A disassembler is a tool that converts machine code (binary) back into
assembly language, allowing the programmer to analyse a compiled program. It is useful when
you have a compiled binary program (such as from a non-8086 source) and want to inspect the
assembly code it corresponds to.
Reverse Engineering: Disassemblers help in reverse engineering binary code to
understand how the machine code operates.
Code Analysis: They help in inspecting the low-level machine instructions for
debugging purposes, allowing programmers to trace how a specific operation is
executed at the machine level.
Memory Inspection: A disassembler can assist in inspecting memory by providing the
assembly equivalent of a machine code dump.
5. Demonstrate how 8086 microprocessor manages multiple interrupt requests during its
operation.
In the 8086 microprocessor, interrupt handling plays a crucial role in managing multiple
interrupt requests that occur during its operation. The 8086 uses a combination of hardware and
software mechanisms to prioritize and manage interrupt requests, ensuring that the most critical
tasks are handled first.
Key Concepts of Interrupt Handling in 8086: (2
Marks)
1. Interrupt Types:
o Hardware Interrupts: These are external signals that request the attention of the
microprocessor. These signals come from external devices such as keyboards,
timers, or external I/O devices.
o Software Interrupts: These are interrupts generated by instructions within the
program (e.g., INT instruction). These interrupts are typically used for system
calls or exception handling.
2. Interrupt Priority: The 8086 microprocessor does not have a built-in priority mechanism
for interrupt requests. However, external hardware (typically in the form of an interrupt
controller) handles the priority of the interrupt requests. The 8086 uses a priority-based
scheme where certain interrupt signals are given precedence over others.
3. Interrupt Vector Table (IVT):
o The interrupt vector table stores the addresses of interrupt service routines (ISR)
for each interrupt. The 8086 supports up to 256 interrupt types (0–255).
o The first 32 interrupts (0–31) are reserved for hardware interrupts, exceptions,
and processor-specific functions. These interrupts are mapped to specific
locations in the interrupt vector table.
o Interrupt vector 0 points to address 0000h, interrupt vector 1 points to 0004h,
and so on. Each vector consists of a 4-byte pointer that specifies the segment
and offset of the ISR.
How the 8086 Prioritizes and Manages Multiple Interrupts: (1
Mark)
1. Interrupt Request (IRQ):
2. Priority
3. Interrupt Acknowledge:
4. Interrupt Handling Process:
Handling Multiple Interrupt Requests: (2 Marks)
If multiple interrupts are triggered at the same time, the priority system plays a critical role in
determining which interrupt is handled first.
1. Masking of Interrupts:
o The 8086 can mask interrupts using the INTR pin. If the INTR pin is not active
(logic low), the 8086 will ignore any interrupt requests.
o The Interrupt Flag (IF) in the FLAGS register determines whether the 8086 will
accept maskable interrupts. When IF = 0, interrupts are disabled, and when IF =
1, interrupts are enabled.
2. Nested Interrupts:
o The 8086 allows for nested interrupts, meaning that if a higher-priority interrupt
occurs while an ISR is running, the microprocessor will suspend the current
ISR, save its state, and jump to the ISR of the higher-priority interrupt.
o Once the higher-priority interrupt is serviced, the processor will return to the
original ISR.
For example, if an interrupt of higher priority (IRQ0) occurs while the microprocessor is
servicing an interrupt of lower priority (IRQ2), the microprocessor suspends the service of
IRQ2 and starts servicing IRQ0. After IRQ0 is handled, the 8086 will return to handle IRQ2.
3. Vectoring and Acknowledgment:
o Each interrupt request has a vector that determines the address of the ISR. For
example, the interrupt vector for IRQ0 (timer interrupt) is 0000h and for IRQ1
(keyboard interrupt) is 0004h.
o The 8086 uses the interrupt vector to jump to the correct location in the Interrupt
Vector Table (IVT). This mechanism allows the system to handle multiple
interrupt requests by directing them to the appropriate ISRs.
6. Summarize the control signals in the 8086 microprocessor’s minimum mode operation to
facilitate communication with external components.
In minimum mode operation of the 8086 microprocessor, the microprocessor operates
independently without the need for additional control chips (such as the 8288 Bus Controller).
The control signals are used to facilitate communication between the 8086 microprocessor and
external components like memory, input/output devices, and other peripherals.
Key Control Signals in 8086 Minimum Mode (Each pin carries ½ mark=5
marks)
In minimum mode, the control signals are directly generated by the 8086. These signals govern
the flow of data, address, and control between the processor and external components. Here is a
summary of the important control signals:
1. M/IO (Memory/Input-Output)
Purpose: This signal distinguishes between memory and I/O operations.
Logic Level:
o Low (0): Memory operation (the address is directed to memory).
o High (1): I/O operation (the address is directed to an I/O device).
Usage: Helps determine whether the current address bus cycle is for memory or I/O
communication.
2. IO/MEM (Memory or I/O Operation)
Purpose: Similar to M/IO, this signal indicates the type of operation (whether accessing
memory or I/O).
Logic Level:
o Low (0): Memory operation.
o High (1): I/O operation.
3. S1 and S0 (Status Signals)
Purpose: These are used to indicate the status of the 8086 during the bus cycle.
Logic Levels: The combination of S1 and S0 determines the type of bus cycle (whether
it's a memory read, memory write, I/O read, I/O write, etc.).
o For example:
S1 = 0, S0 = 0: Microprocessor is in Instruction Fetch mode.
S1 = 0, S0 = 1: Memory Read.
S1 = 1, S0 = 0: Memory Write.
S1 = 1, S0 = 1: I/O Read/Write.
4. RD (Read)
Purpose: This signal indicates that the processor is performing a read operation.
Logic Level:
o Low (0): Read operation.
o High (1): Not a read operation.
Usage: When RD is low, the 8086 reads data from memory or I/O. The ALE (Address
Latch Enable) signal is typically used to latch the address for memory reads.
5. WR (Write)
Purpose: This signal indicates that the processor is performing a write operation.
Logic Level:
o Low (0): Write operation.
o High (1): Not a write operation.
Usage: When WR is low, the 8086 writes data to memory or an I/O device.
6. ALE (Address Latch Enable)
Purpose: This signal is used to latch the address on the address bus into a latch or
buffer.
Logic Level:
o High (1): When the signal is high, the address bus contains valid address data.
o Low (0): The signal is low during the data phase when the data bus is being
used.
7. INTA (Interrupt Acknowledge)
Purpose: This signal is generated by the 8086 in response to an interrupt request.
Logic Level:
o Low (0): Indicates that the processor is acknowledging the interrupt request and
ready to fetch the interrupt vector.
Usage: It is sent when the 8086 acknowledges an interrupt, signaling that it will process
the interrupt.
8. HOLD (Bus Hold)
Purpose: This signal indicates that an external device is requesting control of the system
bus.
Logic Level:
o Low (0): No external device is holding the bus.
o High (1): An external device is requesting control of the bus.
Usage: Used when other devices (like DMA controllers) need access to the system bus
to transfer data.
9. HLDA (Hold Acknowledge)
Purpose: This signal is sent by the 8086 in response to a HOLD request from an
external device.
Logic Level:
o High (1): Indicates that the 8086 has released control of the bus to the external
device.
Usage: When the 8086 releases the bus, it sends HLDA to acknowledge the bus
handover.
10. LOCK (Bus Lock)
Purpose: This signal is used to prevent other devices from accessing the system bus
while the 8086 is executing critical sections of code (e.g., for atomic operations).
Logic Level:
o Low (0): No lock; external devices can access the bus.
o High (1): Bus locked, external devices cannot access the bus.
11. RESET (System Reset)
Purpose: This signal is used to reset the processor and initialize its internal registers and
flags.
Logic Level:
o Low (0): Processor reset is active.
o High (1): Normal operation.
Usage: When active, the 8086 starts executing from memory location 0xFFFF0 (the
reset vector).
7. Illustrate 8086-based microcomputer with the help of block diagram.
The 8086-based microcomputer consists of various components working together to execute
instructions and interact with external devices. Below is a diagrammatic representation of a
typical 8086-based microcomputer, illustrating its essential components.
(2 Marks)
Description of the Components:
1. 8086 Microprocessor:
o The central processing unit (CPU) of the system. It executes instructions,
handles arithmetic and logic operations, manages memory and I/O interactions,
and controls the overall operation of the system.
o The 8086 is a 16-bit microprocessor, which means it has a 16-bit wide data bus
and can handle 16-bit data in one operation.
2. Memory (RAM):
o The RAM (Random Access Memory) stores data and programs that are being
executed. It is connected to the address and data buses of the 8086
microprocessor.
o The 8086 uses a segmented memory model, where it accesses 1MB of memory
using segment registers.
3. I/O Devices:
o These include peripheral devices like a keyboard, monitor, printer, disk drives,
etc.
o The 8086 communicates with these devices via I/O ports.
4. Interrupt Controller (8259 PIC):
o The 8259 Programmable Interrupt Controller is responsible for managing
interrupts in the system.
o The 8086 does not have a built-in interrupt controller, so the 8259 PIC helps
handle multiple interrupt requests, prioritizing them and directing the 8086 to
the appropriate Interrupt Service Routine (ISR).
5. Control Bus:
o This bus carries control signals from the 8086 to manage the operation of
memory, I/O devices, and peripherals. These signals include read, write, and
interrupt signals.
6. Address Bus:
o The address bus is responsible for carrying the address from the 8086 to
memory and I/O devices to fetch or store data.
o The 8086 has a 20-bit address bus, allowing access to 1MB of memory.
7. Data Bus:
o The data bus is used for transferring data between the 8086 microprocessor,
memory, and I/O devices.
o The 8086 has a 16-bit data bus, meaning it can transfer 16 bits of data at a time.
Functionality of Each Component:
The 8086 microprocessor fetches instructions from RAM or I/O devices through the
address and data buses.
It executes the instructions and uses the control bus to manage the communication with
memory and I/O devices.
The 8259 PIC manages interrupts and ensures that the microprocessor handles them in
priority order, sending an Interrupt Acknowledge signal to the processor when an
interrupt is serviced.
This basic architecture allows the 8086 microprocessor to interact with external memory,
peripherals, and handle interrupts, enabling it to perform complex operations and execute user
programs in real-time.
(3 Marks )
8. Explain about the 8086 microprocessor's pin diagram. (Pin diagram – 1 mark, pin
details – 4 marks)
Explanation of Key Pins in the 8086 Microprocessor Pin Diagram:
1. AD0-AD15 (Address/Data Bus):
o These are multiplexed pins for address and data transfer. The 8086 uses these pins
to carry both address and data during different phases of its bus cycle. Initially,
these pins carry address information, and later, they carry data during read/write
operations.
2. A0-A19 (Address Bus):
o These pins provide the 20-bit address for accessing up to 1MB of memory. The
8086 microprocessor can address 1MB of memory, and these address lines send
the corresponding memory address to the RAM or I/O devices.
3. M/IO (Memory/Input-Output):
o This pin tells whether the microprocessor is performing a memory operation or
an I/O operation.
o Low (0): Memory operation
o High (1): I/O operation
4. RD (Read) and WR (Write):
o These pins control read and write operations. When RD is low, it indicates a read
operation, and when WR is low, it indicates a write operation.
5. RESET:
o The RESET pin initializes the microprocessor, clearing all registers and restarting
the program from the reset vector (typically 0xFFFF0).
6. HOLD and HLDA (Hold and Hold Acknowledge):
o HOLD: A request from an external device to take control of the system bus (e.g.,
for DMA operations).
o HLDA: The microprocessor responds to a HOLD request by acknowledging the
bus release.
7. CLK (Clock):
o The clock pin provides the timing signal for the microprocessor, synchronizing
all operations inside the 8086.
8. INTA (Interrupt Acknowledge):
o This pin signals that the 8086 is acknowledging an interrupt request. It is used to
retrieve the interrupt vector.
9. LOCK:
o The LOCK pin prevents other devices from accessing the system bus while the
microprocessor is executing critical instructions that require exclusive access to
the bus.
10. BUSY:
o The BUSY pin indicates if the microprocessor is in use and can accept or initiate
operations. It is used to indicate bus contention.
11. READY:
o The READY pin informs the microprocessor if the external device is ready for
data transfer or if it needs to wait for the device to become ready.
12. NMI (Non-Maskable Interrupt):
o The NMI pin is used to handle high-priority interrupts that cannot be masked by
the interrupt flags.
9. Classify the common problems encountered in the 8086 microprocessor and the steps taken
to troubleshoot them. (Each step 1 mark= 5 marks)
The 8086 microprocessor is a powerful processor, but like any complex electronic device, it can
experience various issues. Below are some common problems encountered in 8086 systems and
the troubleshooting steps to resolve them.
1. System Not Starting / No Power On
Problem: The microprocessor is not powering up, or the system does not begin the boot process.
Possible Causes: Power supply failure, Incorrect power connection to the microprocessor
(VCC/GND), Damaged microprocessor or faulty components like the crystal oscillator.
Troubleshooting Steps: Check Power Supply, Inspect Connections, Check Oscillator Circuit,
Test Microprocessor, Verify Power Rails.
2. Incorrect or No Output on Display
Problem: The system is running, but there is no output on the monitor or incorrect data displayed.
Possible Causes: Issues with the data bus or address bus, Faulty memory (RAM), Problems with
the I/O ports or display circuitry, Misconfigured I/O devices.
Troubleshooting Steps: Check Address/Data Bus, Check Memory, Test Display Interface, Check
I/O Port Connections
3. Intermittent System Crashes or Freezes
Problem: The microprocessor system runs fine for a while, but then it crashes or freezes
intermittently.
Possible Causes: Faulty interrupt handling, Memory issues (e.g., RAM corruption or improper
memory addressing), Bus contention or timing issues, Issues with control signals like RD or WR.
Troubleshooting Steps: Check Interrupts, Examine Timing Signals, Memory Diagnostics, Check
Bus Signals, Check Control Signals.
4. System Running But Incorrect Data Processing (Logical Errors)
Problem: The system runs, but the computations or logic operations produce incorrect results.
Possible Causes: Incorrect programming or corrupted software, Faulty registers or improper
memory access, Issues with the ALU (Arithmetic Logic Unit) or instruction decoding.
Troubleshooting Steps: Check Program Code, Examine Register States, Verify ALU Operations,
Verify Memory Access
5. Interrupts Not Being Serviced Properly
Problem: The system has interrupt handling, but interrupts are not serviced correctly or are
ignored.
Possible Causes: Issues with the interrupt controller (e.g., 8259 PIC), Incorrect interrupt vector
table or handler, Interrupt priority problems.
Troubleshooting Steps: Check Interrupt Controller, Verify Interrupt Vector Table, Check
Interrupt Flags, Test Interrupt Priority.
6. Bus Contention or Conflicts
Problem: The microprocessor is trying to access the bus while another device is also attempting
to use it, leading to bus contention.
Possible Causes: DMA (Direct Memory Access) devices trying to use the bus, Conflicts between
the microprocessor and peripheral devices (e.g., video card, I/O devices).
Troubleshooting Steps:
Monitor Bus Signals, Check DMA Control Lines, Isolate Peripherals, Check Bus
Arbitration.
10. Discuss how the assembler directives influence the way an assembly language program is
processed by the assembler.
Assembler directives are commands in assembly language programs that instruct the assembler
on how to process the source code. They are not translated into machine code but influence the
assembly process, such as the allocation of memory, setting data types, and controlling program
execution. In the context of the 8086 microprocessors, these directives provide essential
guidance on how the assembler handles and structures the assembly code. Here's a breakdown
of how they influence the assembly process:
1. Memory Allocation and Initialization (1 Mark)
Assembler directives play a key role in allocating memory and initializing values. They help
define sections of the program (such as data and code sections) and specify how data is stored.
Example: .data, .bss, .code
.data: This directive is used to declare initialized data (e.g., variables with predefined
values). It tells the assembler that the data following this directive is initialized and ready
for use.
.bss: Used for uninitialized data. This section reserves space in memory but does not
initialize it. The assembler will allocate memory space for variables declared with this
directive but will not assign them a value.
.code: Marks the beginning of the code segment, where the actual instructions reside.
2. Control over Program Execution (1 Mark)
Some directives influence the flow of execution, enabling the programmer to specify where the
program starts or when the execution halts.
Example: .org, .end
.org: This directive is used to set the starting address of the program or a particular
section. It allows control over where specific parts of the program will reside in memory.
.end: Marks the end of the source code. This tells the assembler that there is no more
source code to process.
3. Data Type Definitions and Allocation (1 Mark)
Assembler directives enable the programmer to define the size and type of data elements. This
influences how the data is processed and stored in memory.
Example: .byte, .word, .dword
.byte: This directive defines a byte (8 bits) of data, allowing the programmer to specify
values for individual bytes.
.word: This directive is used to define word-sized data (16 bits). It is particularly useful
for allocating variables that are intended to hold values larger than a byte.
.dword: This is used to define double word data (32 bits) and is more common in modern
systems. In the 8086, it is not as commonly used because the 8086 is a 16-bit
microprocessor.
4. Macro Definitions ( ½ Mark)
Assembler directives like macros help in defining reusable code blocks that can be inserted into
the program at various points. They influence the assembly process by substituting code snippets
wherever macros are invoked.
Example: MACRO, ENDM
MACRO: This directive is used to define a macro that can be used multiple times within
the program. It enables reusability and reduces the need to write repetitive code.
ENDM: Marks the end of the macro definition.
5. Conditional Assembly ( ½ Mark)
Assembler directives also allow for conditional assembly, enabling the program to include
or exclude portions of code based on certain conditions. This is helpful for creating code that
can adapt to different environments or configurations.
Example: IF, ENDIF
IF / ENDIF: This directive enables conditional assembly, allowing the assembler to
include or exclude blocks of code based on the evaluation of a condition.
6. Equate Directives ( ½ Mark)
Equate directives allow programmers to assign names to specific constants or memory
locations. This improves code readability and maintenance by using meaningful names
instead of magic numbers or raw addresses.
Example: EQU
EQU: Used to define constants or equate values to symbolic names.
7. Aligning Data ( ½ Mark)
In some cases, data must be aligned on boundaries (such as word or double-word boundaries)
for optimal performance or correct functioning. Assembler directives allow for this alignment.
Example: .align
.align: Ensures that data is aligned to a specified boundary, typically 2-byte (word) or 4-byte
(double-word) alignment.
UNIT - 2 ANSWER KEY
The MOV instruction in 8086 is one of the most commonly used instructions in assembly
language. It is primarily used to transfer data from one location to another. The MOV
instruction can copy data between various operands, such as registers, memory, and
immediate values.
Syntax:
Destination: This is where the data will be moved to (it can be a register or a memory
location).
Source: This is the data that will be moved to the destination. It can be a register, a
memory location, or an immediate value (constant).
Examples:
"MOV AX, BX": Copies the contents of register BX to register AX.
"MOV [BX], 10H": Stores the immediate value 10H into the memory location
addressed by the contents of register BX.
2. Illustrate the purpose of PUSH and POP instructions in 8086 with relevant syntax
and example.
Explanation:1 Mark
Syntax and Example: 2 Marks
Answer: The PUSH and POP instructions are used in assembly language programming to
manage data on the stack. The stack is a special region of memory used to store temporary
data, such as local variables, return addresses, and saved register values, especially when
calling procedures or handling interrupts.
1. PUSH Instruction:
The PUSH instruction is used to push data onto the stack. It involves two main actions:
Decrement the stack pointer (SP): The Stack Pointer (SP) register points to the top
of the stack. When a PUSH operation is performed, the SP is first decremented
(because the stack grows downward in memory).
Store the value: The value from the specified operand is then stored at the memory
location pointed to by the updated SP.
Syntax:
PUSH operand
Operand: The data that will be pushed onto the stack. This can be a register or a
memory location.
The SP register is first decremented by 2 (since 8086 is a 16-bit processor and uses
16-bit data).
Then, the operand (either a register or a memory value) is copied to the new memory
location pointed to by SP.
Example:
PUSH AX ; Push the value of AX onto the stack
In this example:
2. POP Instruction:
The POP instruction is used to pop data from the stack. It performs two actions:
Load the value from the stack: The value from the memory location pointed to by
the SP register is copied to the operand (usually a register).
Increment the stack pointer (SP): After the value is transferred, the SP is
incremented by 2, effectively removing the data from the stack.
Syntax:
POP operand
Operand: The location (usually a register) where the data will be transferred from the
stack.
How POP Works:
The SP register points to the top of the stack. The value at that memory location is
copied into the specified operand.
After the value is popped off the stack, the SP is incremented by 2.
Example:
In this example:
The value from the memory location pointed to by SP is moved into register BX.
Afterward, the SP is incremented by 2, effectively removing the value from the stack.
The IDIV instruction in the 8086 microprocessor is used for signed integer division. It
divides a signed 16-bit number by another signed 8-bit or 16-bit number, depending on the
operands. The result of the division is placed in the AX register (for 8-bit divisor) or in
DX:AX (for 16-bit divisor), and the flags are updated based on the result.
Syntax:
IDIV divisor
Example: IDIV BL (Divides AX by BL and stores the quotient in AL and remainder in AH).
Examples:
1. 8-bit Signed Division:
MOV AX, 1234h ; Dividend (AX = 1234h)
MOV BL, 10 ; Divisor (BL = 10)
IDIV BL ; Signed division: AX divided by BL
The CALL instruction in 8086 is used to call a procedure or function. When executed, it
does two things:
1. Pushes the address of the next instruction (the instruction following the CALL)
onto the stack.
2. Transfers control to the procedure or function specified by the operand (address).
The CALL instruction is essential for subroutine invocation and procedure calls, enabling
the execution of reusable blocks of code.
Syntax:
CALL destination
The RET instruction stands for return. This instruction is used at the end of the procedures
or the subprograms. This instruction transfers the execution to the caller program. Whenever
the RET instruction is called, the following process takes place inside the microprocessor:
The address of the next instruction in the mainline program which was previously
stored inside the stack is now again fetched and is placed inside the instruction pointer
(IP).
The instruction queue will now again be filled with the subsequent instructions of the
mainline program.
RET
The following diagram illustrates how the control of the instruction execution is transferred
within the code from one program to another whenever a procedure is called and whenever it
returns the execution. In most of the cases, the procedure CALL is made from the mainline
program and hence the control is returned to the mainline program itself.
8. Compare JMP and CALL instructions used in 8086.
Defn: 1 mark
Comparison table (Any 4): 2 marks
Answer:
JMP: An unconditional jump to a specified label or memory address.
CALL: Calls a procedure, saves the return address on the stack, and jumps to the
procedure.
Exam
9.Demonstrate how a WHILE loop can be implemented in assembly language with an
example.
Def: 1 mark
Example: 2 marks
Example:
In this example, the loop continues to run while the value in AX is less than 10.
10. Illustrate the ADD and SUB instructions with relevant examples.
Defn & Example for each: 1.5 marks
ADD Instruction in 8086
The ADD instruction is used to add the contents of two operands and store the result in the
destination operand. The operands can be registers, memory locations, or immediate values.
Syntax:
ADD destination, source
destination: This is the operand that will receive the result of the addition.
source: This is the operand that will be added to the destination operand.
In this example:
After execution, AL = 8.
The SUB instruction is used to subtract the contents of one operand from another and store
the result in the destination operand.
Syntax:
SUB destination, source
destination: This is the operand that will receive the result of the subtraction.
source: This is the operand that will be subtracted from the destination operand.
In this example:
After execution, AL = 6.
2 Direct:
•In the direct addressing mode, a 16-bit memory address (offset) is directly specified
in
the instruction as a part of it.
Eg: MOV AX,[5000H], –Effective address= 10H*DS +5000H
3 Register:
•In the register addressing mode, the data is stored in a register and it is referred using
the particular register
•All the registers, except IP, may be used in this mode.
•Eg: MOV AX, BX
4 Register Indirect:
•Sometimes, the address of the memory location which contains data or operand is
determined in an indirect way, using the offset registers.
•This mode of addressing is known as register indirect mode
•In this addressing mode, the offset address of data is in either BX or SI or DI register.
•The default segment is either DS or ES. The data is supposed to be available at the
address pointed to by the content of any of the above registers in the default data
segment.
Eg: MOV AX,[BX] –Effective address is 10H*DS+[BX]
5 Indexed:
•In this addressing mode, offset of the operand is stored in one of the Index registers.
DS is the default segment for index registers SI and DI
•In the case of string instructions DS and ES are default segments for SI and DI
respectively.
•This mode is a special case of the above discussed register indirect addressing mode
Eg: MOV AX,[SI] –effective address is 10H*DS+[SI]
6 Register Relative:
•In this addressing mode, the data is available at an effective address formed by
adding an 8-bit or 16-bit displacement with the content of any one of the registers BX,
BP, SI and DI in the default (either DS or ES) segment.
Eg: MOV AX,50H[BX] –Effective address is 10H*DS+50H+[BX]
7 Based Indexed:
•The effective address of the data is formed, in this addressing mode, by adding the
content of a base register (any one of BX or BP) to the content of an index register
(anyone of SI or DI)
•For the control transfer instructions, the addressing modes depend upon whether the
destination location is within the same segment or in a different one.
•It also depends upon the method of passing the destination address to the processor.
•Basically there are two addressing modes for the control transfer instructions, viz,
intersegment and intra segment addressing modes.
•If the location to which the control is to be transferred lies in a different segment
other than the current one, the mode is called intersegment mode.
•If the destination location lies in the same segment, the mode is called intra segment
Mode
In the 8086 microprocessor, data transfer instructions are used to transfer data between
registers, memory locations, and I/O ports. These instructions do not involve any arithmetic
or logical operations; instead, they move data from one place to another.
The primary data transfer instructions in 8086 include MOV, PUSH, POP, XCHG, IN, and
OUT.
1. MOV (Move) Instruction
The MOV instruction is used to transfer data between registers, memory, and I/O ports. It
moves data from the source operand to the destination operand. The source and destination
operands can be:
Immediate values
Registers
Memory locations
Syntax:
MOV destination, source
Examples:
MOV AX, BX ; Move the content of BX into AX
MOV AL, 0xFF ; Move immediate value 0xFF into AL
MOV [5000h], AX ; Move the content of AX into memory location 5000h
2. PUSH Instruction
The PUSH instruction is used to push a value onto the stack. It decrements the stack
pointer (SP) and then stores the value at the memory location pointed to by SP.
Syntax:
PUSH source
Example:
PUSH AX ; Push the value of AX onto the stack
This stores the value of the AX register at the memory address pointed to by SP and
decrements SP by 2 (since it's a 16-bit register).
3. POP Instruction
The POP instruction is used to pop a value from the stack into a register or memory location.
It first loads the value from the memory location pointed to by SP and then increments SP.
Syntax:
POP destination
This instruction loads the value at the memory address pointed to by SP into the AX
register and increments SP by 2.
4. XCHG Instruction
The XCHG (Exchange) instruction is used to exchange the values of two operands. The
operands can be registers or memory locations.
Syntax:
XCHG operand1, operand2
Example:
XCHG AX, BX ; Exchange the values of AX and BX
5. IN Instruction
The IN instruction is used for input operations from an I/O port into a register. The value is
read from the I/O port specified by the port address.
Syntax:
IN destination, port
Example:
IN AL, 0x60 ; Input a byte from I/O port 0x60 into AL
This reads a byte of data from I/O port 0x60 and stores it in the AL register.
6. OUT Instruction
The OUT instruction is used for output operations to an I/O port from a register. The value
of the register is written to the specified port.
Syntax:
OUT port, source
port: The I/O port number to which the data will be sent.
source: The register containing the data to be output.
Example:
OUT 0x60, AL ; Output the value of AL to I/O port 0x60
Answer: In the 8086 microprocessor, loop instructions are used to repeatedly execute a block
of code a specific number of times. Looping is essential for implementing repetitive tasks in
assembly language programs. The primary loop instructions in 8086 are:
1. LOOP
2. LOOPNZ / LOOPNE
3. LOOPZ / LOOPE
These loop instructions work by manipulating the CX register (or ECX in 32-bit versions),
which holds the count of iterations. Each time a loop instruction is executed, the CX register
is decremented by 1, and the loop continues until CX becomes zero. The behavior of the loop
can be modified by conditional checks (like Z for zero or NZ for non-zero).
1. LOOP Instruction
The LOOP instruction decrements the CX register by 1 and loops (jumps to the specified
label) if CX is not zero.
Syntax:
LOOP label
CX is automatically decremented by 1.
If CX is not zero, the program jumps to the specified label and repeats the loop.
If CX is zero, the loop is exited, and the program continues with the next instruction.
Example:
MOV CX, 5 ; Load CX with 5 (loop will run 5 times)
START_LOOP:
MOV AX, 0 ; Some code to execute in the loop
ADD AX, 1 ; Increment AX
LOOP START_LOOP ; Decrement CX and loop back if CX != 0
In this example:
The LOOPNZ (Loop if Not Zero) or LOOPNE (Loop if Not Equal) instruction decrements
the CX register by 1 and loops if CX is not zero and if the Zero Flag (ZF) is clear (i.e., the
condition is not zero).
Syntax:
LOOPNZ label
or
LOOPNE label
CX is decremented by 1.
The loop continues if CX is not zero and if ZF is clear (indicating the condition was
not zero).
Example:
MOV CX, 5 ; Load CX with 5
MOV AX, 0 ; Initialize AX to 0
START_LOOPNZ:
CMP AX, 3 ; Compare AX with 3
LOOPNZ START_LOOPNZ ; Loop if CX is not zero and AX != 3
INC AX ; Increment AX
In this example:
The loop will run as long as CX is not zero and AX != 3 (since CMP AX, 3 affects
the ZF).
The LOOPNZ instruction will only jump if ZF is not set (i.e., if the comparison was
not zero).
The loop will stop if CX reaches zero or AX becomes equal to 3.
The LOOPZ (Loop if Zero) or LOOPE (Loop if Equal) instruction decrements the CX
register by 1 and loops if CX is not zero and if the Zero Flag (ZF) is set (i.e., the condition is
zero).
Syntax:
LOOPZ label
or
LOOPE label
CX is decremented by 1.
The loop continues if CX is not zero and if ZF is set (indicating the condition is zero).
Example:
MOV CX, 5 ; Load CX with 5
MOV AX, 0 ; Initialize AX to 0
START_LOOPZ:
CMP AX, 0 ; Compare AX with 0
LOOPZ START_LOOPZ ; Loop if CX is not zero and AX == 0
INC AX ; Increment AX
In this example:
5. Illustrate the term, “Procedure” in 8086 and explain how to define and call a
procedure.
Defn: 2 marks
Explanation: 3 marks
Answer: A procedure is a block of code that performs a specific task. Procedures in 8086
allow modularity and code reusability.
Defining a Procedure: To define a procedure, the PROCEDURE directive is used,
and the RET instruction returns control to the calling program.
Example:
assembly code
PROC1 PROCEDURE
; Procedure instructions
RET
PROC1 ENDP
Calling a Procedure: The CALL instruction is used to invoke a procedure, which
pushes the return address onto the stack and transfers control to the procedure.
Example:
Assembly code
CALL PROC1 ; Calls the PROC1 procedure
After execution, the RET instruction in the procedure will return control to the next
instruction after CALL.
6.Relate macros in assembly language. Discuss how are they defined and used in 8086.
Defn: 2 marks
Explanation with Ex: 3 marks
Answer: A macro is a sequence of assembly instructions that is defined once and can be used
multiple times in a program. Macros are expanded during the assembly process, and their
code is inserted at the point where the macro is called.
Defining a Macro: A macro is defined using the MACRO directive and ends with the
ENDM directive.
Example:
MYMACRO MACRO
; Macro instructions
MOV AX, BX
ENDM
Using a Macro: A macro is called by using its name in the program. When invoked,
the macro's code is inserted inline.
Example:
Assembly code
MYMACRO ; Expands to MOV AX, BX
Macros allow code reuse but increase the size of the program since the code is expanded.
RET none returns from the subroutine to the main program RET
Answer: The IN and OUT instructions in the 8086 microprocessor are used for input and
output operations with I/O ports. These instructions allow the 8086 microprocessor to
communicate with external devices (like keyboards, monitors, or printers) or to transfer data
between the CPU and peripherals.
The IN instruction reads data from an I/O port into a register, while the OUT instruction
writes data from a register to an I/O port.
1. IN Instruction
The IN instruction is used to read data from an I/O port and store it into a register. The I/O
port is specified either as an immediate value (direct port address) or as a value in a register.
Syntax:
IN destination, port
destination: A register where the data from the I/O port will be stored (e.g., AL, AX,
DX).
port: The I/O port number from which data will be read. The port can be specified as
an immediate value (a constant) or a register.
Operation:
The IN instruction reads a byte (if using 8-bit registers like AL) or a word (if using
16-bit registers like AX) of data from the I/O port and stores it in the specified
destination register.
Examples:
IN AL, 0x60 ; Read a byte from I/O port 0x60 into the AL register
This reads a byte from I/O port 0x60 and stores it in the AL register.
2. OUT Instruction
The OUT instruction is used to send data from a register to an I/O port. The I/O port is
specified either as an immediate value (direct port address) or as a value in a register.
Syntax:
OUT port, source
port: The I/O port number where data will be written. The port can be specified as an
immediate value (a constant) or a register.
source: A register whose data will be written to the I/O port (e.g., AL, AX, DX).
Operation:
The OUT instruction sends a byte (if using 8-bit registers like AL) or a word (if using
16-bit registers like AX) of data from the specified register to the specified I/O port.
Examples:
OUT 0x60, AL ; Write the byte in the AL register to I/O port 0x60
This sends the byte stored in the AL register to I/O port 0x60.
The IN and OUT instructions do not directly affect the FLAGS register. They are purely data
transfer instructions and are primarily used to move data between the CPU and I/O ports.
9. Demonstrate the CMP instruction in 8086 and explain the same with suitable syntax
and examples.
Defn & example: 2 marks
Syntax of each: 3 marks
Answer: The CMP instruction is used to compare two operands by subtracting the source
operand from the destination operand. It does not store the result but updates the flags based
on the result of the subtraction. This allows conditional branches based on the result.
The CMP (Compare) instruction in 8086 is used to compare two operands. It subtracts the
source operand from the destination operand, but it does not store the result. Instead, the
flags in the FLAGS register are updated based on the result of the subtraction.
This instruction is typically used to set the flags for conditional jump instructions like JE,
JNE, JL, JLE, etc., which are used to make decisions based on the result of the comparison.
The CMP instruction does not store the result of the subtraction; instead, it affects the status
flags (Zero Flag (ZF), Sign Flag (SF), Carry Flag (CF), Overflow Flag (OF), and Parity Flag
(PF)) based on the result of the subtraction.
NOTE: If Both Strings are Equal,CX becomes ZERO,the ZF is set otherwise ZF is reset
READ_LOOP:
LODSB Load a byte from the memory location pointed to by SI into AL,
and increment SI
STOSB Store the byte in AL at the memory location pointed to by DI,
and increment DI
LOOP READ_LOOP Decrement CX and loop back if CX is not zero
HLT Halt the processor (assembly language instruction for stopping
execution)
UNIT 3 ARM PROCESSOR ARCHITECTURE
Answer Key
Two Marks Questions
6. Summarize the functions of the DWT (Data Watchpoint and Trace) in Cortex-
M.
DWT (Data Watchpoint and Trace): Monitors data accesses and generates events
based on specific conditions, useful for debugging and performance profiling.
9. Demonstrate the role of the System Control Block (SCB) in Cortex-M processors.
Answer: The SCB manages the system control functions, 1 mark
including interrupt handling, system exceptions, 1 mark
system reset, and configuration of the vector table. 1 mark
It also provides status registers like the CPUID and AIRCR.
The Cortex-M block diagram typically includes key components such as the core
processor, interrupt controller, system control unit, and debug interfaces. The major
sections are:
ARM Cortex-M Core: This is the main processing unit that executes
instructions.
NVIC (Nested Vectored Interrupt Controller): Handles interrupts and
prioritizes them.
System Control Unit (SCU): Manages power and clock functions for the
processor.
Memory Protection Unit (MPU): Provides access control for different regions
of memory.
Debug Interfaces: Include features like the Embedded Trace Macrocell (ETM)
for real-time tracing and Instrument Trace Macrocell (ITM) for sending debug
information.
Significance in Embedded Applications: The Cortex-M block diagram is significant
because it provides a well-structured approach to real-time processing, power
efficiency, and low-latency interrupt handling—key requirements in embedded
systems. It is commonly used in applications like automotive control systems,
wearable devices, and IoT devices due to its low power consumption and high
processing speed.
3. Discuss the role of the memory address map and the impact of memory
endianness in system performance.
Memory Address Map: It defines how memory addresses are allocated to different
components such as RAM, ROM, peripheral registers, and special function registers.
This map enables efficient access to various memory segments, contributing to
overall system performance. 2 marks
Impact of Memory Endianness:
Big Endian and Little Endian refer to how byte sequences are stored in memory. In
Big Endian, the most significant byte is stored first, whereas in Little Endian, the
least significant byte is stored first. 1 mark
System Performance: The correct handling of endianness is crucial for performance,
especially when communicating with external devices. Misaligned endianness can
cause overhead due to extra conversion cycles or may lead to incorrect data
interpretation. 1 mark
Hardware Design: Some systems are optimized for a specific endianness, and having
mismatched configurations between devices or memory can lead to inefficiencies in
data transfers. 1 mark
4. Illustrate the concept of bit banding and explain how it improves memory
access efficiency.
5. Explain the debug system components (AHB, FPB, DWT, ITM, ETM, TPIU)
and their significance in debugging embedded applications.
Interrupt Management
1. Automatic Context Saving: When an interrupt occurs, the processor
automatically saves critical registers (R0-R3, R12, LR, PC, and xPSR) onto the
stack.
2. Vector Table: Interrupts are managed through a vector table that maps interrupt
requests to their handlers.
3. Nested Vectored Interrupt Controller (NVIC): The NVIC allows prioritization
and nesting of interrupts.
Key Steps:
Save context on the stack.
Jump to the interrupt service routine (ISR).
Restore context from the stack upon ISR completion.
7. Compare and Contrast the Functions of the Bus System and the Bus Matrix in
Cortex-M Processors.
1. 2 CO4 K2
The two states of operation of ARM processor are, ARM state and
thumb state.
ARM state Thumb state
32 bit operations only Can perform 16-bit half
word
Operations
High performance Higher instruction code
density
1
bitwise operations, which can operate on individual bits and do not
have any adjacency requirement.
7. The special rotate right extended (RRX) instruction has a slightly 2 CO4 K2
different behavior from the usual rotate operations. One key
difference is that no count is specified and this instruction always
rotates by one bit. Second, 1 bit rotation in RRX involves the C flag
as part of the rotation. The LSB of the register moves to C flag and
the original value of C flag enters the MSB of the register.
8. A 32-bit word object will result in an aligned word access if the first 2 CO4 K2
two bits of its starting address are zero or if it is divisible by 4.
Otherwise, the 32-bit data access is unaligned. Usually aligned
memory accesses are faster than the unaligned accesses. But on the
other hand, memory is better utilized with unaligned access. As a
result, there is a tradeoff between memory size required for certain
data and the speed at which this data can be accessed by the
processor.
9. The rules to be followed using stack are, 2 CO4 K2
The push and pop operations should always be performed
inside the memory region specified for stack.
The number of push operations should always have a
matching number of pop operations following a specified
order.
10. The special registers used in ARM processor are, 2 CO4 K1
1. The two types of development environments used in KEIL tool are CO4 K2
software and hardware levels.
2
The second environment enables the user to download, run, 1
and debug the program on an actual hardware platform.
MOV R1, #1 1
LSL R1, #4 ; R1 = 1 << 4 1
ORR R0, R0, R1 ; R0 = R0 | R1 1
7. The operation of the ALP instruction MLA R1, R2, R3, R5 of ARM CO4 K2
processor is
1 Sequence of steps that are followed after reset operation in ARM Cortex CO4 K2
M4:
Memory map is 2
4
we have a code region, where we are going to write our final binary.
That memory is starting from 0x00000000 to 0x1FFFFFFF. The code
region has the final output of our program (.hex or .bin or etc). SRAM
will be having stack, heap, global RW variables, and Static variables,
etc.
5
The final output of our program will be ordered in this way by using a
linker. So, the vector table is starting from 0x00000000 by default.
The vector table will contain all the locations of the exception and
interrupt ISR. As Cortex-M4 has below exceptions, interrupts and those
things are ordered in the below image.
6
The 0x00000000 address contains the initial Stack Pointer Value. Then
0x00000004 has the address of the reset handler.
7
R0 to R12 are the general-purpose registers.
R13 is reserved for the programmer to use it as the stack
pointer.
R14 is the link register which stores a subroutine return
address.
R15 contains the program counter and is accessible by the
programmer.
There are different ways to specify the address of the operands for any 3
given operations such as load, add or branch. The different ways of
determining the address of the operands are called addressing modes.
The different addressing modes of ARM processor fit into a single word
(32 bits).
3. The code for finding minimum and maximum values in numeric array is 5 CO4 K3
given as,
Logic – 1 mark
Program-4 marks
print("""@ Min-Max.s
@ Find minimum and maximum values in array NUM1
.data
NUM1: .word 82, 45, 93, 17, 64, 31, 78, 25, 59 @ Array of
numbers
N: .word 9 @ Length of array
MIN: .word 0 @ Variable to store minimum
MAX: .word 0 @ Variable to store maximum
.text
.global _start
_start:
9
LDR R0, =NUM1 @ Load address of array
LDR R1, [R0] @ Load first element
MOV R2, R1 @ Initialize MIN with first element
MOV R3, R1 @ Initialize MAX with first element
LDR R4, =N @ Load address of N
LDR R4, [R4] @ Load value of N
MOV R5, #1 @ Initialize counter i = 1
loop:
CMP R5, R4 @ Compare i with N
BGE endloop @ If i >= N, exit loop
checkmax:
CMP R7, R3 @ Compare current element with MAX
BLE continue @ If current <= MAX, continue
MOV R3, R7 @ Update MAX
continue:
ADD R5, R5, #1 @ Increment counter
B loop @ Repeat loop
endloop:
LDR R0, =MIN @ Load address of MIN
STR R2, [R0] @ Store minimum value
LDR R0, =MAX @ Load address of MAX
STR R3, [R0] @ Store maximum value
@ Exit program
MOV R7, #1 @ Exit syscall
SWI 0 @ Software interrupt
.end""")
In ARM state, all instructions can access R0 to R12, SP, and LR, and
most instructions can also access PC (R15). However, the use of the
SP in an ARM instruction, in any way that is not possible in the
corresponding Thumb instruction, is deprecated. Explicit use of the PC
in an ARM instruction is not usually useful, and except for specific
instances that are useful, such use is deprecated. Implicit use of the PC,
for example in branch instructions or load (literal) instructions, is
never deprecated.
3
Register accesses
16-bit Thumb instructions can access only a limited set of registers.
There are also some restrictions on the use of special-purpose registers
by ARM and 32-bit Thumb instructions.
Most 16-bit Thumb instructions can only access R0 to R7. Only a small
number of these instructions can access R8-R12, SP, LR, and PC.
Registers R0 to R7 are called Lo registers. Registers R8-R12, SP, LR,
and PC are called Hi registers.
All 32-bit Thumb instructions can access R0 to R12, and LR. However,
apart from a few designated stack manipulation instructions, most
Thumb instructions cannot use SP. Except for a few specific
instructions where PC is useful, most Thumb instructions cannot use
PC.
11
In ARM state, all instructions can access R0 to R12, SP, and LR, and
most instructions can also access PC (R15). However, the use of the SP
in an ARM instruction, in any way that is not possible in the
corresponding Thumb instruction, is deprecated. Explicit use of the PC
in an ARM instruction is not usually useful, and except for specific
instances that are useful, such use is deprecated. Implicit use of the PC,
for example in branch instructions or load (literal) instructions, is never
deprecated.
12
lr=0x003fffff ;
lr=r14
r0=0x12
0x00008000 SWI 0x123456
POST
cpsr=nzcVqIft_SVC
spsr= nzcVqift_USER
pc=0x000000008
lr=0x00008004
r0=0x12
Since SWI instructions are used to call operating system routines, it is
required some form of parameter passing. This achieved by using
registers. In the above example, register r0 is used to pass parameter
0x12. The return values are also passed back via register.
13
7. Logic – 2 marks 5 CO4 K3
Program – 3 marks
ENTRY
BCS ONES
B NEXT
BNE AGAIN
SVC #0123456
END
14
and we say that it employs a full-descending stack management.
The assembly instructions to access the stack memory region are PUSH
and POP. A PUSH instruction copies one or more data objects from a
register or a list of registers onto the stack, whose starting address is
determined by SP. The POP instruction works in the opposite manner.
The general syntax for these two instructions is given below.
To push a data object on the stack, the stack pointer is first decremented
by 4, and then the 32-bit information is stored at the address specified
by SP.
To pop a
data object from the stack, the 32-bit information pointed to by SP is
first retrieved, and then the stack pointer is incremented by 4. The SP
register points to the last item pushed, which is also the next item to be
popped. It is possible to use SP instead of R13, when writing an
assembly program. It is important to note that with PUSH and POP
instructions SP gets adjusted automatically.
In the case of PUSH, the register or set of registers is source operand
while the memory region reserved for the stack in the RAM is the
destination. On the other hand, for POP instruction a register or set of
registers is the destination and memory is the source. Please note that
the contents of the source operands are not changed, while those of the
destination operands get updated.
loop body
loop LDR r4,[r3,r0,LSL #2] ; get c[i]
LDR r6,[r5,r0,LSL #2] ; get x[i]
MUL r4,r4,r6 ; compute c[i]*x[i]
ADD r2,r2,r4 ; add into running sum f
ADD r0,r0,#1 ; add 1 to i
CMP r0,r1 ; exit?
BLT loop ; if i < N, continue ;
Finalize result
LDR r3,=f ; point to f
STR r2,[r3] ; f = result
17
UNIT 5 ARM PROCESSOR INTERFACING
SCHEME OF EVALUATION
Two Marks Questions
1. Name the main processing unit in the TM4C123 microcontroller and its primary
role.
o The main processing unit is the ARM Cortex-M4F processor.
o Its primary role is to execute instructions, perform computations, and control
peripheral operations efficiently, including floating-point tasks.
2. Categorize the real-time applications of the TM4C123 microcontroller into
automotive, industrial, and IoT domains.
o Automotive: Vehicle diagnostics, anti-lock braking systems (ABS).
o Industrial: Motor control, process automation.
o IoT: Smart home controllers, wireless sensor networks.
3. What is polling?
o Polling is a method where the CPU continuously checks the status of a
peripheral device to determine if it requires processing.
4. Compare keypad interfacing with switch interfacing in TM4C123.
o Keypad Interfacing: Requires multiple GPIO pins and is used for multi-input
systems like 4x4 keypads.
o Switch Interfacing: Uses fewer GPIO pins and is suitable for single-control
inputs like push buttons.
5. Clarify the concept of I/O synchronization and state its necessity in
microcontrollers.
o Concept: Ensures data transfer between the CPU and peripherals aligns with
clock cycles or states.
o Necessity: Prevents data corruption and ensures peripherals operate reliably
with the processor.
6. Compare the benefits of interrupt-driven and polling methods in handling I/O
operations.
o Interrupt-Driven: CPU is free until an interrupt occurs, improving efficiency
and responsiveness.
o Polling: Simple to implement but inefficient due to constant CPU checking.
7. How is a timer used as an I/O device in microcontrollers?
o A timer can generate precise delays, periodic signals, or act as a counter to
measure external events.
8. Write an application of a timer as an event counter.
o A timer can count pulses from a tachometer to measure the speed of a rotating
object.
9. Name the two lines used in I2C communication.
o SDA (Serial Data Line) and SCL (Serial Clock Line).
1.Interpret the role of the Nested Vector Interrupt Controller (NVIC) in TM4C123
For each role with explanation- One mark
Interrupt Prioritization & Nesting
NVIC supports up to 138 interrupt sources, each with programmable priority levels.
It allows nested interrupts, meaning a higher-priority interrupt can preempt a lower-
priority one.
Priority levels range from 0 (highest priority) to 7 (lowest priority).
Fast Interrupt Handling
NVIC reduces interrupt latency by using a vector table, which directly stores interrupt
addresses.
It ensures rapid context switching by automatically saving/restoring registers upon
entering/exiting an interrupt.
Efficient Power Management
NVIC allows selective enabling/disabling of interrupts, optimizing power consumption
in embedded applications.
Support for Exception Handling
It manages system exceptions like Hard Faults, Bus Faults, and SysTick interrupts.
Ensures the microcontroller can recover from faults efficiently.
Interrupt Masking & Software Interrupts
Developers can mask (disable) specific interrupts to prevent unwanted interruptions
during critical tasks.
NVIC supports software-triggered interrupts, which can be generated manually via
code.
Vector Table Offset Control
The vector table location can be changed dynamically, allowing the system to relocate
interrupt vectors in memory.
In direct interface each keypad switch (e.g., push button, slide switch, toggle switch, etc.) is
interfaced directly to a dedicated digital GPIO pin of the microcontroller. This type of
interfacing requires n number of GPIO pins for n switches. One key advantage of this
interfacing approach is its capability to detect all possible combinations of multiple
simultaneous switch presses. For n switches, the possible combinations are 2 n. This method
can be used for specific switch combination that needs to be configured or when multiple
simultaneous key presses are required to be recognized. The negative aspect of this approach
is the fact that it is prohibitively demanding in terms of GPIO pins. Some of the possible uses
of this approach are modifier keys (e.g., Shift, Ctrl, Alt, Func keys on a computer keyboard) as
well as in the music keyboards. Figure illustrates the direct hardware interfacing of an eight
switch keypad
The interrupt-driven keypad interface requires additional hardware modifications for proper
functioning. Figure illustrates the hardware needed to implement interrupt-driven interfacing
for a matrix-type keypad. For this interface to work correctly, an interrupt must be generated
each time a key is pressed. To achieve this, four diodes are used, as shown in Figure, which
help in uniquely identifying the pressed key. During initialization, logic 1 is applied to all four
columns. When a key is pressed, a low-to-high transition is generated at PF4, triggering an
interrupt. The keypad scanning then takes place as part of the Port F Interrupt Service Routine
(ISR). It is important to note that the keypad scan function is executed only once for each key
press.
7. Compare polling and interrupt-driven systems in terms of efficiency.
For any three comparisons - Three marks
Power Higher, because the CPU is active and Lower, as the CPU can sleep until an
Consumption checking events continuously. interrupt occurs.
Less scalable, especially with many More scalable, as multiple events can be
Scalability
events to monitor. handled with separate interrupts.
An external
event can be marked by a rising, a falling or both edges. The external events can be either
periodic or aperiodic. A timer can be easily configured to count external events by connecting
the counter input to the external signal source. The functional diagram of timer as an external
event counter is shown in Figure. From Figure observe that there is a selector switch, which
can be configured for timer input selection as internal or external. When an external signal is
used as an input to the timer, the timer counter value shows the number of external events. If
the event count reaches the maximum count value (e.g., 216 1 for 16 bit timer), then an over
ow interrupt can be generated by the timer. It is also possible to configure the timer as down
counter, while enumerating external events. In this case an under ow interrupt can be generated
after a predefined number of external events, depending on the counter initial value.
10. Compare the I2C and SPI communication protocols based on speed, data transfer,
and complexity.
Any three comparisons – Three marks
2. Discuss how to configure the pad control for a GPIO pin on the TM4C123
microcontroller.
The TM4C123 microcontroller platform (TI’s ARM Cortex-M4F-based TivaC) has three
onboard color LEDs (red, green, and blue) and two switches for simple input-output
interfacing. Both LEDs and switches function as digital devices. This section explains how to
interface each of these two different types of devices. LEDs are connected to GPIO pins as
digital outputs, while switches are configured as digital inputs.
The LEDs are connected using digital NPN transistors. A digital transistor integrates base (bias)
resistors inside the transistor package. Unlike ordinary transistors, a digital transistor operates
only in two states: off and saturation. The purpose of using transistors in this setup is to prevent
current overloading, which could occur if the GPIO pin is not capable of handling enough
current. The current that the GPIO pin has to sink depends on both the diode current-limiting
series resistor and the supply voltage.
The switch interfacing is not complete as shown in Figure 8.10. When the switch is pressed, a
logic low signal is applied to the GPIO port pin. However, when the switch is released, there
is no source connection to ensure a logic high signal at the GPIO port pin. Simple
microcontrollers may not function properly with this interface. However, the TM4C123
resolves this issue by using an internal pull-up resistor. When enabled, the pull-up resistor pulls
the GPIO pin to a logic high state when the switch is released. The internal pull-up resistor
values are generally greater than 10kΩ. Since the current drawn by the GPIO port pin, when
configured as an input, is very low due to its high input impedance, the voltage drop across the
pull-up resistor is almost negligible, ensuring that the voltage level remains close to the supply
voltage. This voltage level is interpreted as logic high by the internal logic.
An alternative configuration involves connecting the switch terminal to the supply voltage
(Vcc) instead of ground. In this case, enabling the internal pull-down resistor ensures proper
switch functionality. With this setup, a logic high signal is detected when the switch is pressed.
Similarly, for LED interfacing, an alternative approach is to reverse the LED direction by using
a PNP transistor, which requires reversing the driving logic.
Output Interfacing for LED
To interface LEDs, Port F pins 1, 2, and 3 need to be configured as outputs. The basic steps for
configuring the required Port F pins are:
Enable the clock to the GPIO port.
Select the general-purpose IO functionality by clearing the alternate function select
register (GPIOAFSEL).
Configure the GPIO direction for digital output.
Configure the PAD for digital operation.
Input Interfacing for Switch
Mechanical switches are commonly used for input in digital systems. These switches can be
interfaced with a microcontroller using digital inputs. The software program for switch
interfacing can be implemented using one of two methods:
1. Polling-Based Method:
o In this method, the GPIO pin connected to the switch is frequently polled in
software to avoid missing key presses.
o The polling interval should be shorter than the minimum time the switch is held
down by the user.
2. Interrupt-Based Method:
o The GPIO pin is configured as an external interrupt.
o A key press triggers an interrupt, which can be edge-triggered on either the
rising or falling edge, depending on the switch hardware.
4. Explain the Polling-Based Methods of input-output synchronization.
Continuous Polling (Busy Wait)-3 mark
Periodic Polling-2 mark
Polling is a mechanism in which the software continuously or periodically checks the status
of a hardware device to determine whether an operation has been completed. This method
helps in managing input/output (I/O) operations by allowing the software to respond only
when necessary. Polling-based synchronization can be classified into two types:
1. Continuous Polling (Busy Wait)
Working Principle
In continuous polling, also called busy waiting, the software runs an infinite loop to
check the device status repeatedly.
Once the device completes its operation, it updates a status flag. The software detects
this change and proceeds with the next operation.
Examples
Input Device (e.g., Keyboard, Sensor, or Network Card)
o The software continuously checks if new data is available from the input
device.
o Once data is available, it is read and processed.
o Example: A program continuously checking for user input from a keyboard.
Output Device (e.g., Printer, Display, or Hard Drive)
o The software first writes data to the output device and then continuously
checks its status to confirm whether the operation is complete.
o In another variation, the software first checks if the device is ready before
writing data, allowing some level of parallel execution.
Advantages
✔ Simple to implement.
✔ Ensures immediate response as the software is constantly checking the status.
Disadvantages
✖ Wastes CPU time, as the processor remains occupied in checking the status instead of
performing other useful tasks.
✖ Can cause software blocking, where the processor remains stuck in the loop indefinitely
in case of hardware failure.
2. Periodic Polling
Working Principle
To avoid software blocking, periodic polling uses a timer to generate interrupts at
regular intervals.
Instead of continuously checking the device status, the software checks only when an
interrupt occurs.
Examples
Input Device (e.g., Sensor, Network Receiver)
o When new data is available, the device sets a status flag.
o At the next timer interrupt, the software reads and processes the data.
Output Device (e.g., Printer, Display Buffer)
o The device sets a status flag when it completes an operation.
o The software checks the flag at the next interrupt and, if the device is ready, it
initiates the next operation.
Advantages
✔ Prevents software blocking, as the CPU is free to perform other tasks between polling
intervals.
✔ More efficient compared to continuous polling, as the CPU is not occupied with unnecessary
status checks.
Disadvantages
✖ Can introduce a delay in response time.
✖ The maximum delay can be equal to the timer interrupt period, meaning there might be a
waiting time before the software detects that the device is ready.
✖ Increasing the frequency of timer interrupts can improve performance but leads to higher
CPU overhead due to frequent ISR executions.
.
6. Examine the working of a multiplexed-type keypad when interfaced with the TM4C123
microcontroller.
Diagram -2 marks
Working - 3 marks
In scanned keypad interfacing, the switches are arranged in a matrix format, typically in an m
× n configuration, where m represents the number of rows and n represents the number of
columns. This arrangement allows the use of fewer GPIO pins for interfacing the keypad with
the microcontroller. The software scans the keypad by configuring m rows as inputs and n
columns as outputs. The scanning process involves driving one column at a time, setting it to
a low state (active), and reading the rows to detect which key is pressed in the active column.
This is repeated for each column to detect all key presses in the keypad.
For example, in the TM4C123 microcontroller, you can configure the rows as input pins and
the columns as output pins. The rows may use internal pull-down resistors available in the
microcontroller, eliminating the need for external pull-down resistors in the circuit. This
capability simplifies the design and reduces the number of components required, making the
system more efficient.
One of the key advantages of the scanned keypad interfacing approach is the reduced number
of GPIO pins required. Specifically, a keypad with m × n keys can be interfaced using only m
+ n GPIO pins. This reduces the number of pins compared to direct individual key interfacing,
where each key would need a dedicated pin. For example, for a 4x4 keypad (16 keys), only 8
GPIO pins are needed—4 for the rows and 4 for the columns—versus the 16 GPIO pins
required for a direct interface.
However, this approach has its limitations. One significant drawback is its handling of
simultaneous key presses. The scanned approach is capable of detecting only two simultaneous
key presses. If more than two keys are pressed at the same time, the system can experience key
ghosting or key bouncing. For instance, when keys are pressed in an L-shaped pattern (e.g.,
keys 1, 4, and 5), the system may falsely detect a fourth key press (key 2 in this case) as pressed,
even if it is not physically pressed. This issue arises due to the way the rows and columns
interact during the scanning process, which results in the erroneous detection of additional key
presses when multiple keys are simultaneously pressed.
Thus, while the scanned keypad interface is efficient and works well for detecting a few key
presses, it cannot reliably detect three or more simultaneous key presses. This limitation must
be considered when designing systems that require accurate detection of multiple key presses
at once, such as in complex user input scenarios or systems that need to handle simultaneous
multi-key input.
For instance, if n = m = 4, the setup would involve using 4 GPIO output pins to drive a 4-to-
16 demultiplexer, which then controls the 16 columns of the keypad. At the same time, the 16
rows of the keypad are connected to a 16-to-4 multiplexer that interfaces with 4 GPIO input
pins on the microcontroller. This allows for the interfacing of a keypad with 2^4 × 2^4 = 16 ×
16 = 256 keys using only 8 GPIO pins, which is the maximum number of keys that can be
handled for this configuration. The multiplexing technique optimizes the use of GPIO pins,
allowing a more efficient and scalable interface for larger keypads.
However, since a large number of keys are connected in a multiplexed fashion, the process of
scanning the entire keypad to detect a key press takes significant processing time. The
microcontroller must sequentially scan the rows and columns, activating one row at a time and
reading the corresponding columns to identify which key is pressed. This scanning process
takes time and is one of the drawbacks of multiplexed interfacing.
The relationship between the number of GPIO pins and the number of keys that can be
interfaced is summarized as follows: using m GPIO input pins and n GPIO output pins, the
system can interface a keypad with 2^m × 2^n keys. This method is far more efficient than
connecting each key individually, which would require a separate GPIO pin for each key,
greatly increasing the number of pins needed for larger keypads.
However, this method has some limitations, such as the inability to handle situations like the
"two-key rollover." In a two-key rollover scenario, the first key is pressed and then released
before the second key is pressed. The multiplexed keypad interfacing method described here
assumes that each key is pressed and released before the next key is detected, which could
cause problems in situations where multiple keys are pressed simultaneously.
To illustrate this method, consider a 16-button keypad arranged in a 4x4 matrix. In this case, 8
GPIO pins are used: 4 output pins control the columns, and 4 input pins read the rows. The
microcontroller scans the keypad by sequentially activating the rows and reading the columns,
identifying which key is pressed based on the row-column combination. This process is
relatively straightforward, but due to the multiplexed nature of the interface, it requires careful
handling of timing and key press detection to avoid issues like key bouncing or missed presses.
8. Illustrate the working principle of the I2C communication protocol with respect to
the TM4C123 microcontroller.
Working principle Step 1 -2 – 2 marks
Step 3 - 5 - 3 marks
I2C (Inter-Integrated Circuit) is a communication protocol designed for connecting
multiple devices (master and slave) over a two-wire interface: the Serial Data Line (SDA)
and the Serial Clock Line (SCL). It is commonly used for communication between
microcontrollers and peripheral devices such as sensors, EEPROMs, and ADCs.
Communication Process:
1. Start Condition: The communication begins when the SDA line transitions from high
to low while the SCL line is high, indicating that a data transfer is about to occur.
2. Addressing: The master sends a 7-bit or 10-bit address of the target slave. The 8th bit
indicates the type of operation (0 for write, 1 for read).
3. Data Transfer: Data is transmitted in 8-bit chunks, with each byte followed by an
acknowledgment (ACK) bit to confirm successful reception. If a byte is not received
correctly, a negative acknowledgment (NACK) can be sent.
4. Stop Condition: The communication ends when the SDA line transitions from low to
high while the SCL line is high, marking the end of data transmission.
9. Outline the steps to configure SPI module for data transfer in TM4C123.
For each step - One mark
To configure the SPI (Serial Peripheral Interface) module for data transfer in the TM4C123
microcontroller (from Texas Instruments), you need to follow a series of steps. These steps
include enabling the clock for the SPI module, configuring the relevant SPI parameters (such
as mode, bit order, and data rate), setting up the data frame format, and finally initiating data
transfers.
Here’s a detailed outline of the steps to configure SPI for data transfer in the TM4C123
microcontroller:
1. Enable Clock for the SPI Module
Before configuring the SPI module, the clock for the module must be enabled in the system
control register.
Enable the clock to the SPI peripheral (e.g., SPI0).
Set the clock source for the SPI module.
2. Configure GPIO Pins for SPI
The TM4C123 microcontroller uses dedicated GPIO pins for SPI communication (e.g., SCK,
MOSI, MISO). These pins need to be configured as alternate functions.
Set the pins for SCK (clock), MOSI (Master Out Slave In), and MISO (Master In
Slave Out).
Configure the pin direction (input/output) and select the alternate function for the SPI.
3. Configure the SPI Module (SSI)
Set up the SSI0 (or another SPI instance) for the desired operation. This involves configuring
the SSI Control Register (SSI0_CR1) and SSI Configuration Register (SSI0_CR0).
Set the master/slave mode.
Set the clock polarity (CPOL) and clock phase (CPHA) for communication.
Set the data frame format (typically 8-bit).
Configure the baud rate (divide the system clock to achieve the desired rate).
4. Enable the SPI Interrupts
If you need to handle data transfer via interrupts (for asynchronous operation), enable the
interrupts for the SPI module.
5. Send Data Using SPI
Once everything is set up, you can begin sending and receiving data using the SPI module.
Data is written to the SSI Data Register (SSI0_DR), and you can check the SSI Status
Register for flags to check if the transmission is complete or if the data register is ready.