Microprocessor · Unit 4 · 10 hrs
Assembly Language Programming
Exam-focused notes for Assembly Language Programming (Microprocessor, CSC167): what the TU syllabus asks and how it has actually been tested, with 28 solved past questions from this unit.
Assembly Language Programming in short
This chapter turns the 8085 (and, for the DOS-style example programs, the 8086) instruction set into working assembly language: how an instruction is written and assembled, the different ways an instruction can address its data, and the standard sequence, branching and loop patterns used to build a working program.
What this unit covers
- Assembly instruction format
- Instruction Types
- Mnemonics
- Operands
- Macro assemblers
- Linking
- Assembler directives
- Addressing Modes
- Simple sequence programs
- Flags
- Branch
- Jumps
- While-Do
- Repeat-Until
- If-Then-Else and Multiple If-then Programs
- Debugging
Simple sequence programs
2081 · 10 marks
Explain LHLD and SHLD instruction. Ten 8-bit data are stored at memory location starting from 6000H. Write an assembly program for 8085 microprocessor to calculate the sum of this data array and store the sum and carry starting from 9500H.[10]
Show solved answerHide answer
LHLD & SHLD Instructions + Sum of Data Array Program
Given
- Number of data values: 10 (0AH)
- Data type: 8-bit each
- Data starting address: 6000H (so 6000H to 6009H)
- Sum storage address: 9500H
- Carry storage address: implied 9501H (next location)
All required data is present.
Solution
Part 1: LHLD and SHLD Instructions
LHLD (Load H-L pair Direct)
A 3-byte instruction that loads the contents of two consecutive memory locations directly into the HL register pair.
Syntax: LHLD address
Operation:
- $L \leftarrow M[address]$
- $H \leftarrow M[address+1]$
Example: LHLD 2200H - if 2200H = 45H and 2201H = 32H, then after execution $L = 45H$, $H = 32H$.
Size: 3 bytes, Machine cycles: 5, T-states: 16
SHLD (Store H-L pair Direct)
A 3-byte instruction that stores the contents of the HL register pair into two consecutive memory locations.
Syntax: SHLD address
Operation:
- $M[address] \leftarrow L$
- $M[address+1] \leftarrow H$
Example: SHLD 2302H - if $H = 32H$, $L = 45H$, then 2302H = 45H, 2303H = 32H.
Size: 3 bytes, Machine cycles: 5, T-states: 16
Part 2: Assembly Language Program
Algorithm
- Initialize carry register $C = 00H$
- Initialize counter $B = 0AH$ (10 items)
- Point HL to 6000H
- Clear accumulator ($A = 00H$)
- Add memory content to A; if carry occurs, increment C
- Advance pointer, decrement counter, repeat until zero
- Store sum at 9500H, carry at 9501H
Program
; Sum of 10 eight-bit data stored from 6000H
; Sum -> 9500H, Carry -> 9501H
MVI C, 00H ; carry counter = 0
MVI B, 0AH ; counter = 10
LXI H, 6000H ; HL points to first data
SUB A ; A = 0 (clear accumulator, clears CY)
BACK: ADD M ; A = A + [HL]
JNC SKIP ; if no carry, skip
INR C ; else increment carry register
SKIP: INX H ; next memory location
DCR B ; decrement counter
JNZ BACK ; repeat until counter = 0
STA 9500H ; store sum
MOV A, C ; move carry to A
STA 9501H ; store carry
HLT ; halt
Explanation
| Instruction | Operation |
|---|---|
MVI C, 00H | Carry counter initialized to zero |
MVI B, 0AH | Loop counter = 10 |
LXI H, 6000H | HL points to first data location |
SUB A | Clears A to 00H |
ADD M | Adds memory content to accumulator |
JNC SKIP | Skip if no carry produced |
INR C | Increment carry register on overflow |
INX H | Advance pointer |
DCR B | Decrement counter |
JNZ BACK | Loop until all 10 added |
STA 9500H | Store final sum |
MOV A, C | Move carry count to A |
STA 9501H | Store carry byte |
HLT | Stop |
Key Points
- Register C accumulates the number of carries, forming the high byte of the 16-bit result. Since each byte is at most FFH, the maximum sum of 10 bytes is $10 \times 255 = 2550 = 09F6H$, so C never exceeds 09H: a single carry register suffices.
SUB Aclears the accumulator and also resets the carry flag before the loop.
Result: Low byte of sum stored at 9500H, carry (high byte) stored at 9501H.
Note: the problem does not explicitly state 9501H for the carry, but "starting from 9500H" naturally implies the next byte (9501H), so that assumption is reasonable and standard.
2081 · 5 marks
Write an ALP to convert the string 'computer science' to upper case using 16 bit microprocessor. [5]
Show solved answerHide answer
ALP to Convert String 'computer science' to Upper Case (16-bit Microprocessor / 8086)
Concept
In ASCII, lowercase letters range from 61H ('a') to 7AH ('z') and uppercase letters range from 41H ('A') to 5AH ('Z'). To convert lowercase to uppercase, we subtract 20H from the ASCII value of each lowercase character.
Spaces and other non-alphabetic characters are left unchanged.
Assembly Language Program
.MODEL SMALL
.STACK 100H
.DATA
STRING DB 'computer science', '$' ; Define the string with $ terminator
LEN DW 16 ; Length of the string (16 characters)
.CODE
MAIN PROC
MOV AX, @DATA ; Load address of DATA segment into AX
MOV DS, AX ; Initialize Data Segment register
MOV SI, OFFSET STRING ; SI points to the start of the string
MOV CX, LEN ; CX = loop counter = length of string
BACK:
MOV AL, [SI] ; Load current character into AL
CMP AL, 'a' ; Compare AL with 'a' (61H)
JB SKIP ; If AL < 'a', not a lowercase letter, skip
CMP AL, 'z' ; Compare AL with 'z' (7AH)
JA SKIP ; If AL > 'z', not a lowercase letter, skip
SUB AL, 20H ; Convert lowercase to uppercase by subtracting 20H
MOV [SI], AL ; Store the converted character back into memory
SKIP:
INC SI ; Move SI to point to next character
LOOP BACK ; Decrement CX and repeat if CX != 0
; Display the converted string
MOV DX, OFFSET STRING ; Load address of converted string into DX
MOV AH, 09H ; DOS function 09H: display string
INT 21H ; Call DOS interrupt
MOV AX, 4C00H ; DOS function 4CH: terminate program
INT 21H
MAIN ENDP
END MAIN
Step-by-Step Explanation
| Step | Instruction | Purpose |
|---|---|---|
| 1 | MOV AX, @DATA / MOV DS, AX | Initialize the Data Segment |
| 2 | MOV SI, OFFSET STRING | SI points to first character of string |
| 3 | MOV CX, LEN | Set loop counter to string length (16) |
| 4 | MOV AL, [SI] | Load each character one by one |
| 5 | CMP AL, 'a' and CMP AL, 'z' | Check if character is lowercase |
| 6 | SUB AL, 20H | Convert to uppercase (e.g., 'c' = 63H - 20H = 43H = 'C') |
| 7 | MOV [SI], AL | Write converted character back |
| 8 | INC SI / LOOP BACK | Advance to next character and repeat |
| 9 | INT 21H (AH=09H) | Display the final uppercase string |
Example Conversion
| Character | ASCII (Hex) | After SUB 20H | Result |
|---|---|---|---|
| 'c' | 63H | 43H | 'C' |
| 'o' | 6FH | 4FH | 'O' |
| ' ' (space) | 20H | Skipped | ' ' |
| 's' | 73H | 53H | 'S' |
Output: COMPUTER SCIENCE
2080 · 10 marks
Explain the working of LHLD and DAA instruction of 8085. An array containing 5 elements is stored from memory location 4000h to 4004h; write an assembly language program for 8085 microprocessor to find largest element of array and store in memory location 4005h.[10]
2080 · 5 marks
Write an assembly language program for 16 bit microprocessor to count and display number of occurrence of letter 'o' in string 'Microprocessor organization'. [5]
2079 · 10 marks
Write an assembly language program to find the largest number of an array using 8 bit microprocessor. (Assume appropriate array data and address where minimum array size of 15 should be considered)[10]
Show solved answerHide answer
Assembly Language Program to Find the Largest Number in an Array (8085 Microprocessor)
Given Data (Extracted)
The question specifies no fixed numeric values, so standard exam assumptions are made:
| Item | Assumed Value |
|---|---|
| Array length stored at | 2200H |
| Array data starts at | 2201H |
| Array size (minimum required) | 15 elements (0FH) |
| Result location | 2300H |
| Data type | Unsigned 8-bit numbers |
Sample Array (15 elements)
| Address | Data |
|---|---|
| 2200H | 0FH (count = 15) |
| 2201H | 45H |
| 2202H | 78H |
| 2203H | 12H |
| 2204H | 9AH |
| 2205H | 33H |
| 2206H | FFH |
| 2207H | 56H |
| 2208H | 02H |
| 2209H | 88H |
| 220AH | 67H |
| 220BH | 1CH |
| 220CH | 99H |
| 220DH | 44H |
| 220EH | 7BH |
| 220FH | 3EH |
Algorithm
- Load count from
2200Hinto register C. - Point HL to first data element (
2201H). - Move first element to A (assume it is the largest).
- Decrement C (first element already read).
- Increment HL to next element.
- Compare current element M with A.
- If M > A, update A ← M.
- Increment HL, decrement C.
- If C ≠ 0, repeat from step 6.
- Store A at
2300H; HALT.
8085 Assembly Program
;-----------------------------------------------
; Find Largest Number in an Array
; Length at 2200H, Data from 2201H, Result at 2300H
;-----------------------------------------------
LDA 2200H ; A <- array length (count)
MOV C, A ; C <- count (loop counter)
LXI H, 2201H ; HL -> start of array
MOV A, M ; A <- first element (assume largest)
DCR C ; one element already read
INX H ; HL -> next element
LOOP: MOV B, M ; B <- current element
CMP B ; A - B ; if A < B, Carry = 1
JNC SKIP ; if A >= B, keep A
MOV A, B ; else A <- larger value B
SKIP: INX H ; next element
DCR C ; decrement counter
JNZ LOOP ; repeat until C = 0
STA 2300H ; store largest number
HLT ; stop
Dry Run (with Sample Data)
| Element | B | A (largest) | A < B? | Action |
|---|---|---|---|---|
| 1st (2201H) | - | 45H | - | A = 45H |
| 2202H | 78H | 45H | Yes | A = 78H |
| 2203H | 12H | 78H | No | A = 78H |
| 2204H | 9AH | 78H | Yes | A = 9AH |
| 2205H | 33H | 9AH | No | A = 9AH |
| 2206H | FFH | 9AH | Yes | A = FFH |
| 2207H | 56H | FFH | No | A = FFH |
| 2208H..220FH | ≤ FFH | FFH | No | A = FFH |
Final Result at 2300H = FFH (255 decimal): the largest element.
Registers Used
| Register | Purpose |
|---|---|
| A | Current largest value |
| B | Current element for comparison |
| C | Loop counter |
| HL | Memory pointer |
2079 · 5 marks
Write an assembly language program for 8086 to read two strings and check whether they are same or not. [5]
2078 · 10 marks
Explain LXI and CMP instruction. Write an assembly language program for 8-bit microprocessor to divide 8 bit data stored in memory location 8050 by 8 bit data stored in 8051 and store the quotient in 8052 and remainder in 8053.[10]
2078 · 5 marks
Write an assembly language program for 16 bit microprocessor to reverse the string 'This is Microprocessor' [5]
2076 · 10 marks
Write an assembly language program to find the greatest number in an array in using 8 bit microprocessor. (Assume appropriate array data and address where minimum array size of 20 should be considered.)[10]
Show solved answerHide answer
Assembly Language Program to Find the Greatest Number in an Array (8085 Microprocessor)
Problem Statement
Find the greatest (maximum) number in an array of 8-bit numbers using the 8085 (8-bit) microprocessor. The array has a minimum size of 20 elements.
Assumptions
| Item | Value / Description |
|---|---|
| Array length | 20 (14H) stored at memory location 2200H |
| Array data | Starts from memory location 2201H onwards |
| Result storage | Memory location 2300H |
| Data type | Unsigned 8-bit numbers |
Sample Array Data (20 elements at 2201H onwards)
2200H --> 14H ; count = 20
2201H --> 45H
2202H --> 78H
2203H --> 23H
2204H --> 99H ; greatest
2205H --> 12H
... (remaining 15 elements)
2214H --> 67H
Algorithm / Logic
Step 1: Load the count (length) of array into register C
Step 2: Load the first element of array into Accumulator (A)
This is our initial "maximum" value
Step 3: Decrement counter C by 1 (since first element already loaded)
Step 4: Point HL register pair to the next element (2202H)
Step 5: LOOP:
Load next element from memory into register B
Compare A with B (A - B)
If A >= B, skip (A is still the maximum)
If A < B, update A = B (new maximum found)
Increment HL to point to next element
Decrement counter C
If C != 0, repeat LOOP
Step 6: Store the result (maximum value) into 2300H
Step 7: HLT
Assembly Language Program (8085)
LDA 2200H ; Load array length (20 = 14H) into Accumulator
MOV C, A ; Move length/count into register C (counter)
LXI H, 2201H ; Point HL to the start of array (first element)
MOV A, M ; Load first element into Accumulator
; Assume first element as the greatest initially
INX H ; Increment HL to point to second element
DCR C ; Decrement counter (one element already loaded)
LOOP: MOV B, M ; Load next array element into register B
CMP B ; Compare Accumulator (current max) with B
; Internally performs A - B and sets flags
JNC SKIP ; Jump to SKIP if A >= B (No Carry means A >= B)
; i.e., current max is still greater or equal
MOV A, B ; If A < B, update Accumulator with new maximum
SKIP: INX H ; Increment HL to point to next memory location
DCR C ; Decrement counter register C by 1
JNZ LOOP ; If counter != 0, jump back to LOOP
STA 2300H ; Store the greatest number into memory location 2300H
HLT ; Stop the program
Step-by-Step Explanation of Each Instruction
| Instruction | Operation | Purpose |
|---|---|---|
LDA 2200H | A <- [2200H] | Load count (14H = 20) into A |
MOV C, A | C <- A | Use C as loop counter |
LXI H, 2201H | HL <- 2201H | Point HL to first array element |
MOV A, M | A <- [HL] | Load first element as initial max |
INX H | HL <- HL + 1 | Move pointer to second element |
DCR C | C <- C - 1 | Reduce count by 1 (first element done) |
MOV B, M | B <- [HL] | Load current element into B |
CMP B | A - B (flags set) | Compare current max with current element |
JNC SKIP | Jump if No Carry | If A >= B, skip update |
MOV A, B | A <- B | Update max if B is greater |
INX H | HL <- HL + 1 | Move to next element |
DCR C | C <- C - 1 | Decrement counter |
JNZ LOOP | Jump if C != 0 | Repeat until all elements checked |
STA 2300H | [2300H] <- A | Store the greatest number |
HLT | Stop | End of program |
Dry Run / Trace (Partial Example)
Assume array: 45H, 78H, 23H, 99H, 12H ...
| Iteration | A (current max) | B (new element) | CMP result | Action |
|---|---|---|---|---|
| Initial | 45H | -- | -- | A = 45H (first element) |
| 1 | 45H | 78H | A < B (carry set) | A = 78H |
| 2 | 78H | 23H | A > B (no carry) | A = 78H (no change) |
| 3 | 78H | 99H | A < B (carry set) | A = 99H |
| 4 | 99H | 12H | A > B (no carry) | A = 99H (no change) |
| ... | 99H | ... | A >= all | A = 99H |
Result stored at 2300H = 99H (Greatest number)
Key Notes
CMP instruction in 8085 subtracts the operand from Accumulator without storing the result, but sets the Carry Flag (CY) and Zero Flag (ZF) according to the result: if A = B, CY = 0 and ZF = 1; if A > B, CY = 0 and ZF = 0; if A < B, CY = 1 and ZF = 0.
JNC (Jump if No Carry) is used right after
CMPto branch when A >= B, since the Carry flag is cleared only when no borrow was needed.
Using
CMPfollowed by a conditional jump lets the program compare values without altering the Accumulator, which is essential here because the running maximum stored in A must be preserved across every loop iteration until it is actually replaced.
2076 · 5 marks
Write an ALP for 8086 to read a string and print it in the reverse order. [5]
2075 · 10 marks
Write an assembly language program to find the smallest number in an array using 8 bit microprocessor, (assume appropriate array data and address where minimum array size of 15 should be considered.)[10]
Show solved answerHide answer
Assembly Language Program to Find the Smallest Number in an Array (8-bit Microprocessor - 8085)
Problem Understanding
- We need to find the smallest (minimum) number in an array of 8-bit data.
- Array size: minimum 15 elements
- We assume:
- Memory location 2200H stores the length of the array (count = 15 = 0FH)
- Memory locations 2201H onwards store the array elements
- Result (smallest number) is stored at memory location 2300H
Assumed Array Data
| Memory Address | Data (Hex) |
|---|---|
| 2200H | 0FH (length = 15) |
| 2201H | 45H |
| 2202H | 12H |
| 2203H | 78H |
| 2204H | 03H |
| 2205H | 56H |
| 2206H | 89H |
| 2207H | 21H |
| 2208H | 0AH |
| 2209H | 34H |
| 220AH | 67H |
| 220BH | 09H |
| 220CH | 55H |
| 220DH | 1FH |
| 220EH | 72H |
| 220FH | 2BH |
Expected smallest value = 03H (at address 2204H)
Algorithm / Logic
Step 1: Load the count (length) of array from memory 2200H into register C
Step 2: Point HL register pair to the first element (2201H)
Step 3: Load the first element into Accumulator as the assumed minimum
Step 4: Decrement counter C by 1 (first element already loaded)
Step 5: Advance HL pointer to next element
Step 6: Compare current element (M) with Accumulator (current minimum)
- If current element >= Accumulator, skip (no update)
- If current element < Accumulator, update Accumulator with current element
Step 7: Decrement counter C, advance pointer
Step 8: Repeat Steps 6-7 until counter C = 0
Step 9: Store the result (Accumulator) at 2300H
Step 10: HLT
Assembly Language Program (8085 ALP)
; ============================================================
; Program : Find Smallest Number in an Array
; Array : Starts at 2201H, Length stored at 2200H
; Result : Stored at 2300H
; Array Size: 15 elements (0FH)
; ============================================================
LDA 2200H ; Load the count (length = 0FH) into Accumulator
MOV C, A ; Move count into register C (loop counter)
LXI H, 2201H ; Point HL pair to the first element of array
MOV A, M ; Load first element into Accumulator
; Assume first element as the current minimum
DCR C ; Decrement counter (first element already read)
INX H ; Advance HL pointer to next element
LOOP: MOV B, M ; Load next array element into register B
CMP B ; Compare Accumulator (current min) with B
; CMP performs A - B and sets flags
; If A <= B, Carry flag = 0, so A is still smaller
; If A > B, Carry flag = 1, so B is the new minimum
JC UPDATE ; Jump to UPDATE if Carry = 1 (i.e., A > B, B is smaller)
JZ SKIP ; Jump to SKIP if Zero = 1 (i.e., A = B, no update needed)
JMP SKIP ; Jump to SKIP if A < B (A is already smaller)
UPDATE: MOV A, B ; Update Accumulator with the new smaller value (B)
SKIP: INX H ; Advance HL pointer to next memory location
DCR C ; Decrement loop counter
JNZ LOOP ; If counter not zero, repeat loop
STA 2300H ; Store the smallest number into memory location 2300H
HLT ; Stop the program
Step-by-Step Instruction Explanation
| Instruction | Operation | Purpose |
|---|---|---|
LDA 2200H | A <- M[2200H] | Load array length (15 = 0FH) |
MOV C, A | C <- A | Set loop counter to 15 |
LXI H, 2201H | HL <- 2201H | Point to first array element |
MOV A, M | A <- M[HL] | Load first element as assumed minimum |
DCR C | C <- C - 1 | Reduce count (first element consumed) |
INX H | HL <- HL + 1 | Move to next element |
MOV B, M | B <- M[HL] | Load current element into B |
CMP B | A - B (flags set) | Compare current min with current element |
JC UPDATE | Jump if Carry=1 | If A > B, update minimum |
MOV A, B | A <- B | B is new minimum |
INX H | HL <- HL + 1 | Advance to next element |
DCR C | C <- C - 1 | Decrement counter |
JNZ LOOP | Jump if C != 0 | Repeat until all elements checked |
STA 2300H | M[2300H] <- A | Store final minimum |
HLT | -- | End program |
Dry Run (Partial Trace)
| Iteration | A (Current Min) | B (New Element) | CMP Result | Action |
|---|---|---|---|---|
| 1 | 45H | 12H | A > B | A <- 12H (new minimum) |
| 2 | 12H | 78H | A < B | No change |
| 3 | 12H | 03H | A > B | A <- 03H (new minimum) |
| 4 | 03H | 56H | A < B | No change |
| 5 | 03H | 89H | A < B | No change |
| 6 | 03H | 21H | A < B | No change |
| 7 | 03H | 0AH | A < B | No change |
| 8 | 03H | 34H | A < B | No change |
| 9 | 03H | 67H | A < B | No change |
| 10 | 03H | 09H | A < B | No change |
| 11 | 03H | 55H | A < B | No change |
| 12 | 03H | 1FH | A < B | No change |
| 13 | 03H | 72H | A < B | No change |
| 14 | 03H | 2BH | A < B | No change |
After the fourteenth comparison the counter in C reaches zero, the loop ends, and STA 2300H stores the accumulator.
Result: memory location 2300H holds 03H, the smallest number in the array, which matches the expected value identified with the assumed data.
Conclusion
The program treats the first element as the assumed minimum and then walks the array once with the HL pair, comparing each element against the accumulator and replacing it whenever a smaller value is found. Since every element is examined exactly once, the routine needs (n - 1) comparisons for n elements, which is 14 comparisons for the 15-element array assumed here, and it works unchanged for any array length placed in 2200H.
2075 · 5 marks
Write an ALP for 8086 to read a string and display the string in uppercase. [5]
2080.1 · 10 marks
Write an Assembly program for calculating the factorial of a number using 8085 microprocessor.[10]
2080.1 · 5 marks
Write an Assembly program to reverse the given string. [5]
Addressing Modes
2081 · 5 marks
Explain different addressing modes in 8085 microprocessor. [5]
2080 · 5 marks
What is mean by addressing mode? Explain different addressing modes in 8085 microprocessor. [5]
2078 · 5 marks
What is mean by addressing mode? Explain all the addressing mode available in 8085 microprocessor. [5]
2075 · 5 marks
Explain the addressing modes of 8085 microprocessor with examples. [5]
Flags
2081 · 5 marks
Write short notes on :a. Flags in 8085 MPU b. DMA [5]
Show solved answerHide answer
Short Notes: Flags in 8085 MPU and DMA
a. Flags in 8085 MPU
Flags are special flip-flop circuits within the Flag Register (also called the Program Status Word) of the 8085 microprocessor. They are set (1) or reset (0) automatically based on the result of arithmetic and logical operations performed by the ALU. They indicate the status of the accumulator and other registers after the completion of an operation.
The 8085 MPU uses 5 flags, arranged in an 8-bit flag register:
| Bit Position | D7 | D6 | D5 | D4 | D3 | D2 | D1 | D0 |
|---|---|---|---|---|---|---|---|---|
| Flag | S | Z | -- | AC | -- | P | -- | CY |
The Five Flags:
-
Sign Flag (S)
- Set to 1 if the result of an operation is negative (i.e., the MSB/D7 bit of the result is 1).
- Reset to 0 if the result is positive.
-
Zero Flag (Z)
- Set to 1 if the result of an operation is zero.
- Reset to 0 if the result is non-zero.
-
Auxiliary Carry Flag (AC)
- Set to 1 if there is a carry out from bit D3 to bit D4 (carry from the lower nibble to the upper nibble).
- Primarily used in BCD (Binary Coded Decimal) arithmetic operations.
-
Parity Flag (P)
- Set to 1 if the result contains an even number of 1s (even parity).
- Reset to 0 if the result contains an odd number of 1s (odd parity).
-
Carry Flag (CY)
- Set to 1 if an arithmetic operation generates a carry out from the MSB (D7) or requires a borrow.
- Used in multi-byte addition and subtraction operations.
These flags are essential for conditional branching instructions (e.g., JZ, JNZ, JC, JNC) which allow the program to make decisions based on the result of previous operations.
b. DMA (Direct Memory Access)
DMA (Direct Memory Access) is a technique that allows I/O devices to transfer data directly to or from memory without the involvement of the CPU for each byte of data transferred.
Need for DMA:
- Normally, data transfer between memory and I/O devices is managed by the CPU, which wastes CPU time.
- For large and high-speed data transfers (e.g., disk drives, video, network), DMA provides a much faster and efficient method.
How DMA Works:
- The I/O device requests a DMA transfer by sending a signal to the DMA Controller (DMAC).
- The DMAC sends a HOLD request to the CPU.
- The CPU completes its current operation, then sends a HLDA (Hold Acknowledge) signal and releases the buses (address, data, and control buses).
- The DMAC takes control of the buses and transfers data directly between the I/O device and memory.
- After the transfer is complete, the DMAC releases the buses and the CPU resumes normal operation.
Key Components:
- DMA Controller (DMAC): A dedicated chip (e.g., Intel 8257) that manages the transfer.
- HOLD and HLDA pins of the 8085 are used for DMA handshaking.
Advantages of DMA:
- Fast data transfer at memory speed.
- CPU is free to perform other tasks (or is only briefly paused).
- Efficient for bulk data transfers.
Disadvantage:
- Requires additional hardware (DMAC chip), increasing system cost and complexity.
Summary Table:
| Feature | Flags | DMA |
|---|---|---|
| Purpose | Indicate ALU result status | Fast memory-I/O data transfer |
| Location | Inside 8085 Flag Register | External DMAC chip |
| Number | 5 flags (S, Z, AC, P, CY) | Uses HOLD/HLDA pins |
| Use | Conditional branching | Bulk data transfer |
2080 · 5 marks
What is flag? Explain all the flags present in 8085 microprocessor. [5]
Show solved answerHide answer
Flags in 8085 Microprocessor
What is a Flag?
A flag is a single-bit flip-flop (1-bit register) that indicates the status of the accumulator or other registers after the completion of an arithmetic or logical operation. These flip-flops are set (1) or reset (0) according to the data condition of the result stored in the accumulator.
The flag register (also called the status register or F register) is an 8-bit register, but only 5 bits are used as flags in the 8085 microprocessor.
The 5 Flags of 8085 Microprocessor
The flag register layout is as follows:
| Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
|---|---|---|---|---|---|---|---|
| S | Z | -- | AC | -- | P | -- | CY |
1. Sign Flag (S) -- Bit 7
- Set to 1 if the MSB (bit 7) of the result is 1, indicating the result is negative.
- Reset to 0 if the result is positive (MSB = 0).
- Used in signed number arithmetic.
Example: If result = 10000001 (negative in 2's complement), S = 1.
2. Zero Flag (Z) -- Bit 6
- Set to 1 if the result of the operation is zero.
- Reset to 0 if the result is non-zero.
Example: If 05H - 05H = 00H, then Z = 1.
3. Auxiliary Carry Flag (AC) -- Bit 4
- Set to 1 if there is a carry out from bit 3 to bit 4 (i.e., carry from the lower nibble to the upper nibble).
- Primarily used in BCD (Binary Coded Decimal) arithmetic operations.
Example: If lower nibble addition produces a carry to bit 4, AC = 1.
4. Parity Flag (P) -- Bit 2
- Set to 1 if the result contains an even number of 1s (even parity).
- Reset to 0 if the result contains an odd number of 1s (odd parity).
Example: If result = 00000011 (two 1s -- even), then P = 1.
5. Carry Flag (CY) -- Bit 0
- Set to 1 if there is a carry out from the MSB (bit 7) during addition, or a borrow during subtraction.
- Reset to 0 if there is no carry or borrow.
Example: If FFH + 01H = 100H (carry out), then CY = 1.
Summary Table
| Flag | Symbol | Bit Position | Set When |
|---|---|---|---|
| Sign | S | 7 | Result is negative (MSB = 1) |
| Zero | Z | 6 | Result is zero |
| Auxiliary Carry | AC | 4 | Carry from bit 3 to bit 4 |
| Parity | P | 2 | Result has even number of 1s |
| Carry | CY | 0 | Carry out from MSB |
These five flags together help the programmer make conditional decisions (using conditional jump instructions) based on the outcome of arithmetic and logical operations.
2076 · 5 marks
What is flag? Explain the flags that are present in 8085 microprocessor. [5]
Show solved answerHide answer
Flag in 8085 Microprocessor
What is a Flag?
A flag is a single-bit flip-flop (1-bit register) that indicates the status or condition of the result stored in the accumulator after the completion of an arithmetic or logical operation. Flags are part of the Flag Register (also called the Program Status Word) inside the ALU. These flip-flops are set (1) or reset (0) according to the data condition of the result in the accumulator.
Flags in 8085 Microprocessor
The 8085 microprocessor has five flags arranged in an 8-bit flag register. The five flags are:
1. Sign Flag (S)
- After an arithmetic or logical operation, if the Most Significant Bit (D7) of the result is 1, the Sign flag is set (S = 1), indicating the result is negative.
- If D7 = 0, the flag is reset (S = 0), indicating the result is positive.
- Example: If result = 10000001 (in 2's complement, a negative number), S = 1.
2. Zero Flag (Z)
- If the result of an operation is zero (00H), the Zero flag is set (Z = 1).
- If the result is non-zero, the flag is reset (Z = 0).
- Example: If 05H - 05H = 00H, then Z = 1.
3. Auxiliary Carry Flag (AC)
- Also called the Half Carry Flag.
- It is set (AC = 1) when there is a carry out from bit D3 to bit D4 (i.e., carry from the lower nibble to the upper nibble) during an arithmetic operation.
- It is primarily used in BCD (Binary Coded Decimal) arithmetic operations (DAA instruction).
- Example: If 0FH + 01H = 10H, a carry is generated from bit 3 to bit 4, so AC = 1.
4. Parity Flag (P)
- After an operation, if the result has an even number of 1s, the Parity flag is set (P = 1) -- indicating even parity.
- If the result has an odd number of 1s, the flag is reset (P = 0) -- indicating odd parity.
- Example: Result = 00000011 (two 1s, even parity), so P = 1.
5. Carry Flag (CY)
- The Carry flag is set (CY = 1) when an arithmetic operation results in a carry out from the MSB (bit D7) during addition, or a borrow during subtraction.
- If there is no carry or borrow, it is reset (CY = 0).
- Example: FFH + 01H = 100H; the carry out of bit 7 sets CY = 1.
Summary Table
| Flag | Symbol | Set (= 1) When |
|---|---|---|
| Sign | S | Result is negative (D7 = 1) |
| Zero | Z | Result is zero |
| Auxiliary Carry | AC | Carry from D3 to D4 |
| Parity | P | Result has even number of 1s |
| Carry | CY | Carry out from D7 (MSB) |
These five flags together help the programmer to make conditional decisions (using conditional jump instructions like JZ, JC, JP, etc.) based on the outcome of operations.
Instruction Types
2079 · 5 marks
Explain different types of instruction group of 8085. [5]
2078 · 5 marks
Differentiate between PUSH and POP instruction with example illustrating the use of these instruction. [5]
2076 · 5 marks
Differentiate between PUSH and POP instruction with example illustrating the use of these instructions. [5]
2076 · 5 marks
What is CALL operation? How does it differ with JUMP operation? [5]
2076 · 5 marks
What is instruction set? Explain various kinds of instructions of 8086 microprocessor. [5]
Show solved answerHide answer
Instruction Set and Types of Instructions in 8086 Microprocessor
Definition of Instruction Set
An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor supports is called the Instruction Set. Each instruction is represented by a binary value called an Op-code (Operation Code).
Types of Instructions in 8086 Microprocessor
The instructions of the 8086 microprocessor are grouped into the following categories:
1. Data Transfer Instructions
These instructions transfer data between registers, memory, and I/O ports.
| Instruction | Description |
|---|---|
MOV | Move data from source to destination |
PUSH | Push data onto the stack |
POP | Pop data from the stack |
IN | Input data from I/O port |
OUT | Output data to I/O port |
XCHG | Exchange contents of two operands |
2. Arithmetic Instructions
These instructions perform arithmetic operations such as addition, subtraction, multiplication, and division.
| Instruction | Description |
|---|---|
ADD | Add source to destination |
SUB | Subtract source from destination |
MUL | Unsigned multiplication |
DIV | Unsigned division |
INC | Increment operand by 1 |
DEC | Decrement operand by 1 |
3. Logical Instructions
These instructions perform bitwise logical operations.
| Instruction | Description |
|---|---|
AND | Bitwise AND of two operands |
OR | Bitwise OR of two operands |
XOR | Bitwise XOR of two operands |
NOT | Bitwise complement of operand |
CMP | Compare two operands |
4. Branch / Control Transfer Instructions
These instructions alter the normal sequential flow of program execution.
| Instruction | Description |
|---|---|
JMP | Unconditional jump to a particular address |
JC | Jump if Carry Flag (CF) = 1 |
JE / JZ | Jump if Equal / Zero Flag (ZF) = 1 |
JNC | Jump if CF = 0 |
JNE / JNZ | Jump if Not Equal / ZF = 0 |
JS | Jump if Sign Flag (SF) = 1 |
CALL | Call a subroutine/procedure |
RET | Return from subroutine to calling program |
5. Loop Instructions
These instructions repeat a block of instructions a specified number of times.
| Instruction | Description |
|---|---|
LOOP | Loop until CX = 0 |
LOOPE / LOOPZ | Loop while ZF = 1 and CX != 0 |
LOOPNE / LOOPNZ | Loop while ZF = 0 and CX != 0 |
6. Rotate and Shift Instructions
These instructions shift or rotate the bits of an operand.
| Instruction | Description |
|---|---|
ROL | Rotate bits left (MSB to LSB and CF) |
ROR | Rotate bits right (LSB to MSB and CF) |
RCL | Rotate bits left through Carry Flag |
RCR | Rotate bits right through Carry Flag |
SHL / SAL | Shift bits left logically/arithmetically |
SHR / SAR | Shift bits right logically/arithmetically |
7. Interrupt Instructions
These instructions handle interrupt operations.
| Instruction | Description |
|---|---|
INT | Software interrupt generated by I/O operations |
INTO | Interrupt only if Overflow Flag (OF) = 1 |
IRET | Return from interrupt procedure to main program |
Summary
The 8086 instruction set covers data movement, arithmetic, logic, branching, looping, bit manipulation, and interrupt handling, making it a complete and powerful instruction set for general-purpose computing.
2075 · 5 marks
What is instruction set? Explain various kinds of instructions of 8085 microprocessor. [5]
Show solved answerHide answer
Instruction Set and Types of Instructions in 8085 Microprocessor
Definition of Instruction Set
An instruction is a binary pattern designed inside a microprocessor to perform a specific function. The entire group of instructions that a microprocessor supports is called the Instruction Set.
- The 8085 microprocessor supports 246 instructions.
- Each instruction is represented by an 8-bit binary value called the Op-code or Instruction Byte.
Types (Kinds) of Instructions in 8085 Microprocessor
The instructions of the 8085 microprocessor are classified into the following categories:
1. Data Transfer Instructions
These instructions move data between registers, memory, and I/O ports without modifying the data.
| Instruction | Function |
|---|---|
| MOV | Move data from one register to another |
| MVI | Move immediate data to a register |
| LDA | Load accumulator from memory |
| STA | Store accumulator to memory |
| IN / OUT | Input/Output data from/to I/O port |
2. Arithmetic Instructions
These instructions perform arithmetic operations such as addition and subtraction.
| Instruction | Function |
|---|---|
| ADD | Add register or memory to accumulator |
| ADI | Add immediate data to accumulator |
| SUB | Subtract register or memory from accumulator |
| INR | Increment register by 1 |
| DCR | Decrement register by 1 |
3. Logical Instructions
These instructions perform logical (Boolean) operations on data.
| Instruction | Function |
|---|---|
| ANA | AND register with accumulator |
| ORA | OR register with accumulator |
| XRA | XOR register with accumulator |
| CMA | Complement the accumulator |
| CMP | Compare register with accumulator |
4. Branch / Jump Instructions
These instructions alter the normal sequential flow of a program by jumping to a specific address, either conditionally or unconditionally.
| Instruction | Function |
|---|---|
| JMP | Unconditional jump to a particular address |
| JC | Jump if Carry Flag (CF) = 1 |
| JNC | Jump if Carry Flag (CF) = 0 |
| JZ / JE | Jump if Zero Flag (ZF) = 1 |
| JNZ | Jump if Zero Flag (ZF) = 0 |
| CALL | Call a subroutine/procedure |
| RET | Return from subroutine to calling program |
5. Stack and Machine Control Instructions
These instructions control the stack operations and the overall machine state.
| Instruction | Function |
|---|---|
| PUSH | Push register pair onto the stack |
| POP | Pop data from stack to register pair |
| HLT | Halt the processor |
| NOP | No operation (do nothing for one cycle) |
| EI / DI | Enable / Disable interrupts |
6. Rotate Instructions
These instructions rotate the bits of the accumulator left or right.
| Instruction | Function |
|---|---|
| ROL / RLC | Rotate bits from MSB to LSB (left) |
| ROR / RRC | Rotate bits from LSB to MSB (right) |
| RCL / RAL | Rotate left through Carry Flag |
| RCR / RAR | Rotate right through Carry Flag |
Summary Table
| Category | Purpose |
|---|---|
| Data Transfer | Move data between registers/memory/I/O |
| Arithmetic | Add, subtract, increment, decrement |
| Logical | AND, OR, XOR, compare, complement |
| Branch/Jump | Change program flow conditionally or unconditionally |
| Stack/Control | Manage stack and machine state |
| Rotate | Shift/rotate bits in the accumulator |
The 8085 instruction set provides a complete set of operations allowing the microprocessor to perform arithmetic, logical, data movement, and program control tasks efficiently.
Jumps
Make Unit 4 stick
Practice CSC167 with flashcards & quizzes