0% found this document useful (0 votes)
35 views

ANSWERS 1 Microprocessor & Assembly Language Programming Year 3 Semester II

Microprocessor & Assembly Language Revision
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

ANSWERS 1 Microprocessor & Assembly Language Programming Year 3 Semester II

Microprocessor & Assembly Language Revision
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

UNIVERSITY EXAMINATION 2020/2021

YEAR 3 SEMESTER II EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE


IN COMPUTER SCIENCE

SPC 2312 Microprocessor & Assembly Language Programming Year 3 Semester II

Date: Friday 10th September, 2021 Time: 11.00 am – 1.00 pm

INSTRUCTIONS
Answer Question ONE and any other TWO Questions
Section (30 Marks)

Answer all questions in this section

Question One (30)


a) Define the following terms as applied in microprocessors and assembly 4 Marks
i) Accumulator: The accumulator is a special-purpose register within the microprocessor's
CPU. It acts as the primary register for storing operands (data used in calculations) during
arithmetic and logic operations (addition, subtraction, AND, OR, etc.) in assembly language
programming. The result of these operations is usually stored back in the accumulator for
further use.
ii) Subroutine program: A subroutine program, also known as a subroutine or a procedure, is
a reusable block of code within an assembly language program. It can be called from multiple
locations in the main program using a specific instruction (e.g., CALL). This allows for
modularity and code optimization by avoiding repetitive code.
b) Differentiate between ALIGN & ASSUME instructions of microprocessor 4 Marks

● ALIGN: The ALIGN instruction is used in assembly language to force the next
instruction to start at a specific memory address boundary. This can be useful for
aligning data structures or improving code execution efficiency on certain
microprocessor architectures.
● ASSUME: The ASSUME instruction allows the programmer to make assumptions about
the location of a register or memory address during assembly. This is often used for
temporary convenience during the assembly process. However, it's important to note
that ASSUME doesn't actually reserve memory or modify the program's behavior. The
assembler uses the assumed value during translation but may need adjustments later.

c) Differentiate between hardware interrupt and software interrupt giving examples in each
case 6 Marks

● Hardware Interrupt: A hardware interrupt is an asynchronous signal generated by an


external device (like a keyboard, timer, or network card) to notify the microprocessor
about an event requiring attention. The processor temporarily suspends its current task,
saves its state, and services the interrupt by executing an appropriate interrupt service
routine (ISR).
● Software Interrupt: A software interrupt is an instruction deliberately triggered within
the assembly language program itself. This allows the program to invoke specific system
services or handle internal events. Software interrupts provide a controlled way to
interact with the operating system or perform actions within the program.

d) Describe two types of Assemblies in assembly language programming.

● One-pass Assembler: A one-pass assembler reads the source code once and
translates it directly into machine code in a single step. This is faster but may not be
able to handle complex dependencies between program sections.
● Two-pass Assembler: A two-pass assembler reads the source code twice. In the first
pass, it gathers information about labels (symbolic names for memory locations) and
references (uses of those labels). In the second pass, it translates the code with all
references resolved to actual memory addresses. This allows for more complex code
structures and error checking.

e) Describe why direct memory access (DMA) is considered an efficient mechanism for
performing I/O. 4 Marks

Direct Memory Access (DMA) is considered an efficient mechanism for performing I/O
operations because it offloads data transfer between memory and I/O devices from the
microprocessor. A dedicated DMA controller manages the transfer without involving the CPU.
This frees up the processor to continue executing instructions while the I/O operation is
happening in the background. This improves overall system performance by reducing
processor overhead during I/O tasks.

f) Explain factors that affect characteristics and performance of a bus 4 Marks

Several factors influence the characteristics and performance of a bus in a microprocessor


system:
● Data Width: The width of the data bus determines how many bits of data can be
transferred simultaneously. A wider data bus allows for faster data transfer rates.
● Address Bus Width: The address bus width defines the total memory address space
that can be accessed by the processor. A wider address bus allows for addressing a
larger memory space.
● Clock Speed: The clock speed of the bus system determines the rate at which data is
transferred. A higher clock speed translates to faster data transfer.
● Control Lines: Specific control lines manage the flow of data, synchronization between
components, and memory access operations. The presence and functionality of these
control lines impact the overall efficiency of the bus.

g) Outline Four Characteristics of RISC microprocessor 4 Marks

Reduced Instruction Set Computing (RISC) processors are characterized by:

● Simple Instructions: RISC processors focus on a set of simple instructions that can be
executed in a single clock cycle. This simplifies the design and improves execution
speed.
● Few Addressing Modes: RISC architectures typically use fewer addressing modes for
instructions, reducing the complexity of decoding instructions during execution.
● Registers for Data: RISC processors rely more heavily on registers for data
manipulation, minimizing memory access and improving performance.
● Complex Control Unit: While instructions are simpler, the control unit in a RISC
processor may be more complex to handle instruction sequencing and pipeline
management efficiently.

h) Describe the term data movement as applied in assembly language programming 4


Marks

Data movement in assembly language programming refers to instructions that transfer data
between various locations within the microprocessor system. These locations can include:

● Registers: Internal CPU registers used for temporary storage and manipulation of data.
● Memory: The main memory of the system where data and programs are stored.
● I/O Devices: Peripheral devices like keyboards, displays, or network cards that interact
with the processor.

Common assembly language instructions for data movement include:


● Load (LD): Loads data from a memory location or I/O device into a register.
● Store (ST): Stores data from a register to a memory location or I/O device.
● Move (MOV): Transfers data between two registers within the CPU.
● Push/Pop: Used with a stack, a special area of memory, to store and retrieve data
(often used for subroutine calls and parameter passing).

These instructions, along with addressing modes that specify the source and destination of the
data, form the foundation for manipulating and processing data within assembly language
programs.

Section B (40 Marks)


Answer any two questions from this section
Question Two (20 Marks)

a) Describe Assembly Language Condition Codes (6 Marks)

Assembly language condition codes are flags set by the microprocessor's ALU (Arithmetic
Logic Unit) after performing arithmetic and logical operations. These flags indicate the outcome
of the operation, allowing the program to make decisions based on the results. Common
condition codes include:

● Zero Flag (ZF): Set to 1 if the result of the operation is zero.


● Carry Flag (CF): Set to 1 if there was a carry out of the most significant bit during
addition or a borrow out during subtraction.
● Sign Flag (SF): Set to 1 if the result is negative.
● Overflow Flag (OF): Set to 1 if an arithmetic overflow occurred (result is too large or too
small to be represented in the destination register).

Conditional branch instructions in assembly language utilize these flags to control program
flow. For example, a JZ (Jump if Zero) instruction will only jump to a specific code section if the
Zero Flag (ZF) is set (meaning the previous operation resulted in zero).

b) Bus Architectures in Microprocessors (6 Marks)

i) Peripheral Component Interconnect (PCI):

The Peripheral Component Interconnect (PCI) bus is a high-performance internal bus


architecture for connecting peripheral devices like network cards, graphics cards, and storage
controllers to the microprocessor in a computer system. Key features of PCI include:
● High bandwidth: Supports data transfer rates at hundreds of megabytes per second.
● Burst mode transfers: Allows for transferring multiple data elements in a single bus
transaction, improving efficiency.
● Plug-and-play: Enables dynamic configuration of devices on the bus.
● Master/Slave architecture: Defines devices that can initiate data transfers (masters)
and those that respond to requests (slaves).

ii) Universal Serial Bus (USB):

The Universal Serial Bus (USB) is a serial bus standard commonly used for connecting
external peripherals like keyboards, mice, printers, and external storage devices to a computer.
Key characteristics of USB include:

● Serial communication: Transfers data one bit at a time.


● Plug-and-play: Allows for easy connection and configuration of devices.
● Multiple data transfer speeds: Supports different speed variations (USB 1.0, 2.0, 3.0,
etc.) with varying transfer rates.
● Power delivery: Can provide power to low-power devices through the bus connection.

c) Finding the Largest Number in 8086 Assembly (8 Marks)

Here's an assembly language program for the 8086 microprocessor that finds the largest
number from a series of 10 numbers stored in memory locations starting from DATA_START:

Code snippet

; Define data segment

DATA_SEGMENT SEGMENT

DATA_START DW 10 DUP (?) ; Allocate space for 10 word (16-bit)


values

; (replace '?' with actual data values)

DATA_SEGMENT ENDS

; Define code segment

CODE_SEGMENT SEGMENT ASSUME CS:CODE_SEGMENT


START:

MOV AX, @DATA_START ; Load address of first number into AX

MOV CX, 10 ; Initialize counter for 10 numbers


(CX)

FIND_LARGEST:

LODS WORD PTR AX ; Load current number into DX

CMP DX, [AX] ; Compare with current largest (in AX)

JG IS_LARGER ; If greater, jump to update largest

LOOP FIND_LARGEST ; Loop 10 times to check all numbers

; After loop, AX holds the address and DX holds the largest


number

; (Optional: You can display the largest number here)

MOV AH, 4CH ; AH = 4Ch for DOS exit function

INT 21h ; Terminate program

IS_LARGER:

MOV AX, DX ; Update largest number in AX

MOV [AX], DX ; Store largest number back to memory

JMP FIND_LARGEST ; Continue loop to check remaining numbers


CODE_SEGMENT ENDS

END START ; Program entry point

Explanation:

1. The program defines a data segment with space for 10 words (16-bit values) to store the
number series (replace ? with actual data).
2. The code segment starts with the START label where the program begins.
3. It loads the address of the first number

Question Three (20 Marks)

a) Explain Three features of microprocessors 6 Marks

Microprocessors are the brains of modern computers and possess several key features:

1. Central Processing Unit (CPU): The microprocessor acts as the central processing
unit, fetching, decoding, and executing instructions. It performs arithmetic and logical
operations, manages data flow, and controls other components within the system.
2. Instruction Set Architecture (ISA): Each microprocessor has a defined ISA, a set of
instructions it understands and can execute. The ISA determines the types of operations
the processor can perform and how data is manipulated. Software developers write
programs specific to the target microprocessor's ISA.
3. Clock Speed: The microprocessor operates at a specific clock speed, measured in MHz
(MegaHertz) or GHz (Gigahertz). This clock speed determines the number of cycles the
processor can execute per second. A higher clock speed generally translates to faster
processing performance.

b) Explain areas of applications of interrupts 6 Marks

Interrupts are a crucial mechanism for handling asynchronous events within a computer
system. Here are some common areas where interrupts are used:

1. Input/Output (I/O) Operations: When an external device (keyboard, network card)


requires attention, it can generate an interrupt signal to notify the processor. This allows
the processor to temporarily suspend its current task, service the I/O request (like
handling a key press), and then resume its previous operation.
2. Timers: Timer interrupts can be used to trigger periodic tasks at specific intervals. This
is essential for functionalities like real-time processing (updating the system clock),
refreshing the display, or initiating background tasks at regular intervals.
3. Error Handling: Hardware or software errors can trigger interrupts, alerting the
processor to potential issues. This allows the system to initiate error handling routines,
potentially preventing crashes or data loss. Interrupt-driven error handling enables the
processor to address issues efficiently and maintain system stability.

c) With reference to architecture of 8086 microprocessor write a program


to multiplies two constants and displays the result 8 Marks

Here's an assembly language program for the 8086 microprocessor that multiplies two
constants and displays the result (replace CONSTANT1 and CONSTANT2 with your actual
values):

; Define data segment


DATA_SEGMENT SEGMENT
CONSTANT1 DW 5 ; Define first constant (replace with
your value)
CONSTANT2 DW 3 ; Define second constant (replace with
your value)
RESULT DW 0 ; Allocate space to store the product

DATA_SEGMENT ENDS

; Define code segment


CODE_SEGMENT SEGMENT ASSUME CS:CODE_SEGMENT
START:
MOV AX, @CONSTANT1 ; Load first constant into AX
MOV BX, @CONSTANT2 ; Load second constant into BX
MUL BX ; Multiply AX by BX (result in
DX:AX)
MOV WORD PTR RESULT, DX ; Store lower 16 bits of
result in memory

; Display the result (optional)


MOV AH, 9 ; AH = 9 for printing an
unsigned integer
MOV DX, OFFSET RESULT ; Set DS:DX to point to the
result
INT 21h ; Call DOS interrupt to print
the value in DX

MOV AH, 4CH ; AH = 4Ch for DOS exit function


INT 21h ; Terminate program

CODE_SEGMENT ENDS

END START ; Program entry point

Explanation:

1. The program defines a data segment with memory locations for the constants and the
result.
2. In the code segment, it loads the constants into registers AX and BX.
3. The MUL BX instruction multiplies the values in AX and BX, storing the lower 16 bits of
the result in AX and the upper 16 bits (if any) in the DX register.
4. The lower 16 bits of the product (in AX) are then stored in the memory location pointed
to by RESULT.

(Optional): Displaying the Result

The provided code also includes an optional section to display the result using a DOS interrupt
call. This functionality depends on the specific environment you're running the assembly
program in. You might need to adjust this section based on your system's requirements.

Question Four (20 Marks)


a) Describe the following types of special type of microprocessors 6 Marks

i) Transputer Microprocessor:

● A transputer is a specialized microprocessor designed for parallel processing. It


contains multiple processing elements (cores) that can communicate with each other
directly.
● This architecture enables efficient execution of tasks that can be broken down into
concurrent processes, significantly improving performance for suitable applications.
● Transputers are well-suited for areas like:
○ Scientific computing (complex simulations)
○ Image processing (parallel image manipulation)
○ Real-time systems (demanding real-time responsiveness)

ii) Digital Signal Processor (DSP):

● A Digital Signal Processor (DSP) is a specialized microprocessor optimized for


processing digital signals.
● It typically includes features like:
○ Hardware multipliers for efficient mathematical operations
○ Accumulators for fast signal accumulation
○ Specialized instructions for digital signal processing algorithms (filtering,
compression)
● DSPs are widely used in applications that involve processing digital signals, such as:
○ Audio and video processing (compression, filtering, effects)
○ Digital filtering (noise reduction, signal enhancement)
○ Real-time signal processing (communication systems, modems)

b) Explain different methods are used to decide which device to select when
more than one device raises an interrupt request signal. 6 Marks

When multiple devices request an interrupt simultaneously, the processor needs to determine
which interrupt gets serviced first. Here are some common interrupt priority methods:

● Fixed Priority: Each interrupt source is assigned a fixed priority level. Higher priority
interrupts preempt lower priority ones, ensuring critical events are handled first. This is
simple to manage but may not be suitable for situations where interrupt frequency varies
greatly.
● Nested Interrupt: The processor can temporarily disable lower-priority interrupts while
servicing a higher-priority interrupt. This prevents lower-priority events from interrupting
the handling of a critical event. Nested interrupts offer more flexibility but require careful
management to avoid situations where high-priority interrupts prevent lower-priority ones
from being serviced indefinitely.
● Software-Configurable Priority: The interrupt priority levels can be dynamically
configured by software based on the system's needs. This allows for more flexible
prioritization but may require additional software overhead for managing priorities.
● Daisy Chaining: Devices are connected in a daisy chain where each device can identify
the source of the interrupt and pass the request along to the processor. The device
closest to the source has higher priority. This approach can be useful for specific bus
architectures.

The choice of interrupt priority mechanism depends on the specific requirements of the system,
considering factors like real-time response needs, interrupt frequency variations, and desired
flexibility in priority management.

c) Write an Assembly Language Program to find sum of odd numbers in a


given series containing 8 bit numbers stored in a continuous memory location
and store the result in another memory location. 8 Marks

Here's an assembly language program for the 8086 microprocessor that finds the sum of odd
numbers in a series of 8-bit values stored in a continuous memory location (replace
DATA_START with the actual starting address and adjust the loop count if needed):

; Define data segment

DATA_SEGMENT SEGMENT

DATA_START DB 10 DUP (?) ; Allocate space for 10 bytes


(8-bit values)

; (replace '?' with actual


data values)

RESULT DW 0 ; Allocate space to store the


sum
DATA_SEGMENT ENDS

; Define code segment

CODE_SEGMENT SEGMENT ASSUME CS:CODE_SEGMENT

START:

MOV CX, 10 ; Initialize counter for


10 elements (CX)

MOV AX, 0 ; Initialize sum


accumulator (AX)

MOV SI, @DATA_START ; Set memory pointer to


data start (SI)

SUM_LOOP:

MOV AL, [SI] ; Load current byte into


AL

TEST AL, 1 ; Check if least


significant bit is set (odd)

JZ NOT_ODD ; Jump if not odd

ADD AX, AL ; Add odd value to sum


(AX)

NOT_ODD:

INC SI ; Increment memory pointer


(SI)

LOOP SUM_LOOP ; Loop 10 times to check


all elements
; After loop, AX holds the sum of odd numbers

; (Optional: You can display the sum here)

MOV AH, 4CH ; AH = 4Ch for DOS exit function

INT 21h ; Terminate program

CODE_SEGMENT ENDS

END START ; Program entry point

Explanation:

1. The program defines a data segment with space for 10 bytes (8-bit values) and a word
(16-bit) variable to store the sum.
2. In the code segment, it initializes a counter for the loop, an accumulator for the sum, and
a memory pointer to the data start.
3. The loop iterates

Question Five (20 Marks)

a) Differentiate between the following as applied in machine


language

i) Level-Triggered Interrupt vs. Edge-Triggered Interrupt:

● Level-Triggered Interrupt:
○ Remains asserted (active) as long as the interrupting condition persists.
○ The processor will continue to receive the interrupt request until the condition is
cleared (goes back to inactive state).
○ Useful for situations where the processor needs to be notified of a condition that
exists for a certain duration (e.g., a device holding data ready for transfer).
● Edge-Triggered Interrupt:
○ Occurs only at the moment the interrupting condition transitions from inactive to
active (rising edge) or vice versa (falling edge).
○ The processor acknowledges the interrupt only at the specific point of transition.
○ Suitable for events that happen momentarily (e.g., a key being pressed or a timer
expiring).

ii) Doorbell Interrupt vs. Message-Signaled Interrupt (4 Marks)

● Doorbell Interrupt:
○ A simple interrupt signaling mechanism where a device asserts an interrupt line
to notify the processor of a condition.
○ Doesn't provide any additional information about the interrupt source or the
nature of the event.
○ The processor typically needs to poll devices to identify the source after receiving
the interrupt.
● Message-Signaled Interrupt:
○ Provides more information along with the interrupt request.
○ The interrupting device sends a message on a data bus along with the interrupt
signal, specifying the source and potentially additional details about the event.
○ This allows the processor to directly identify the source and handle the interrupt
more efficiently.

b) Program to find sum of Even numbers in a given series 8 Marks

Here's an assembly language program for the 8086 microprocessor that finds the sum of even
numbers in a series (replace DATA_START with the actual starting address and adjust the loop
count if needed):

; Define data segment

DATA_SEGMENT SEGMENT
DATA_START DB 10 DUP (?) ; Allocate space for 10 bytes
(8-bit values)

; (replace '?' with actual


data values)

RESULT DW 0 ; Allocate space to store the


sum

DATA_SEGMENT ENDS

; Define code segment


CODE_SEGMENT SEGMENT ASSUME CS:CODE_SEGMENT
START:
MOV CX, 10 ; Initialize counter for
10 elements (CX)

MOV AX, 0 ; Initialize sum


accumulator (AX)

MOV SI, @DATA_START ; Set memory pointer to


data start (SI)

SUM_LOOP:
MOV AL, [SI] ; Load current byte into
AL

TEST AL, 1 ; Check if least


significant bit is set (odd)

JNZ NOT_EVEN ; Jump if not even

ADD AX, AL ; Add even value to sum


(AX)

NOT_EVEN:
INC SI ; Increment memory pointer
(SI)

LOOP SUM_LOOP ; Loop 10 times to check


all elements

; After loop, AX holds the sum of even numbers


; (Optional: You can display the sum here)

MOV AH, 4CH ; AH = 4Ch for DOS exit function


INT 21h ; Terminate program

CODE_SEGMENT ENDS

END START ; Program entry point

Explanation:

1. The program defines a data segment with space for 10 bytes (8-bit values) and a word
(16-bit) variable to store the sum.
2. In the code segment, it initializes a counter for the loop, an accumulator for the sum, and
a memory pointer to the data start.
3. The loop iterates 10 times, checking each byte in the data series.
4. The TEST instruction checks the least significant bit (LSB) of the current byte. If the LSB
is 0 (even number), the ADD instruction adds the value to the sum accumulator (AX).

c) With reference to architecture of 8086 microprocessor write a program


to check whether a given number is odd or even and output either Even
number or Odd number 8 Marks

; Define data segment


DATA_SEGMENT SEGMENT
DATA_VAR DW ? ; Allocate space to store the number

DATA_SEGMENT ENDS

; Define code segment


CODE_SEGMENT SEGMENT ASSUME CS:CODE_SEGMENT
START:
MOV AX, @DATA_VAR ; Load the number into AX

CHECK_ODD:
TEST AL, 1 ; Check if least significant bit is set (odd)

Prepared by: Joseph Mwaura Njenga | 0717065073 | Best Wishes in your Exam

You might also like