0% found this document useful (0 votes)
20 views34 pages

Mpi 4,2 (1,2,3)

Uploaded by

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

Mpi 4,2 (1,2,3)

Uploaded by

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

Unit-1

4m

Sure, I can help with that. Here are the relevant answers to your questions:

1. Differences between minimum mode and maximum mode of 8086 microprocessor:

- **Minimum Mode:**

- Involves a single microprocessor in a system.

- The microprocessor generates the control signals for bus operation.

- Uses a 74LS273 latch for address bus multiplexing.

- Generally used in systems with only one processor.

- **Maximum Mode:**

- Supports multiple processors in a system.

- Requires an 8288 bus controller to generate bus control signals.

- Utilizes a 74LS245 transceiver for address bus multiplexing.

- Suitable for systems with more than one processor.

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.

3. Effective addresses (physical addresses) for the given instructions:

i) MOV CX, [5000h] - Effective address: 5000h

ii) MOV AX, [BX] - Effective address: 2000h (Contents of BX register)

iii) MOV AX, [BX+SI] - Effective address: 5000h (2000h + 3000h)

iv) MOV AX, 50[BX] - Effective address: 2050h (2000h + 50h)

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

MOV AX, 0200h ; Load first number from offset 0200h

ADD AX, 0400h ; Add second number from offset 0400h

MOV [0500h], AX ; Store the result at offset 0500h

```

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.

9. Program to store the value 05h at five consecutive memory locations:

i) Using direct addressing mode:

```assembly

MOV [2000h], 05h

MOV [2001h], 05h

MOV [2002h], 05h

MOV [2003h], 05h

MOV [2004h], 05h

```

ii) Using register indirect addressing mode:

```assembly

MOV CX, 5 ; Number of iterations

Store_Loop:

MOV [BX], 05h ; Stor e 05h at memory location pointed by BX


INC BX ; Increment BX to point to the next memory location

LOOP Store_Loop ; Loop until CX becomes zero

```

10. Addition of DCh and DEh in 8086:

```

DCh + DEh = 1CAh

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.

15. Result of AND operation between AL=58h and BL=34h:

```

AL = 58h AND 34h = 18h

```

16. Result of XOR operation between AL=58h and BL=34h:

```

AL = 58h XOR 34h = 6Ch


```

2m

Here are the relevant answers to your questions:

1. Value of AL after executing the instructions:

```

MOV AL, 35H ; AL = 35H

ADD AL, 49H ; AL = 7EH (35H + 49H = 7EH)

DAA ; Adjust AL after addition, no carry from lower nibble to upper nibble, so AL remains 7EH

AL = 7EH

```

2. Value stored in G after executing the instructions:

```

PUSH AX ; Pushes the value of AX (20H) onto the stack

PUSH BX ; Pushes the value of BX (34H) onto the stack

POP AX ; Pops the top of the stack into AX, AX now contains 34H

ADD AX, BX ; Adds AX (34H) and BX (34H), AX = 68H

POP G ; Pops the top of the stack into G, G now contains 20H

```

3. Matching of Addressing modes with Instructions:

a) Register indirect addressing mode - 4. MOV BX,[BP]"

b) Indexed addressing mode - 3. MOV CL,[BX+05H]

c) Direct addressing mode - 1. MOV BX,[SI+1528H]

d) Base addressing mode - 2. ADD BL,[0103]

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

SUB AL, BL ; AL = AL - BL = 35H - 39H = FCH

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

```

6. Effective addresses for different addressing modes:

- MOV AX, [5000H] - Effective address: 5000H

- MOV AX, 5000H[BX][SI] - Effective address: 5000H + 2000H + 3000H = A000H

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

MOV AX, 1000H ; Dividend

MOV BX, 20H ; Divisor

DIV BX ; AX = AX / BX (unsigned division)

```

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.

9. Matching for addressing modes:

- X: Indirect addressing - 2: pointers

- Y: Immediate addressing - 3: constants

- Z: Auto decrement addressing - 1: Loops


10. Output of the code:

```

AL = 00110100 (34H)

BL = 00111000 (38H)

ADD AL, BL ; AL = AL + BL = 34H + 38H = 6CH

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.

13. Result of CX register after executing the code:

```

MOV AX, 45A8H ; AX = 45A8H

MOV CX, 0E87H ; CX = 0E87H

OR CX, AX ; Bitwise OR operation, CX = CX OR AX = 0EEFH

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.

15. Two major categories of flags in 8086:

- Status flags (also known as condition flags): CF, PF, AF, ZF, SF, OF

- Control flags: DF (Direction Flag), IF (Interrupt Flag), TF (Trap Flag)

16. Data transfer instructions involving stack in 8086:


- PUSH: Pushes data onto the stack

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

For the given 8-bit data 11000110:

1. First rotate right with carry:

- Initial value: 11000110

- After rotate right with carry: 01100011 (CF = 0)

2. Second rotate right with carry:

- Initial value: 01100011

- After rotate right with carry: 10110001 (CF = 1)

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

For the given data 11000111:

1. First shift arithmetic left:

- Initial value: 11000111

- After shift arithmetic left: 10001110 (CF = 1)

2. Second shift arithmetic left:

- Initial value: 10001110


- After shift arithmetic left: 00011100 (CF = 1)

Final result after two times shift arithmetic left: 00011100

---

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

State the difference between unconditional and conditional branch instructions.

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

Describe the difference between jump and call instruction.

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

State the difference between software and hardware interrupts of 8086.

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

Write an 8086 assembly language program to demonstrate any software interrupt.

**Answer:**
```assembly

.model small

.stack 100h

.data

message db 'Hello, world!', '$'

.code

main:

mov ah, 9

mov dx, offset message

int 21h ; Invoke DOS interrupt to display message

mov ah, 4Ch

int 21h ; Invoke DOS interrupt to terminate program

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

Explain the following terms with examples:

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

count dw 10 ; Define a variable named count to store a 16-bit integer value

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

mov ax, bx ; Move the value of bx into ax

add ax, 10 ; Add 10 to the value in ax

cmp ax, bx ; Compare the values of ax and bx

```

---

**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

mov cx, 5 ; Repeat the comparison 5 times

compare_loop:

cmpsb ; Compare byte at [SI] with byte at [DI]

je equal ; Jump if equal

jb less ; Jump if less

jg greater ; Jump if greater

; Continue looping or perform other actions

equal:

; Handle the case when the bytes are equal

jmp compare_loop ; Continue looping

less:

; Handle the case when the byte at [SI] is less than the byte at [DI]

jmp compare_loop ; Continue looping

greater:

; Handle the case when the byte at [SI] is greater than the byte at [DI]

jmp compare_loop ; Continue looping

```

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

Assembly level language provides a more human-readable and understandable representation of


machine instructions compared to machine level language. Assembler directives facilitate the
process of writing assembly code by providing instructions to the assembler on how to process the
code. They help in defining data, organizing code, and controlling assembly process. This makes
programming in assembly language more efficient and less error-prone than directly working with
machine code.

---

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

Write an assembly language program to perform Multi-Number addition.

**Answer:**

```assembly

.model small

.stack 100h

.data

numbers db 10, 20, 30, 40, 50

count equ 5 ; Number of elements in the array


.data

sum dw ?

.code

main:

mov ax, 0 ; Initialize sum to 0

mov cx, count ; Set loop counter to number of elements

add_loop:

mov dl, numbers[si] ; Load number from array

add ax, dx ; Add number to sum

inc si ; Move to next element

loop add_loop ; Repeat for all elements

; At this point, sum contains the total sum of numbers

; Do whatever you want with the sum

mov ah, 4Ch

int 21h ; Terminate program

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

Write an Assembly language program to perform Multi-byte number addition.


**Answer:**

```assembly

.model small

.stack 100h

.data

num1 dw 1234h

num2 dw 5678h

.data

sum dw ?

.code

main:

mov ax, num1 ; Load first number into ax

add ax, num2 ; Add second number to ax

mov sum, ax ; Store the result in sum

; At this point, sum contains the total sum of num1 and num2

; Do whatever you want with the sum

mov ah, 4Ch

int 21h ; Terminate program

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

mov al, 15 ; Example: Load the 8-bit number into al

test al, 1 ; Test the least significant bit

jz even ; Jump if zero (even)

; Odd number handling here

jmp end

even:

; Even number handling here

end:

; Continue with the rest of the program

```

---

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

1. Load the BCD numbers into registers or memory.

2. Add the two BCD numbers using ADD instruction.

3. Adjust the result to ensure it remains in BCD format.

4. Check for carry and adjust if necessary.

5. Continue with the rest of the program.

Example:

```assembly

mov al, bcd1

add al, bcd2

daa ; Decimal adjust after addition

; Check carry and adjust if necessary

jc carry_detected

; No carry, continue

carry_detected:

; Handle carry condition

; Continue with the rest of the program

```

2 marks

**Question 1:**

"What will be the content of reg AX after execution of the following program. Assume CF=1.

```

MOV AH, 0FH


MOV AL, FFH

SAR AH, 02

SHL AL, 02

SHR AL, 03

HLT

```

**Answer:**

Given:

- CF = 1 (Assumption)

- AH = 0FH

- AL = FFH

Execution steps:

1. Shift Arithmetic Right (SAR AH, 02):

- Before: AH = 0FH (00001111 in binary)

- After: AH = 03H (00000011 in binary) [CF = 1]

2. Shift Logical Left (SHL AL, 02):

- Before: AL = FFH (11111111 in binary)

- After: AL = FC (11111100 in binary) [CF = 1]

3. Shift Logical Right (SHR AL, 03):

- Before: AL = FC (11111100 in binary)

- After: AL = 1F (00011111 in binary) [CF = 1]

So, after execution, AX = 031FH.

---

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

- Content of accumulator (A7) in binary: 10100111

- Carry flag before rotation: 0

After RLC execution:

- Content of accumulator: 4F (in hex) (01001111 in binary)

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

In MOVSB, MOBSW, or MOVSD instructions:

- Source: The memory location addressed by the DS:SI register pair.

- Destination: The memory location addressed by the ES:DI register pair.

---

**Question 4:**

What is the output for the given 8086 program code?

```

MOV AX,0200H

MOV DS,AX

MOV SI, 0000

MOV DI, 0000

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.

- DS segment contains 528A00

- ES segment after execution contains 52748A

So, the output would be 52748A.

---

**Question 5:**

What would be the output for the following code?

```

MOV AX,01234H

MOV BX,01233H

XOR AX,BX

JZ ABC

MOV CX,01234H

HLT

ABC: MOV DX,1234H

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

Identify the hardware interrupt pins of 8086.

**Answer:**

The hardware interrupt pins of the 8086 microprocessor are:

- INTR (Interrupt Request)

- NMI (Non-Maskable Interrupt)

---

**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 XOR AL, AL, AL becomes 0.

After MOV CL, 03, CL becomes 3.

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?
```

A1: MOV AL,00H

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

ii. I2 requires 35 microseconds

iii. I3 requires 20 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:

- Time for microprocessor to respond to an interrupt: 4.5 microseconds

- Execution time after interrupt recognition:

i. I1 requires 25 microseconds

ii. I2 requires 35 microseconds

iii. I3 requires 20 microseconds

1. When only I3 occurs:

- Time taken = Time to respond to interrupt + Execution time for I3

- Time taken = 4.5 microseconds + 20 microseconds = 24.5 microseconds


2. When I1 occurs before I3:

- Time taken = Time to respond to interrupt + Execution time for I1

- Time taken = 4.5 microseconds + 25 microseconds = 29.5 microseconds

3. When I2 occurs before I3:

- Time taken = Time to respond to interrupt + Execution time for I2

- Time taken = 4.5 microseconds + 35 microseconds = 39.5 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:

- Time for microprocessor to respond to an interrupt: 4.5 microseconds

- Execution time after interrupt recognition:

i. I1 requires 25 microseconds

ii. I2 requires 35 microseconds

iii. I3 requires 20 microseconds

1. When only I3 occurs:

- Time taken = Time to respond to interrupt + Execution time for I3

- Time taken = 4.5 microseconds + 20 microseconds = 24.5 microseconds

2. When I1 occurs before I3:

- Time taken = Time to respond to interrupt (I1) + Execution time for I1

- Time taken = 4.5 microseconds + 25 microseconds = 29.5 microseconds


3. When I2 occurs before I3:

- Time taken = Time to respond to interrupt (I2) + Execution time for I2

- Time taken = 4.5 microseconds + 35 microseconds = 39.5 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:**

Match the following:

i. MOVSB/SW 1) loads AL/AX register by content of a string

ii. CMPS 2) moves a string of bytes stored in source to destination

iii. SCAS 3) compares two strings of bytes or words whose length is stored in CX register

iv. LODS 4) scans a string of bytes or words

**Answer:**

i. MOVSB/SW - 2) moves a string of bytes stored in source to destination

ii

. CMPS - 3) compares two strings of bytes or words whose length is stored in CX register

iii. SCAS - 4) scans a string of bytes or words

iv. LODS - 1) loads AL/AX register by content of a string

---

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

Describe LOCK prefix.

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

What is the value of AL register after execution of the following code:

```

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

Is Number less than 100?

No --> End

Yes

Convert Number to ASCII

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

MOV AL, [ASCII_digit1] ; Load the first ASCII digit into AL

SUB AL, '0' ; Convert ASCII digit to binary

MOV BL, 10 ; Load 10 into BL for multiplication

MUL BL ; Multiply AL by BL

MOV BH, 0 ; Clear BH

MOV BL, 16 ; Load 16 into BL for division

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

Input Hexadecimal Number

Display First Digit

Display Second Digit

Display Third Digit

Display Fourth Digit

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

; Using the macro

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:

\[ \text{Clock cycle time} = \frac{1}{\text{Clock frequency}} \]

Given the operating system frequency of 8086 system is 10 MHz, the time required for one clock
cycle would be:

\[ \frac{1}{10 \text{ MHz}} = 0.1 \mu s \]

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:

MOV CX, 50000 ; Load 50000 into CX (50000 * 0.1μs = 5000ms)

DELAY_LOOP:

DEC CX ; Decrement CX

JNZ DELAY_LOOP ; Jump if CX is not zero

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

MOV AL, 38h ; Load ASCII low nibble into AL

SUB AH, '0' ; Convert ASCII to binary

SUB AL, '0' ; Convert ASCII to binary

SHL AH, 4 ; Shift AH left by 4 bits

ADD BL, AH ; Add AH to BL

ADD BL, AL ; Add AL to BL

```

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

MOV AL, 45h ; Load packed BCD number into AL

AND AL, 0FH ; Mask lower nibble

OR AL, 30h ; Convert to ASCII

MOV AH, AL ; Copy ASCII digit to AH

SHR AL, 4 ; Shift AL right by 4 bits to get higher nibble

OR AL, 30h ; Convert to ASCII

```

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

MY_MACRO MACRO param1, param2

; Macro code using param1 and param2

ENDM

; Invoking the macro with parameters

MY_MACRO value1, value2

```

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

MY_MACRO MACRO param1, param2


MOV AX, param1

ADD AX, param2

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.

You might also like