0% found this document useful (0 votes)
33 views15 pages

ANSWERS 2 Microprocessor & Assembly Language Programming Year III Semester II

Revision
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
33 views15 pages

ANSWERS 2 Microprocessor & Assembly Language Programming Year III Semester II

Revision
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 15

Kirinyaga University

UNIVERSITY EXAMINATIONS 2020/2021

EXAMINATION FOR DEGREE OF BACHELOR OF SCIENCE IN COMPUTER


SCIENCE

SPC 2312 Microprocessor & Assembly Language Programming Year III Semester II

Date: Friday 17th June, 2022 Time: 8.30 am – 10.30 am Section (30 Marks)
Question One (30)
a) Explain why data transfer instructions are important 4 Marks

Data transfer instructions are fundamental operations in any microprocessor. They are
crucial for:

1. Moving data between registers and memory locations: This allows the
processor to load data from memory into registers for processing and store
results back to memory.
2. Communication with peripheral devices: Data transfer instructions enable
the processor to send data to devices (like sending commands to a printer) or
receive data from devices (like reading data from a keyboard).
3. Performing arithmetic and logical operations: Many arithmetic and logical
instructions (like addition, subtraction, AND, OR) inherently involve transferring
data between registers during the operation.

Without efficient data transfer instructions, a microprocessor wouldn't be able to


perform its core functionalities and interact with other components within the computer
system.

b) Describe the following terms as used in microprocessors 4 Marks

i) Interrupt Latency:

Interrupt latency refers to the time delay between the assertion of an interrupt request
by a device and the moment the processor starts servicing the interrupt. This delay
can be influenced by factors like:

● Current processor workload: If the processor is busy executing a complex


task, the interrupt handling might be delayed.
● Interrupt priority scheme: Higher priority interrupts will be serviced before
lower priority ones, potentially increasing latency for lower priority requests.
● Hardware design: The architecture of the microprocessor and the interrupt
handling mechanism can impact the overall latency.
ii) Direct Memory Access (DMA):

Direct Memory Access (DMA) is a technique that allows certain devices (like disk
controllers, network cards) to transfer data directly between their memory and the
system's main memory without involving the processor at every step. This offloads
data transfer tasks from the processor, improving overall system performance,
especially for high-bandwidth data transfers.

c) Outline Four functions of an assembler 4 Marks

An assembler performs several key functions:

1. Translates assembly language instructions into machine code: The


assembler reads assembly language instructions written by programmers and
converts them into the binary opcodes (machine code) that the microprocessor
understands.
2. Allocates memory for variables and data: The assembler assigns memory
locations within the program's address space for variables and data declared in
the assembly code.
3. Resolves symbolic references: Assembly code often uses symbolic labels to
reference memory locations or instructions. The assembler resolves these
symbols to their actual memory addresses during the assembly process.
4. Performs error checking: The assembler can identify syntax errors or
semantic errors within the assembly code, helping programmers write correct
and functional code.

d) Describe Three functions of buffering as applied in peripheral interfacing 6 Marks

Buffering plays a significant role in peripheral interfacing:

1. Data Rate Matching: Peripheral devices may have different data transfer rates
compared to the processor. Buffers can temporarily store data from a faster
device or provide data to a slower device, smoothing out these differences and
ensuring smooth communication.
2. Synchronization: Buffers can help synchronize data flow between the
processor and peripherals. The processor can write data to a buffer without
waiting for the device to be ready, and the device can read data from the buffer
at its own pace.
3. Reduced CPU Load: By handling data transfer asynchronously using buffers,
the processor can focus on other tasks while data is being transferred between
the device and memory.
4. Error Handling: Buffers can be used to store data during error recovery
situations. For example, if a transmission error occurs, the data can be
re-transmitted from the buffer.

e) Explain the following instructions 4 Marks

i) MOV CX, CS

This instruction is illegal in most microprocessor architectures. The CS register


typically holds the current code segment address, which is a read-only register.
Attempting to modify it directly using MOV can lead to unexpected behavior or program
crashes.

ii) MOV AX, [ALPHA]

This instruction assumes ALPHA is a symbolic label representing a memory location.


The instruction loads the value from the memory location pointed to by ALPHA into
register AX. The size of the data being loaded depends on the specific instruction
used (e.g., MOV for byte, MOVZX for zero-extending a byte to a word, etc.).

f) Discus two advantages of handshaking method of interfacing 4 Marks

The handshaking method of interfacing provides two key advantages:

1. Reliable Data Transfer: Both the processor and the peripheral device can
explicitly signal their readiness to send or receive data. This ensures that data
isn't sent or received when the other party is not prepared, preventing data
corruption or loss.
2. Error Detection: Handshake protocols often include mechanisms for error
detection. If a transmission error occurs, the devices can signal the error and
potentially re-send the data, improving data integrity.

g) Explain any Two factors that affect characteristics and performance of a bus in a
microprocessor system 4 Marks

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


microprocessor system:

1. Bus Width: The bus width determines the number of bits that can be
transferred simultaneously on the bus. A wider bus allows for faster data
transfer compared to a narrower bus (assuming the same clock speed).
2. Bus Speed: The bus speed, measured in MHz (MegaHertz), indicates the
number of cycles the bus can perform per second. A higher bus speed
translates to faster data transfer rates.
3. Bus Multiplexing: Some buses may use multiplexing techniques to transmit
different types of signals (address, data, control) on the same physical wires at
different times. This can improve efficiency but adds complexity to the bus
design.
4. Signaling Method: Buses can use different signaling methods, such as
single-ended or differential signaling. Differential signaling offers better noise
immunity, which can be crucial for reliable data transmission at high speeds.
5. Bus Topology: The physical layout of the bus connections (e.g., point-to-point,
multi-drop) can impact performance and scalability. Point-to-point connections
offer dedicated bandwidth between devices but may not be suitable for large
systems. Multi-drop connections allow for more devices but require arbitration
mechanisms to avoid data collisions.

By carefully considering these factors, designers can select or create a bus


architecture that meets the specific performance requirements of the microprocessor
system.

Section B (40 Marks)


Answer any two questions from this section
Question Two (20 Marks)
a) Explain three Difference Between Linker and Loader 6 Marks
b) Differentiate between Cyclic Stealing and Interleaved mode of data transfer in
DMA 4 Marks

i) Cyclic Stealing:

● In cyclic stealing, the DMA controller steals a fixed number of bus cycles from
the processor at regular intervals (e.g., every few processor cycles).
● This allows for a steady flow of data transfer between the device and memory
without significantly interrupting the processor.
● However, cyclic stealing can introduce some overhead due to the constant
context switching between the processor and DMA controller.

ii) Interleaved Mode:

● In interleaved mode, the DMA controller steals bus cycles on an opportunistic


basis, transferring data whenever the processor doesn't require the bus.
● This approach can potentially improve transfer efficiency compared to cyclic
stealing, especially if the processor has idle bus cycles.
● However, interleaved mode can make it more difficult to predict the timing of
data transfers, which might be an issue for real-time applications with strict
timing requirements.

c) Outline four advantages of microprocessors 4 Marks

Microprocessors offer several advantages over traditional computer architectures


based on central processing units (CPUs):

1. Increased Integration: Microprocessors integrate various functionalities


(processing unit, memory controller, I/O interfaces) onto a single chip. This
reduces complexity, size, and power consumption compared to multi-chip CPU
designs.
2. Lower Cost: Due to the high level of integration and mass production,
microprocessors are generally more cost-effective than traditional CPU
architectures.
3. Scalability and Performance: Microprocessor architectures can be scaled by
increasing clock speeds, adding cores (multi-core processors), or using
specialized instruction sets to improve performance for specific tasks.
4. Versatility: Microprocessors can be tailored for various applications by
incorporating specialized features or instruction sets, making them suitable for
a wide range of devices beyond traditional computers.
d) Write a program to add a data byte located at offset 0500H in 2000H segment to
another data byte available at 0600H in the same segment and store the result at
0700H in the same segment. 6 Marks
MOV AX, @0000H:2000H ; Load data byte from 2000:0500H into AX
ADD AX, @0000H:2000H ; Add data byte from 2000:0600H to AX
MOV @0000H:2000H, AX ; Store the result in 2000:0700H

; (Optional: You can terminate the program here)


MOV AH, 4CH ; AH = 4Ch for DOS exit function
INT 21h ; Terminate program

Explanation:

1. The first MOV instruction loads the data byte located at offset 0500H within
segment 2000H into register AX.
2. The second MOV instruction (with the ADD opcode) adds the data byte located
at offset 0600H within segment 2000H to the value already present in AX (the
first data byte).
3. The final MOV instruction stores the result (sum) from AX back to memory
location 2000:0700H.

(Optional): The additional lines provide a way to terminate the program using the
DOS function for exiting.

Question Three (20 Marks)


a) Explain any three Functions of Buses in Computers 6 Marks

Buses play a critical role in data transfer within a computer system. Here are three key
functions of buses:

1. Data Transfer: Buses provide a pathway for transferring data between various
components within a computer, such as the processor, memory, and peripheral
devices. The width of the bus determines the number of bits that can be
transferred simultaneously, impacting data transfer speed.
2. Address Lines: Buses also carry address signals that specify the source or
destination of the data being transferred. These address lines allow the
processor to locate specific memory locations or devices on the bus.
3. Control Signals: Control signals travel on the bus to coordinate data transfer
operations. These signals indicate whether the operation is a read or write,
synchronize the transfer process, and manage arbitration when multiple
devices attempt to use the bus simultaneously.
b) Use a block diagram to describe the input-output interface system of a
microprocessor system 6 Marks

) Write an assembly language program for calculating the factorial of a number


using 8086 microprocessor 8 Marks
; Define data segment
DATA_SEGMENT SEGMENT
NUMBER DW ? ; Allocate space to store the number
RESULT DW 1 ; Allocate space to store the factorial (initialized to 1)

DATA_SEGMENT ENDS

; Define code segment


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

; Check for negative or zero


CMP AX, 0
JL INVALID_INPUT ; Jump if less than 0 (invalid)
JE FACTORIAL_DONE ; Jump if zero (factorial is 1)

MOV CX, AX ; Initialize loop counter (CX) with the number

FACTORIAL_LOOP:
LOOP FACTORIAL_LOOP ; Decrement CX and loop if not zero
MUL AX, CX ; Multiply the result by the loop counter

FACTORIAL_DONE:
MOV @RESULT, AX ; Store the factorial in memory

; (Optional: Handle invalid input and program termination)

INVALID_INPUT:
; Handle invalid input error (e.g., display message)

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 to store the number and the
calculated factorial.
2. In the code segment, it loads the number from memory into register AX.
3. It checks if the number is negative or zero. If negative, it jumps to an error
handling section (optional). If zero, the factorial is already 1, so it jumps to the
result storage section.
4. Otherwise, it moves the number to the loop counter (CX).
5. The LOOP instruction decrements CX and jumps back to FACTORIAL_LOOP as
long as CX is not zero.
6. Inside the loop, the MUL instruction multiplies the current result in AX by the
loop counter (current number).

Question Four (20 Marks)

a) Explain Three important design issues that must be considered while designing
an instruction set 6 Marks

1. Instruction Set Size (RISC vs. CISC):


○ Reduced Instruction Set Computing (RISC): Utilizes a small set of
simple instructions that can be executed quickly. Benefits include
efficient hardware design and faster execution for frequently used
operations. However, complex tasks may require more instructions.
○ Complex Instruction Set Computing (CISC): Offers a wider range of
instructions, including complex ones that can perform multiple
operations in a single instruction. This can be more concise for specific
tasks but may lead to slower execution due to hardware complexity. The
choice depends on the target application and desired balance between
simplicity and instruction power.
2. Addressing Modes:
○ Addressing modes determine how operands (data) are accessed within
an instruction. A well-designed instruction set offers a variety of
addressing modes (e.g., register direct, immediate, indirect) to provide
flexibility for programmers and optimize memory access patterns.
3. Instruction Encoding:
○ The way instructions are encoded into binary code impacts code size
and execution speed. A balance is needed between instruction size
(fewer bits) and ease of decoding for the processor. Additionally,
instruction encoding can influence instruction set orthogonality, meaning
instructions should ideally use consistent opcodes and operand formats
for similar operations.

b) Explain the following assembly program 8 Marks


MEMORY ADDRESS MNEMONICS COMMENT
● 400-405: Initialize registers and pointers
○ MOV SI, 500: Set the memory pointer (SI) to the starting address
(500H).
○ MOV CL, [SI]: Load the first byte from memory (pointed to by SI) into
the counter register (CL).
○ INC SI: Increment the memory pointer (SI) to point to the next byte.
● 406-408: Set accumulator and carry flag
○ MOV CH, 00: Set the carry flag (CH) to 0 (cleared).
○ MOV AL, 00: Set the accumulator (AL) to 0 (initialize the sum).
● 40A-414: Loop to process bytes and sum even values
○ MOV BL, [SI]: Load the next byte from memory into BL.
○ TEST BL, 01: Check the least significant bit (LSB) of BL for 0 (even
number).
○ JNZ 413: Jump to instruction at 413H if the LSB is not zero (odd
number, skip addition).
○ ADD AL, BL: Add the current byte value (BL) to the accumulator (AL),
accumulating the sum of even numbers.
○ INC SI: Increment the memory pointer (SI) to point to the next byte.
○ LOOP 40A: Decrement the counter (CL) and loop back to instruction at
40AH if CL is not zero (repeat for remaining bytes).
● 416: Store the final sum at address 600H
○ MOV [600], AL: Move the value in the accumulator (AL), which holds
the sum, to memory location 600H.
● 41A: Halt the program
○ HLT: Stop program execution.

c) Describe the two main types of flags of 8086 microprocessor giving two
examples in each category 6 Marks

The 8086 microprocessor has two main categories of flags:

1. Status Flags (6 bits):

● Zero Flag (ZF): Set to 1 if the result of the last arithmetic or logical operation is
zero. (Example: MOV AL, 5; SUB AL, 5 sets ZF)
● Carry Flag (CF): Set to 1 if an arithmetic operation overflows or underflows
(carrying a bit into or out of the register). (Example: MOV AL, 255; ADD AL,
1 sets CF)
● Parity Flag (PF): Set to 1 if the result of the last operation has an even number
of 1 bits (even parity). (Example: MOV AL, 0101 sets PF)
● Auxiliary Carry Flag (AF): Set to 1 if a carry occurs between bit 3 and bit 4
during an addition or subtraction involving BCD (Binary-Coded Decimal)
numbers.
● Sign Flag (SF): Set to the sign bit (bit 7) of the result

Question Five (20 Marks)

a) Describe two functional components of a microcontroller 6 Marks

Microcontrollers are tiny computers on a single chip, but they still require some
essential components for operation:

1. Central Processing Unit (CPU):


○ The CPU is the brain of the microcontroller, responsible for fetching,
decoding, and executing instructions. It performs arithmetic, logical, and
control operations.
2. Memory:
○ Microcontrollers have two main types of memory:
■ Program Memory (ROM, Flash): Stores the program
instructions that the CPU executes.
■ Data Memory (RAM): Stores temporary data used during
program execution and variable values.

These two components form the core functionality of a microcontroller. Additional


components may be present depending on the specific microcontroller, such as:

● Input/Output (I/O) peripherals for interacting with external devices (e.g., timers,
analog-to-digital converters, communication interfaces).
● Clock oscillator to provide timing signals for the CPU and other components.

b) Differentiate between RISC and CISC type of microprocessors 6 Marks


Reduced Instruction Set Computing (RISC):

● Utilizes a small set of simple instructions that can be executed quickly.


● Advantages:
○ Efficient hardware design
○ Faster execution for frequently used operations
● Disadvantages:
○ May require more instructions for complex tasks
○ May require additional registers for temporary storage

Complex Instruction Set Computing (CISC):

● Offers a wider range of instructions, including complex ones that can perform
multiple operations in a single instruction.
● Advantages:
○ More concise code for specific tasks
● Disadvantages:
○ Slower execution due to hardware complexity
○ Less consistent instruction formats

Choosing between RISC and CISC depends on the application:

● RISC: Ideal for tasks that emphasize speed and efficiency (e.g., embedded
systems, mobile devices).
● CISC: More suitable for scenarios where code size is a primary concern or
complex operations are frequently used.

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


two constants and displays the result 8 Marks

; Define data segment

DATA_SEGMENT SEGMENT
FACTOR1 DW 5 ; First constant (replace with actual value)

FACTOR2 DW 3 ; Second constant (replace with actual value)

RESULT DW 0 ; Store the multiplication result

DATA_SEGMENT ENDS

; Define code segment

CODE_SEGMENT SEGMENT ASSUME CS:CODE_SEGMENT

START:

MOV AX, @FACTOR1 ; Load first factor into AX

; Multiplication (consider overflow for large constants)

MUL @FACTOR2 ; Multiply AX by second factor (stored in memory)

MOV @RESULT, AX ; Store the result in memory

; Display the result using DOS function (optional)

MOV AH, 9 ; AH = 9 for DOS print string function


MOV DX, OFFSET MSG ; Set pointer to message string

INT 21h ; Print the message string

MOV DX, OFFSET RESULT ; Set pointer to result data

MOV DL, 2 ; Print two digits (can be adjusted based on result size)

INT 21h ; Print the result as a decimal number (unsigned)

; (Optional: Program termination)

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

INT 21h ; Terminate program

MSG DB "Result: $" ; Message string to display before the result

CODE_SEGMENT ENDS

END START ; Program entry point

Explanation:
1. The program defines data for the two factors and the result.
2. In the code segment, it loads the first factor into register AX.
3. The MUL instruction multiplies AX by the second factor, whose address is
provided. (For large constants, overflow handling might be needed)
4. The result is stored back in memory at the RESULT location.

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

You might also like