0% found this document useful (0 votes)
9 views8 pages

Module2 QB Answers

The document provides a comprehensive overview of the 8086 microprocessor, detailing various instructions such as DAA, MOV, and REP, along with their addressing modes and examples. It includes assembly language programs for tasks like finding the largest number in a series, multiplying and dividing numbers, and counting odd numbers. Additionally, it explains assembler directives and their purposes, such as DB, DW, DD, and DUP.

Uploaded by

mishraaayush8721
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)
9 views8 pages

Module2 QB Answers

The document provides a comprehensive overview of the 8086 microprocessor, detailing various instructions such as DAA, MOV, and REP, along with their addressing modes and examples. It includes assembly language programs for tasks like finding the largest number in a series, multiplying and dividing numbers, and counting odd numbers. Additionally, it explains assembler directives and their purposes, such as DB, DW, DD, and DUP.

Uploaded by

mishraaayush8721
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

Module 2 – Question Bank Answers

8086 Microprocessor – Architecture, Instructions & Programming

Q1. Explain DAA Instruction with a suitable example


DAA stands for Decimal Adjust after Addition. It is used to adjust the result in the AL register
after adding two BCD (Binary Coded Decimal) numbers using the ADD or ADC instruction. After
a binary addition that might produce a non-BCD result, DAA corrects the AL register to a valid
packed BCD number.

How DAA works:


• If the lower nibble of AL > 9, OR if AF (Auxiliary Carry) = 1, then 06H is added to AL.
• If the upper nibble of AL > 9, OR if CF (Carry Flag) = 1, then 60H is added to AL.

Example:
MOV AL, 48H ; AL = 48 (BCD for 48)
MOV BL, 29H ; BL = 29 (BCD for 29)
ADD AL, BL ; AL = 71H (not valid BCD – lower nibble > 9)
DAA ; Adjust: 71H + 06H = 77H (valid BCD for 77)

Result: AL = 77H, which correctly represents BCD 77 (48 + 29 = 77).

Q2. State the Addressing Mode of the Following Instructions

1) DAS
• DAS = Decimal Adjust after Subtraction.
• Addressing Mode: Implied / Implicit Addressing Mode – no operands; operates implicitly
on the AL register.

2) MOV AX, [2300H]


• Addressing Mode: Direct Addressing Mode.
• The address 2300H is directly specified in the instruction.
• Physical Address = DS × 10H + 2300H

Q3. What is the Function of REP Instruction Prefix in String Instructions?


REP (Repeat) is a prefix used with string instructions to repeat the operation until the CX
register becomes zero. It decrements CX by 1 after each execution of the string instruction.

Variants:
• REP – Repeat while CX ≠ 0
• REPE / REPZ – Repeat while CX ≠ 0 AND ZF = 1
• REPNE / REPNZ – Repeat while CX ≠ 0 AND ZF = 0
Example – MOVS (Move String):
MOV CX, 10 ; Set counter to 10 (move 10 bytes)
LEA SI, SRC ; SI points to source string
LEA DI, DEST ; DI points to destination string
CLD ; Clear DF (auto-increment mode)
REP MOVSB ; Move 10 bytes from [SI] to [DI]
This copies 10 bytes from the source to the destination, decrementing CX each time until CX =
0.

Q4. Physical Address Calculation for Given Addressing Modes


Given register values:
Register Value Register Value

CS 0000H DS 1000H

SS 2000H BX 2000H

IP 7000H SI 3000H

DI 4000H BP 5000H

SP 6000H

Instruction 1: MOV AX, [5000H] → Direct Addressing Mode


Physical Address = DS × 10H + Offset = 1000H × 10H + 5000H = 10000H + 5000H = 15000H

Instruction 2: MOV [6000H], AX → Direct Addressing Mode


Physical Address = DS × 10H + 6000H = 10000H + 6000H = 16000H

Q5. Explain the Following Instructions with Examples

1) JNZ – Jump if Not Zero


JNZ (Jump if Not Zero) is a conditional jump instruction. It transfers control to the target label if
the Zero Flag (ZF) = 0 (i.e., the previous result was NOT zero).

Syntax: JNZ label

Example:
MOV CX, 5 ; Initialize counter
LOOP_START:
DEC CX ; Decrement CX
JNZ LOOP_START ; Jump back if CX ≠ 0
This loop repeats 5 times until CX becomes 0.

2) LEA – Load Effective Address


LEA loads the 16-bit offset address (effective address) of the source operand into the
destination register. Unlike MOV, it does NOT access memory – it loads the address itself.

Syntax: LEA destination, source

Example:
LEA BX, [2000H] ; Load effective address 2000H into BX
LEA SI, ARRAY ; Load address of ARRAY into SI
After LEA BX, [2000H]: BX = 2000H (not the content at address 2000H).

Q6. State the Addressing Mode of the Following Instructions (Justify)

1) MOV [4500H], AX
• Addressing Mode: Direct Addressing Mode
• Justification: The memory address (4500H) is specified directly in the instruction. The
contents of AX are stored at the memory location DS:4500H.
• Physical Address = DS × 10H + 4500H

2) AND AX, BX
• Addressing Mode: Register Addressing Mode
• Justification: Both operands (AX and BX) are CPU registers. No memory access is
needed; the operation is performed directly on register contents.

Q7. Explain the Purpose of Assembler Directives


Assembler directives (also called pseudo-ops) are instructions to the assembler program, NOT
to the CPU. They do not generate machine code directly but guide the assembler in translating
the program.

Common Assembler Directives:


Directive Purpose Example
DB Define Byte – allocates 1 byte of DATA DB 25H
memory
DW Define Word – allocates 2 bytes NUM DW 1234H
DD Define Doubleword – allocates 4 bytes VAL DD 12345678H
DUP Duplicate – reserve multiple locations ARR DB 10 DUP(0)
EQU Equate – assigns a constant value MAX EQU 100
SEGMENT Define a memory segment CODE SEGMENT
ENDS End of segment CODE ENDS
PROC Define a procedure MAIN PROC FAR
ASSUME Associates registers with segments ASSUME CS:CODE, DS:DATA
END End of program END MAIN

Q8. ALP to Find the Largest Number in a Series


Program: Finds the largest number from a series stored in memory and stores it immediately
after the series.

DATA SEGMENT
SERIES DB 25H, 10H, 45H, 30H, 05H ; Series of 5 numbers
COUNT EQU 5 ; Number of elements
RESULT DB ? ; Storage for result
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC FAR
MOV AX, DATA
MOV DS, AX

LEA SI, SERIES ; SI points to start of series


MOV CX, COUNT-1 ; CX = 4 (comparisons = n-1)
MOV AL, [SI] ; AL = first element (assumed largest)
INC SI ; Move to next element

COMPARE:
CMP AL, [SI] ; Compare current largest with [SI]
JAE SKIP ; If AL >= [SI], skip update
MOV AL, [SI] ; Update AL with new largest
SKIP:
INC SI ; Point to next element
LOOP COMPARE ; Decrement CX and repeat

MOV RESULT, AL ; Store largest after the series

MOV AH, 4CH


INT 21H
MAIN ENDP
CODE ENDS
END MAIN

Q9. ALP to Multiply Two 8-bit Numbers and Store Result at Memory
RESULT
DATA SEGMENT
NUM1 DB 05H ; First 8-bit number
NUM2 DB 04H ; Second 8-bit number
RESULT DW ? ; 16-bit result (5 x 4 = 20 = 0014H)
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC FAR
MOV AX, DATA
MOV DS, AX

MOV AL, NUM1 ; Load first number into AL


MOV BL, NUM2 ; Load second number into BL
MUL BL ; AX = AL * BL (unsigned 8x8 multiply)
MOV RESULT, AX ; Store 16-bit result

MOV AH, 4CH


INT 21H
MAIN ENDP
CODE ENDS
END MAIN

Note: MUL BL performs AL × BL and stores the 16-bit result in AX.

Q10. ALP to Divide Two 8-bit Numbers (NUM1 ÷ NUM2), Store Result
DATA SEGMENT
NUM1 DB 14H ; Dividend = 20 decimal
NUM2 DB 04H ; Divisor = 4 decimal
QUOTIENT DB ? ; Result = 5
REMAINDER DB ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC FAR
MOV AX, DATA
MOV DS, AX

MOV AH, 00H ; AH = 0 (upper byte of dividend)


MOV AL, NUM1 ; AL = NUM1 (dividend)
MOV BL, NUM2 ; BL = divisor
DIV BL ; AL = Quotient, AH = Remainder

MOV QUOTIENT, AL ; Store quotient


MOV REMAINDER, AH ; Store remainder

MOV AH, 4CH


INT 21H
MAIN ENDP
CODE ENDS
END MAIN

Note: DIV BL divides AX by BL. Quotient → AL, Remainder → AH.


Q11. WAP to Find the Lowest in a Series of 10 Numbers from 20,000H
Store result immediately after the series.
DATA SEGMENT
ORG 20000H
SERIES DB 10 DUP(?) ; 10 numbers starting at 20000H
RESULT DB ? ; Result stored after series at 2000AH
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC FAR
MOV AX, DATA
MOV DS, AX

MOV SI, 20000H ; SI = start of series


MOV CX, 9 ; Compare 9 times (n-1)
MOV AL, [SI] ; AL = first element (assume minimum)
INC SI

FIND_MIN:
CMP AL, [SI] ; Compare current min with [SI]
JBE SKIP ; If AL <= [SI], keep AL
MOV AL, [SI] ; New minimum found
SKIP:
INC SI
LOOP FIND_MIN

MOV [SI], AL ; Store minimum after series (at 2000AH)

MOV AH, 4CH


INT 21H
MAIN ENDP
CODE ENDS
END MAIN

Q12. ALP to Find the Total Number of ODD Numbers in a Series of 10


Numbers
Algorithm / Flowchart Description:
• Start
• Load count = 10, odd_count = 0
• Load next number from series
• Test if LSB = 1 (AND with 01H; if result ≠ 0, it is ODD)
• If ODD, increment odd_count
• Decrement CX; if CX ≠ 0, go to step 3
• Store odd_count in RESULT
• Stop

DATA SEGMENT
SERIES DB 11H,22H,33H,44H,55H,66H,77H,88H,99H,0AAH
COUNT EQU 10
ODD_COUNT DB 00H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA
MAIN PROC FAR
MOV AX, DATA
MOV DS, AX

LEA SI, SERIES ; SI → start of series


MOV CX, COUNT ; CX = 10
MOV BL, 00H ; BL = odd counter

CHECK:
MOV AL, [SI] ; Load number
AND AL, 01H ; Test LSB
JZ EVEN ; If ZF=1, number is even
INC BL ; Increment odd count
EVEN:
INC SI
LOOP CHECK

MOV ODD_COUNT, BL ; Store result


MOV AH, 4CH
INT 21H
MAIN ENDP
CODE ENDS
END MAIN

Q13. Explain the Instructions: DAA, PUSH, MOVS, LOOP, CMPS

1) DAA – Decimal Adjust Accumulator after Addition


Adjusts AL after BCD addition. Already explained in Q1.
ADD AL, BL ; Binary add
DAA ; Correct AL to valid BCD

2) PUSH – Push Data onto Stack


Pushes a 16-bit register or memory value onto the stack. SP is decremented by 2, then the
value is stored at [SP].
PUSH AX ; SP = SP-2; Memory[SP] = AX
PUSH BX ; SP = SP-2; Memory[SP] = BX

3) MOVS – Move String


Copies a byte (MOVSB) or word (MOVSW) from the address in DS:SI to ES:DI, then auto-
increments/decrements SI and DI based on the Direction Flag.
MOVSB ; ES:[DI] = DS:[SI]; SI++; DI++
REP MOVSB ; Repeat CX times

4) LOOP – Loop Control


Decrements CX by 1. If CX ≠ 0, jumps to the specified label. If CX = 0, execution continues to
the next instruction.
MOV CX, 05H ; Set loop count
AGAIN:
; loop body
LOOP AGAIN ; Decrement CX; jump if CX ≠ 0

5) CMPS – Compare String


Compares a byte (CMPSB) or word (CMPSW) at DS:SI with ES:DI and sets flags accordingly.
Used with REPE/REPNE to search or compare strings.
CMPSB ; Compare DS:[SI] with ES:[DI]; update flags
REPE CMPSB ; Repeat while equal and CX ≠ 0

Q14. Explain the Assembler Directives: DB, DW, DD, DUP

(a) DB – Define Byte


Allocates 1 byte (8 bits) of memory and optionally initializes it.
NUM DB 25H ; Allocates 1 byte, initialized to 25H
MSG DB 'A' ; Stores ASCII value of 'A'
TEMP DB ? ; 1 byte, uninitialized

(b) DW – Define Word


Allocates 2 bytes (16 bits) of memory. In little-endian format, the low byte is stored first.
DATA DW 1234H ; Stores 34H at first byte, 12H at second
VAL DW ? ; 2 bytes, uninitialized

(c) DD – Define Doubleword


Allocates 4 bytes (32 bits) of memory. Used for 32-bit data or far pointers.
BIG DD 12345678H ; Stores 4 bytes
PTR DD FAR_PROC ; Far pointer (segment:offset)

(d) DUP – Duplicate Operator


Used with DB/DW/DD to repeat a value a specified number of times. Very useful for initializing
arrays.
ARR DB 10 DUP(0) ; 10 bytes, all initialized to 0
BUF DB 5 DUP(?) ; 5 bytes, uninitialized
WORD_ARR DW 4 DUP(0FFH) ; 4 words, all set to 00FFH

Summary Table:
Directive Size Bits Use Case
DB 1 byte 8-bit Single character, small integers
DW 2 bytes 16-bit Integers, addresses, offsets
DD 4 bytes 32-bit Long integers, far pointers
DUP Variable N/A Arrays, buffers, repeated data

— End of Module 2 Question Bank Answers —

You might also like