Mpi 4,2 (1,2,3)
Mpi 4,2 (1,2,3)
4m
Sure, I can help with that. Here are the relevant answers to your questions:
- **Minimum Mode:**
- **Maximum Mode:**
2. The 8086 acts as a multi-processor system when used in maximum mode configuration, allowing
multiple processors to work together in a single system.
4. **Logical address** is the address generated by the CPU during program execution, which is
translated into a physical address by the memory management unit (MMU). Example: 16-bit address
generated by an x86 processor.
**Physical address** is the actual location in the memory where data is stored. Example: Memory
cell 0x1234.
5. Here's an example of an 8086 assembly language program to add two 8-bit numbers and store the
result:
```assembly
```
6. Segment registers in 8086 (CS, DS, SS, ES) are used to hold segment addresses, which are
combined with an offset to form a physical address. They facilitate memory segmentation in the x86
architecture.
7. The prefetch queue in 8086 holds the next instruction to be executed, fetched from memory in
advance. This prefetching helps improve instruction execution speed by reducing memory access
time.
8. The Instruction Pointer (IP) in 8086 holds the offset address of the next instruction to be executed.
It is essential for the processor to fetch the correct instructions in sequential order.
```assembly
```
```assembly
Store_Loop:
```
```
Flags affected: Carry Flag (CF), Auxiliary Carry Flag (AF), Zero Flag (ZF), Sign Flag (SF), Parity Flag
(PF), Overflow Flag (OF)
```
11. **Sequential flow instructions** execute instructions in the order they appear in the program,
while **control transfer instructions** alter the normal flow of execution by transferring control to a
different part of the program (e.g., jump, call, return instructions).
12. **MOV instruction** is used to transfer data between registers or between a register and
memory, while **XCHG instruction** exchanges the contents of two registers or a register and a
memory location.
13. **MUL instruction** performs unsigned multiplication, while **IMUL instruction** performs
signed multiplication in 8086.
14. **DIV instruction** performs unsigned division, while **IDIV instruction** performs signed
division in 8086.
```
```
```
2m
```
DAA ; Adjust AL after addition, no carry from lower nibble to upper nibble, so AL remains 7EH
AL = 7EH
```
```
POP AX ; Pops the top of the stack into AX, AX now contains 34H
POP G ; Pops the top of the stack into G, G now contains 20H
```
4. The direction flag (DF) in 8086 is used to control the direction of certain string instructions like REP
MOVSB, REP STOSB, etc. When DF = 0, these instructions process data from lower memory addresses
to higher memory addresses. When DF = 1, they process data in the reverse direction, from higher
addresses to lower addresses.
5. Output of the code:
```
AL = 00110101 (35H)
BL = 39H
AAS ; Adjust AL after subtraction, since AL is greater than 9 (in hexadecimal), AAS subtracts 6
from AL and adjusts the result, AL = FCH - 6 = F6H
AL = F6H
```
7. IDIV and DIV instructions perform division operations. IDIV is used for signed division (with signed
operands), while DIV is used for unsigned division (with unsigned operands). Here's an example
code:
```assembly
```
For IDIV, you would use signed values for AX and BX.
8. The opcode is a part of the instruction in machine language that specifies the operation to be
performed by the CPU. It is essential for decoding instructions and executing the corresponding
operations.
```
AL = 00110100 (34H)
BL = 00111000 (38H)
AAA ; Adjusts AL after addition, since AL > 9 (in decimal), AAA adds 6 to AL and adjusts, AL =
6CH + 6 = 72H
AL = 72H
```
11. ADC (Add with Carry) instruction is used to add two operands along with the value of the Carry
Flag (CF). It's used in arithmetic operations where a carry from a previous operation needs to be
considered.
12. The NEG instruction inverts the sign of a number. It is used to perform two's complement
negation, converting a positive number to negative and vice versa.
```
CX = 0EEFH
```
14. The NOT instruction inverts each bit of a binary number. It is used for bitwise complementation,
flipping 0s to 1s and vice versa.
- Status flags (also known as condition flags): CF, PF, AF, ZF, SF, OF
- POP: Pops data from the stack into a register or memory location
Unit-2
**Question 1:**
Consider the 8-bit data as 11000110 and assume the carry flag is 0. Perform two times rotate right
with carry and show the final result.
**Answer:**
Final result after two times rotate right with carry: 10110001
---
**Question 2:**
Consider the data is 11000111, assume the carry flag is 0. Perform two times shift arithmetic left and
show the final result.
**Answer:**
---
**Question 3:**
Define the role of the direction flag in MOVSB instruction in the 8086 processor.
**Answer:**
The direction flag (DF) in the 8086 processor determines the direction of string operations like
MOVSB. When DF is set (1), string operations decrement the SI and DI registers after each operation.
When DF is cleared (0), the registers are incremented. This flag allows for efficient processing of data
in memory, facilitating both forward and backward movement through memory locations.
---
**Question 4:**
State the use of REP & REPE instructions in the 8086 processor.
**Answer:**
- REP (Repeat) instruction is used to repeat string operations such as MOVSB, STOSB, etc., a specific
number of times specified by the CX register.
- REPE (Repeat if Equal) instruction is used in conjunction with string comparison instructions like
CMPSB to repeat the operation until a mismatch occurs or until the CX register becomes zero.
---
**Question 5:**
**Answer:**
- Unconditional branch instructions (e.g., JMP) always transfer control to a specified address without
any conditions.
- Conditional branch instructions (e.g., JZ, JNZ) transfer control to a specified address only if a certain
condition is met, such as the zero flag being set or cleared.
---
**Question 6:**
**Answer:**
- Jump (JMP) instruction transfers the control of the program unconditionally to a specified address.
- Call (CALL) instruction transfers control to a subroutine, but before doing so, it saves the return
address in the stack. After executing the subroutine, control returns to the instruction following the
call.
---
**Question 7:**
**Answer:**
- Software interrupts are initiated by software instructions (e.g., INT) to request services from the
operating system or to invoke specific routines.
- Hardware interrupts are initiated by external hardware devices to request attention from the CPU
for various events like I/O completion or timer expiry.
---
**Question 8:**
**Answer:**
```assembly
.model small
.stack 100h
.data
.code
main:
mov ah, 9
end main
```
This program displays "Hello, world!" using DOS interrupt 21h (function 09) and then terminates the
program using DOS interrupt 21h (function 4Ch).
---
**Question 9:**
a. Variables
b. Suffixes
c. Operators
**Answer:**
a. Variables: Variables are named memory locations used to store data during program execution.
They are identified by a unique name and can hold different types of data such as integers,
characters, or arrays. Example:
```assembly
message db 'Hello, world!', '$' ; Define a variable named message to store a string
```
b. Suffixes: Suffixes in assembly language indicate the size or type of data being used. They are
appended to data declarations or instructions to specify the size of the data. Examples:
```assembly
num1 dw 1234h ; Define a word (16-bit) variable num1 with initial value 1234h
value1 db 'A' ; Define a byte (8-bit) variable value1 with initial value 'A'
```
c. Operators: Operators in assembly language are symbols used to perform operations on data. They
include arithmetic operators (+, -, *, /), logical operators (AND, OR, XOR), comparison operators
(CMP), and bitwise operators (AND, OR, XOR). Examples:
```assembly
```
---
**Question 10:**
Explain CMPSB instruction with an example. Discuss how you can conclude that the two numbers
compared are equal, lesser, or greater.
**Answer:**
CMPSB (Compare String Byte) instruction is used to compare two bytes in memory. It compares the
byte at the address pointed to by the SI register with the byte at the address pointed to by the DI
register. The result of the comparison is reflected in the status flags.
Example:
```assembly
mov si, offset array1 ; Set SI to point to the first byte of array1
mov di, offset array2 ; Set DI to point to the first byte of array2
compare_loop:
equal:
less:
; Handle the case when the byte at [SI] is less than the byte at [DI]
greater:
; Handle the case when the byte at [SI] is greater than the byte at [DI]
```
In the above example, if the byte at [SI] is equal to the byte at [DI], the zero flag (ZF) will be set after
the CMPSB instruction (je equal). If the byte at [SI] is less than the byte at [DI], the carry flag (CF) will
be set (jb less). If the byte at [SI] is greater than the byte at [DI], the zero flag (ZF) will be cleared, and
the carry flag (CF) will be cleared (jg greater).
---
**Question 11:**
State the advantage of Assembly level language over Machine level language discuss about the role
of assembler directives in achieving these advantages in short.
**Answer:**
---
**Question 12:**
State the advantage of assembly level language over machine level language discuss about the role
of assembler directives in achieving these advantages in short.
**Answer:**
Apologies for the repetition in the question. Please refer to the answer provided for Question 11.
---
**Question 13:**
**Answer:**
```assembly
.model small
.stack 100h
.data
sum dw ?
.code
main:
add_loop:
end main
```
This program calculates the sum of multiple numbers stored in an array. It initializes the sum to 0 and
then iterates over each element in the array, adding it to the sum. Finally, it displays the sum.
---
**Question 14:**
```assembly
.model small
.stack 100h
.data
num1 dw 1234h
num2 dw 5678h
.data
sum dw ?
.code
main:
; At this point, sum contains the total sum of num1 and num2
end main
```
This program calculates the sum of two multi-byte numbers and stores the result in a variable called
sum.
---
**Question 15:**
How can you check if an 8-bit number is even or odd using appropriate 8086 assembly language
instructions?
**Answer:**
You can check if an 8-bit number is even or odd by examining the least significant bit (LSB) of the
number. If the LSB is 0, the number is even; if it is 1, the number is odd. Here's how you can do it in
assembly language:
```assembly
jmp end
even:
end:
```
---
**Question
16:**
What are the sequence of instructions that can be used to perform addition of two BCD numbers in
8086 processor so that the results must be in BCD?
**Answer:**
To perform addition of two BCD (Binary Coded Decimal) numbers in 8086 processor so that the result
must be in BCD, you can follow these steps:
Example:
```assembly
jc carry_detected
; No carry, continue
carry_detected:
```
2 marks
**Question 1:**
"What will be the content of reg AX after execution of the following program. Assume CF=1.
```
SAR AH, 02
SHL AL, 02
SHR AL, 03
HLT
```
**Answer:**
Given:
- CF = 1 (Assumption)
- AH = 0FH
- AL = FFH
Execution steps:
---
**Question 2:**
In 8086 Processor, the content of the accumulator and the carry flag are A7 and 0 (in hex). if the RLC
instruction is executed, then the content of the accumulator (in hex) and the carry flag, respectively
will be______.
**Answer:**
RLC (Rotate Left through Carry) instruction rotates the bits of the accumulator to the left through the
carry flag. After execution:
- Carry flag: 1
---
**Question 3:**
While performing any of the MOV instructions over Strings, i.e. MOVSB, MOBSW, or MOVSD, by
default, what is the source and destination?
**Answer:**
---
**Question 4:**
```
MOV AX,0200H
MOV DS,AX
MOV AX,0300H
MOV ES,AX
MOV DS:[0000],52H
MOV DS:[0001],74H
MOV DS:[0002],8AH
MOVSB
MOVSB
MOVSB
HLT
```
**Answer:**
This program copies three bytes from the DS segment to the ES segment using MOVSB instruction.
---
**Question 5:**
```
MOV AX,01234H
MOV BX,01233H
XOR AX,BX
JZ ABC
MOV CX,01234H
HLT
HLT
```
**Answer:**
Given:
- AX = 01234H
- BX = 01233H
XOR AX, BX results in AX = 00001H. Since AX is not zero, the JZ instruction doesn't jump. Hence, the
next instruction MOV CX, 01234H is executed, loading CX with 01234H. The program then halts. So,
the output is CX = 01234H.
---
**Question 6:**
**Answer:**
---
**Question 7:**
What name is given to a special software routine to which control is passed when an interrupt
occurs?
**Answer:**
The special software routine to which control is passed when an interrupt occurs is called an
Interrupt Service Routine (ISR) or Interrupt Handler.
---
**Question 8:**
What will be the hexadecimal value in the register AX (32-bits) after executing the following
instructions?
```
MOV AL,15
MOV AH,15
XOR AL,AL
MOV CL,03
SHR AX,CL
```
**Answer:**
Given:
- AL = 15 (in hex)
- AH = 15 (in hex)
After SHR AX, CL, AX is right shifted by 3 bits. So, AX = 00001500 (in hex).
---
**Question 9:**
In 8086 microprocessor ________ has the highest priority among all type interrupts?
**Answer:**
In the 8086 microprocessor, Non-Maskable Interrupt (NMI) has the highest priority among all types
of interrupts.
---
**Question 10:**
How many times the instruction sequence below will loop before coming out of the loop?
```
INC AL
JNZ A1
```
**Answer:**
The instruction sequence will loop 256 times because AL is initially set to 00H, and INC AL increments
it by 1. When AL reaches FFH, the next increment will make it 00H again, and the loop continues. So,
the loop iterates through all possible values of AL, resulting in 256 iterations.
---
**Question 11:**
A certain microprocessor requires 4.5 microseconds to respond to an interrupt. Assuming that the
three interrupts I1, I2, I3 requires the following execution time after the interrupt is recognized:
i. I1 requires 25 microseconds
To determine the possible range of time for I3 to be executed, considering that it may or may not
occur simultaneously with other interrupts, let's analyze the scenario:
Given:
i. I1 requires 25 microseconds
Thus, the possible range of time for I3 to be executed is between 24.5 microseconds and 39.5
microseconds, assuming it may or may not occur simultaneously with other interrupts.
12)I1 has the highest priority and I3 has the lowest. What is the possible range of time for I3 to be
executed assuming it may or may not occur simultaneously with other interrupts?
If I1 has the highest priority and I3 has the lowest priority, let's consider the possible scenarios for
the execution of I3:
Given:
i. I1 requires 25 microseconds
Since I3 has the lowest priority, it can only occur after the other interrupts have been processed.
Therefore, the possible range of time for I3 to be executed is between 29.5 microseconds and 39.5
microseconds, assuming it may or may not occur simultaneously with other interrupts.
**Question 13:**
iii. SCAS 3) compares two strings of bytes or words whose length is stored in CX register
**Answer:**
ii
. CMPS - 3) compares two strings of bytes or words whose length is stored in CX register
---
**Question 14:**
Which instruction cannot force the 8086 processor out of ‘halt’ state?
**Answer:**
The instruction that cannot force the 8086 processor out of the 'halt' state is the NOP (No Operation)
instruction.
---
**Question 15:**
**Answer:**
The LOCK prefix is used in multiprocessor environments to ensure that certain instructions are
executed atomically. When a LOCK prefix is used with an instruction, it ensures that no other
processor can access the memory while the instruction is being executed. This is often used in critical
sections of code where multiple processors might try to access shared resources simultaneously.
---
**Question 16:**
```
MOV AL, 09
MOV AH, 08
ADD AL, AH
DAA
HLT
```
**Answer:**
Given:
- AL = 09 (in hex)
- AH = 08 (in hex)
After ADD AL, AH, AL becomes 11 (in hex). DAA (Decimal Adjust AL after Addition) adjusts AL to
represent the correct decimal result. In this case, since AL = 11 (in hex), no adjustment is needed. So,
after DAA, AL remains 11 (in hex).
UNIT-3A
4m
1. The total cycles required to execute a program using counters can vary depending on the specific
operations and instructions involved in the program. Generally, you would need to analyze the
individual instructions in the program and their corresponding cycle counts, then sum up the cycles
for each instruction to get the total cycle count for the program.
2. Generating a delay when a multiplier count is included involves utilizing a counter or a timer to
count a certain number of clock cycles or time intervals, effectively creating a delay. This delay can be
achieved by repeatedly decrementing the counter until it reaches zero, indicating the desired delay
duration has elapsed.
3. Here's a simple flowchart to illustrate how to find the ASCII equivalent of a number less than 100:
```
Start
Input Number
No --> End
Yes
Output ASCII
|
End
```
4. Converting the number 7CH to ASCII involves dividing the binary representation of 7CH (0111
1100) into groups of 4 bits each, then converting each group to its corresponding hexadecimal ASCII
value. The binary-to-ASCII conversion table is used for this purpose.
5. Here's a snippet of 8086 assembly code to convert a two-digit ASCII coded decimal to
hexadecimal:
```assembly
MUL BL ; Multiply AL by BL
DIV BL ; Divide AX by BL
```
6. To convert a three-digit decimal number to hexadecimal, you can repeatedly divide the number by
16 and store the remainders. The remainders will represent the hexadecimal digits in reverse order.
Then, you reverse the order of the remainders to get the hexadecimal equivalent.
7. To check whether a given input is a letter or a number and convert it into a hexadecimal number,
you would need to examine each character of the input string. For each character, you can check if it
falls within the ASCII range for letters or numbers. Then, convert the character to its hexadecimal
equivalent.
8. A simple program to read input from the keyboard and display it on the monitor would involve
using appropriate input and output instructions provided by the assembly language or programming
environment being used.
9. To find the LCM of two numbers and display the result in hexadecimal, you can first calculate the
LCM using standard algorithms, then convert the result to hexadecimal.
10. Here's a flowchart illustrating how to display a 4-digit hexadecimal number:
```
Start
End
```
11. Different techniques for data conversion using lookup tables include direct indexing,
interpolation, and hashing.
12. BCD to 7-segment code conversion involves mapping each BCD digit to its corresponding 7-
segment display pattern. Accessing ASCII data in lookup tables typically involves indexing the table
with the ASCII value of the character to retrieve the corresponding data.
13. Procedures and macros serve similar purposes in programming, but they have some key
differences. Procedures are reusable blocks of code that are defined separately from the main
program and can be called multiple times. Macros, on the other hand, are preprocessor directives
that are expanded inline during compilation.
14. Instructions used in procedures typically include function calls, parameter passing, local variable
manipulation, and return statements.
15. A macro consists of a sequence of instructions or statements that are defined using a macro
definition. Here's an example:
```assembly
; Macro definition
MACRO AddNumbers x, y
MOV AX, x
ADD AX, y
ENDM
AddNumbers 10, 20
```
16. Macros are efficient compared to procedures in certain situations because they eliminate the
overhead of function call and return, as macros are expanded inline during compilation. However,
macros can lead to code bloat and may be harder to debug compared to procedures.
2M:
Since your questions are related to assembly language programming and microprocessor
architecture, I'll address each one accordingly:
1. The time required for one clock cycle can be calculated using the formula:
Given the operating system frequency of 8086 system is 10 MHz, the time required for one clock
cycle would be:
2. Here's an assembly language program to generate a delay of 500 msec on an 8086 system with a
frequency of 10 MHz:
```assembly
DELAY_500MSEC:
DELAY_LOOP:
DEC CX ; Decrement CX
RET ; Return
```
3. The ASCII equivalent of the number 0059H in AX register is '9'. Since the ASCII value of '9' is 39h,
the ASCII equivalent of 0059H would also be 39h.
4. AAM (ASCII Adjust for Multiplication) instruction is used to adjust the result of a binary
multiplication operation in AX register to unpacked BCD (Binary Coded Decimal) format. AAD (ASCII
Adjust for Division) instruction is used to adjust the dividend before performing a binary division
operation when the dividend is in unpacked BCD format.
5. Here's a code snippet to convert the ASCII form of the decimal number 48 (AH = 34h, AL = 38h) to
an 8-bit hexadecimal number and store the result in BL register:
```assembly
MOV AH, 34h ; Load ASCII high nibble into AH
```
6. Here's a code snippet to convert the two-digit packed BCD number 45h to ASCII and store the
result in AH:AL:
```assembly
```
7. Writing a program to read input from the keyboard and display it on the monitor involves using
appropriate input and output instructions provided by the assembly language or programming
environment being used.
8. Data need to be converted in the 8086 microprocessor for various reasons, including ensuring
compatibility between different data formats, facilitating arithmetic and logical operations, and
enabling proper interpretation by the CPU and other components of the system.
9. A near procedure is a subroutine that resides within the same code segment as the calling code,
allowing for efficient and fast execution. A far procedure, on the other hand, resides in a different
code segment and may require additional overhead for segment loading and switching.
10. The delay generated by an inner loop with the maximum count (FFFFH) would depend on the
instructions executed within the loop and the frequency of the microprocessor. Each iteration of the
loop would consume a certain amount of time, determined by the execution time of the instructions
within the loop.
11. Look-up tables can be stored in any available segment of memory, including code segment, data
segment, or even in separate segments allocated specifically for storing tables.
12. To modify the XLAT instruction to access a byte from the code segment, you would need to load
the segment address of the code segment into the DS (Data Segment) register using appropriate
instructions before executing the XLAT instruction.
13. Data or address variables can be passed in procedures in various ways, including passing them as
function arguments, accessing them through global variables, or storing them in memory locations
accessible to both the calling code and the procedure.
14. Writing a program to pass parameters in a macro involves defining the macro with parameters
and then invoking the macro with specific values for those parameters. Here's an example:
```assembly
ENDM
```
15. Macro expansion involves replacing the macro invocation in the code with the actual code
defined in the macro, along with the provided parameter values. Here's an example of macro
expansion:
```assembly
; Macro definition
ENDM
; Macro invocation
MY_MACRO 10, 20
; Macro expansion
MOV AX, 10
ADD AX, 20
```
16. Parameters are passed to a macro by specifying them within the macro invocation. The macro
definition includes placeholders for parameters, which are then replaced by the actual values
provided during macro invocation.