8085
MICROPROCESSOR –
PRACTICAL
QUESTIONS
1. Add two 8-bit numbers
Q: Add numbers stored at 2000H and
2001H. Store result at 2002H.
Program:
LDA 2000H
MOV B, A
LDA 2001H
ADD B
STA 2002H
HLT
-------------------------------------
Step-by-Step Processing
|
Step |
Instruction |
Operation Performed |
Registers After Execution |
|
1 |
LDA 2000H |
Load contents of 2000H into the Accumulator |
A = 25H |
|
2 |
MOV B, A |
Copy Accumulator content to
Register B |
B = 25H |
|
3 |
LDA 2001H |
Load contents of 2001H into
Accumulator |
A = 15H |
|
4 |
ADD B |
Add B to Accumulator (A = A + B) |
A = 3AH |
|
5 |
STA 2002H |
Store the Accumulator result into
2002H |
2002H = 3AH |
|
6 |
HLT |
Stop program execution |
— |
Output (Final Result)
|
Memory Address |
Data |
|
2002H |
3AH |
====================================================
2. Add two 16-bit numbers
Q: Add 16-bit numbers at
2000H–2001H and 2002H–2003H.
LHLD 2000H
XCHG
LHLD 2002H
DAD D
SHLD 2004H
HLT
---------------------------------------
Assumed Memory Contents (Example)
|
Memory Address |
Data (Hex) |
|
2000H |
34H |
|
2001H |
12H |
|
2002H |
78H |
|
2003H |
56H |
Step-by-Step Processing
|
Step |
Register/Memory |
Value |
|
HL after LHLD 2000H |
HL |
1234H |
|
After XCHG |
DE |
1234H |
|
HL after LHLD 2002H |
HL |
5678H |
|
After DAD D |
HL |
68ACH |
|
Stored result |
2004H–2005H |
68ACH |
Final Output (Memory Contents)
|
Address |
Data |
|
2004H |
ACH |
|
2005H |
68H |
Result = 68ACH
===========================================================
3. Subtract two 8-bit numbers
Q: Subtract the content of 2001H from
2000H.
LDA 2000H
MOV B, A
LDA 2001H
SUB B
STA 2002H
HLT
-------------------------------------------------------------------------------------
Assumed Input Data
|
Memory Address |
Data (Hex) |
|
2000H |
05H |
|
2001H |
09H |
Step-by-Step Execution
|
Step |
Instruction |
Operation Performed |
|
1 |
LDA 2000H |
A ← [2000H] → A = 05H |
|
2 |
MOV B, A |
B ← A → B = 05H |
|
3 |
LDA 2001H |
A ← [2001H] → A = 09H |
|
4 |
SUB B |
A ← A − B → A = 09H − 05H = 04H |
|
5 |
STA 2002H |
[2002H] ← A → 04H stored |
|
6 |
HLT |
Program execution stops |
Output
|
Memory Address |
Result |
|
2002H |
04H |
✔ Carry Flag (CY) = 0 (No borrow)
✔
Result is positive
Note:- If the result is Negative
(Example)
Assume:
2000H = 09H
2001H = 05H
Then:
A = 05H − 09H = FCH (2’s complement form)
CY = 1 (Borrow occurred)
|
Memory Address |
Data |
|
2002H |
FCH |
Output:
2002H ← Difference
==============================================================
4. Multiply two 8-bit numbers (Repeated Addition)
LDA 2000H
MOV B, A
LDA 2001H
MOV C, A
MVI A, 00H
LOOP: ADD B
DCR C
JNZ LOOP
STA 2002H
HLT
------------------------------------------------------------------------------------
Purpose of the Program
To multiply two 8-bit numbers using
repeated addition
- Number
at 2000H → Multiplicand
- Number
at 2001H → Multiplier
- Result
stored at 2002H
Assumed Input (Example)
|
Memory Address |
Data (Hex) |
Meaning |
|
2000H |
04H |
Multiplicand |
|
2001H |
03H |
Multiplier |
Expected result:
04H × 03H = 0CH
Step-by-Step Processing
|
Loop |
A (Accumulator) |
B |
C |
Operation |
|
Start |
00H |
04H |
03H |
— |
|
1st |
04H |
04H |
02H |
A = A + B |
|
2nd |
08H |
04H |
01H |
A = A + B |
|
3rd |
0CH |
04H |
00H |
A = A + B |
Loop Execution
Loop runs C times (3 times)
|
Loop |
A (Accumulator) |
B |
C |
Operation |
|
Start |
00H |
04H |
03H |
— |
|
1st |
04H |
04H |
02H |
A = A + B |
|
2nd |
08H |
04H |
01H |
A = A + B |
|
3rd |
0CH |
04H |
00H |
A = A + B |
- When
C = 00H, JNZ LOOP fails
- Loop exits
Final Output
|
Memory Address |
Data |
|
2002H |
0CH |
✔ Result = 12 (decimal)
======================================================
5. Divide two
8-bit numbers
CODE
LDA 2000H
MOV B, A
LDA 2001H
MOV C, A
MVI D, 00H
LOOP: CMP C
JC DONE
SUB C
INR D
JMP LOOP
DONE: STA 2002H
MOV A, D
STA 2003H
HLT
-------------------------------------------------------------------------------------------
Assumed Input
|
Memory Location |
Data |
|
2000H |
14H (20 decimal) |
|
2001H |
04H (4 decimal) |
Step-by-Step Processing
Step 1: Load Dividend
LDA 2000H
A ← 14H
MOV B, A
B ← 14H
Step 2: Load Divisor
LDA 2001H
A ← 04H
MOV C, A
C ← 04H
Step 3: Initialize Quotient
MVI D, 00H
D ← 00H
Step 4: Start Loop (Repeated
Subtraction)
Loop 1
CMP C
A (14H) ≥ C (04H) → No carry →
Continue
SUB C
A = 14H − 04H = 10H
INR D
D = 01H
Loop 2
A = 10H
A ≥ 04H → Subtract
A = 0CH
D = 02H
Loop 3
A = 0CH
A ≥ 04H → Subtract
A = 08H
D = 03H
Loop 4
A = 08H
A ≥ 04H → Subtract
A = 04H
D = 04H
Loop 5
A = 04H
A ≥ 04H → Subtract
A = 00H
D = 05H
Loop 6
CMP C
A (00H) < C (04H) → Carry set →
Jump to DONE
Final Output
|
Memory Location |
Result |
Meaning |
|
2002H |
00H |
Remainder |
|
2003H |
05H |
Quotient |
✔ Final Result:
20 ÷ 4 = 5 remainder 0
======================================================
6. Find the largest of the two numbers
Answer:- code
LDA 2000H ; Load first number into Accumulator
MOV B, A ; Copy first number to register B
LDA 2001H ; Load second number into Accumulator
CMP B ; Compare A with B (A − B)
JC STORE_B ; If A < B, jump to STORE_B
STA 2002H ; Else A is larger, store it
HLT
STORE_B:
MOV A, B ; Move B (largest) to Accumulator
STA 2002H; Store the largest number
HLT
Processing (Step-by-Step)
Assume:
- 2000H
= 3AH
- 2001H
= 27H
Step 1
LDA 2000H
Accumulator ← 3AH
Step 2
MOV B, A
Register B ← 3AH
Step 3
LDA 2001H
Accumulator ← 27H
Step 4
CMP B
Operation performed internally:
A − B = 27H − 3AH
Result is negative, so:
- Carry
flag = 1
Step 5
JC STORE_B
Since Carry = 1 → jump taken
(Control transfers to STORE_B)
Step 6
MOV A, B
Accumulator ← 3AH
Step 7
STA 2002H
Largest number (3AH) stored at
2002H
Step 8
HLT
Program execution stops
Output
|
Memory Address |
Data |
|
2000H |
3AH |
|
2001H |
27H |
|
2002H |
3AH (Largest) |
✔ Largest number = 3AH
=======================================================
7. Find the smallest of the two numbers
Answers:- code
LDA 2000H ; Load first number into Accumulator
MOV B, A ; Copy first number to register B
LDA 2001H ; Load second number into Accumulator
CMP B ; Compare A with B (A − B)
JC SMALL ; If A < B, jump to SMALL
MOV A, B ; Else, move B (smaller) to A
SMALL: STA 2002H ; Store smallest
number
HLT ; Stop execution
Processing (Step-by-Step)
assume:
|
Memory Location |
Data (Hex) |
|
2000H |
35H |
|
2001H |
2AH |
Step 1
LDA 2000H
- Accumulator
← 35H
Step 2
MOV B, A
- Register
B ← 35H
Step 3
LDA 2001H
- Accumulator
← 2AH
Step 4
CMP B
- Internally
compares:
A − B = 2AH − 35H - The result is negative
- Carry
flag = 1
Step 5
JC SMALL
- Carry
= 1 → Jump taken
- The accumulator already contains a smaller number (2AH)
Step 6
STA 2002H
- Store
2AH at memory location 2002H
Step 7
HLT
- Program
stops
Output
|
Memory Location |
Result |
|
2002H |
2AH (Smallest number) |
Case Analysis
|
Condition |
Carry Flag |
Stored Value |
|
First < Second |
CY = 1 |
First number |
|
First > Second |
CY = 0 |
Second number |
|
Equal |
CY = 0 |
Any one (same) |
=============================================================
8. Find the largest
number in an array
Answer:-
Assumptions:-
·
Starting
address of array: 2000H
·
Number
of elements (N): stored at 2000H
·
Array
data starts from 2001H
·
Result
(largest number) stored at 2100H
Program (Answer)
LXI H, 2000H ; HL points to count
MOV C, M ; C ← number of elements (N)
INX H ; HL points to first data element
MOV A, M ; A ← first element
DCR C ; Decrease count
LOOP: INX H ; Point to next element
CMP M ; Compare A with memory
JNC SKIP ; If A ≥ M, skip update
MOV A, M ; Else A ← new larger value
SKIP: DCR C
JNZ LOOP
STA 2100H ; Store largest number
HLT
Memory Contents Before Execution
|
Address |
Data (Hex) |
Description |
|
2000H |
05H |
Number of elements |
|
2001H |
2AH |
Array element 1 |
|
2002H |
45H |
Array element 2 |
|
2003H |
1CH |
Array element 3 |
|
2004H |
60H |
Array element 4 |
|
2005H |
38H |
Array element 5 |
Processing
(Step-by-Step)
Step 1: Initialize
- HL
→ 2000H
- C
← 05H (number of elements)
- HL
→ 2001H
- A
← 2AH (first element)
Step 2: Compare Loop Execution
|
Comparison |
A (Accumulator) |
Memory |
Result |
|
A vs 45H |
2AH vs 45H |
45H larger |
A ← 45H |
|
A vs 1CH |
45H vs 1CH |
A larger |
No change |
|
A vs 60H |
45H vs 60H |
60H larger |
A ← 60H |
|
A vs 38H |
60H vs 38H |
A larger |
No change |
Step 3: Store Result
- Final
value in A = 60H
- Stored
at 2100H
Output (Memory Contents After
Execution)
|
Address |
Data |
|
2100H |
60H |
==================================================
9. Check even or
odd number
Logic / Principle (Processing
Logic)
- An
even number has LSB = 0
- An
odd number has LSB = 1
- LSB
using ANI 01H
- Result
= 00H → EVEN
- Result
= 01H → ODD
Input & Output
|
Parameter |
Memory Address |
|
Input number |
2000H |
|
Output result |
2001H |
Output Meaning:
- 00H
→ Even number
- 01H
→ Odd number
8085 Program
LDA 2000H ; Load number into Accumulator
ANI 01H ; Mask LSB
STA 2001H ; Store result
HLT ; Stop execution
Processing (Step-by-Step Execution)
Assume Input:
Memory Location 2000H = 25H
Binary Representation:
25H = 0010 0101
Step Execution Table
|
Step |
Instruction |
Operation |
Accumulator |
|
1 |
LDA 2000H |
Load 25H |
25H |
|
2 |
ANI 01H |
25H AND 01H |
01H |
|
3 |
STA 2001H |
Store result |
01H |
|
4 |
HLT |
Stop |
— |
Output
Memory Location 2001H = 01H
Interpretation:
Number is ODD
Another Example (Even Number)
Input:
2000H = 24H → 0010 0100
AND Operation:
0010 0100
0000 0001
-----------
0000 0000
Output:
2001H = 00H
Interpretation:
Number is EVEN
==========================================================
10. Complement a number
Program
LDA 2000H ; Load data from 2000H into A
CMA ; Complement accumulator (1's
complement)
STA 2001H ; Store result at 2001H
HLT ; Stop program
Processing (Step-by-Step Execution)
Assume:
Memory location 2000H = 3AH
Binary of 3AH:
3A(H) = 0011 1010 (Binary)
Instruction Execution Table
|
Step |
Instruction |
Operation Performed |
Accumulator Content |
|
1 |
LDA 2000H |
Load data from memory |
0011 1010 |
|
2 |
CMA |
Complement bits |
1100 0101 |
|
3 |
STA 2001H |
Store result |
1100 0101 |
|
4 |
HLT |
Halt program |
— |
Output
Memory Contents After Execution
|
Memory Address |
Data (Hex) |
Data (Binary) |
|
2000H |
3A |
0011 1010 |
|
2001H |
C5 |
1100 0101 |
✔ Output = C5H
Explanation
- The
CMA instruction in 8085 performs 1’s complement.
- Each
bit is inverted:
- 0
→ 1
- 1
→ 0
==============================================================
11. Find 2’s
complement
8085 Program
LDA 2000H ; Load number into accumulator
CMA ; 1's complement of A
INR A ; Add 1 to get 2's complement
STA 2001H ; Store result
HLT ; Stop
Processing (Step-by-Step Execution)
Assume Input:
Memory Location Data
2000H 25H
Execution Details:
|
Step |
Instruction |
Accumulator (A) |
Explanation |
|
1 |
LDA 2000H |
25H |
Load number |
|
2 |
CMA |
DAH |
1’s complement of 25H |
|
3 |
INR A |
DBH |
Add 1 → 2’s complement |
|
4 |
STA 2001H |
DBH |
Store result |
|
5 |
HLT |
— |
Program ends |
Output
Memory Location Data
2001H DBH
✔ DBH is the 2’s complement of 25H
Binary Verification (Optional – for
clarity)
25H = 0010 0101
1’s Complement = 1101 1010
2’s Complement = 1101 1011 = DBH
===============================================
12. Transfer block of data
Problem Statement
Write an 8085 program to transfer a
block of N bytes of data from one memory location to another.
Assumptions
|
Purpose |
Address |
|
Source start address |
2000H |
|
Destination start address |
3000H |
|
Number of bytes (N) |
05H |
|
Register pair HL |
Source pointer |
|
Register pair DE |
Destination pointer |
|
Register C |
Counter |
Program (Answer)
LXI H, 2000H ; HL points to source block
LXI D, 3000H ; DE points to destination block
MVI C, 05H ; Number of bytes to transfer
LOOP: MOV A, M; Copy data from source to A
STAX D : Store data from A to the destination
INX H ; Increment source address
INX D ; Increment destination address
DCR C ; Decrement counter
JNZ LOOP ; Repeat until C = 0
HLT
Processing (Step-by-Step Working)
Initial Memory Contents (Example)
|
Source (2000H–2004H) |
Data |
|
2000H |
25H |
|
2001H |
36H |
|
2002H |
48H |
|
2003H |
52H |
|
2004H |
61H |
Execution Flow
Step 1: Initialization
- HL
= 2000H → Source start
- DE
= 3000H → Destination start
- C
= 05H → Number of bytes
Step 2: First Iteration
- MOV
A, M → A = 25H
- STAX
D → 25H stored at 3000H
- HL
= 2001H
- DE
= 3001H
- C
= 04H
Step 3: Second Iteration
- A
= 36H
- Stored
at 3001H
- HL
= 2002H
- DE
= 3002H
- C
= 03H
Step 4: Continue Loop
This repeats until:
- All
5 bytes are transferred
- Counter
C becomes 00H
Step 5: Termination
- JNZ
LOOP fails when C = 0
- HLT
stops execution
Output
Destination Memory After Execution
|
Destination (3000H–3004H) |
Data |
|
3000H |
25H |
|
3001H |
36H |
|
3002H |
48H |
|
3003H |
52H |
|
3004H |
61H |
✔ Block successfully transferred
=======================================================
13. Exchange two
memory locations
Assumption
- First
memory location: 2000H
- Second
memory location: 2001H
Initial Data (Example)
|
Memory Address |
Data |
|
2000H |
3AH |
|
2001H |
7CH |
Program (Answer)
LDA 2000H
MOV B, A
LDA 2001H
STA 2000H
MOV A, B
STA 2001H
HLT
Step-by-Step Processing (Execution)
|
Step |
Instruction |
Operation Performed |
|
1 |
LDA 2000H |
Load content of 2000H (3AH) into
Accumulator |
|
2 |
MOV B, A |
Copy A → B (B = 3AH) |
|
3 |
LDA 2001H |
Load content of 2001H (7CH) into
Accumulator |
|
4 |
STA 2000H |
Store A (7CH) into 2000H |
|
5 |
MOV A, B |
Copy B (3AH) into Accumulator |
|
6 |
STA 2001H |
Store A (3AH) into 2001H |
|
7 |
HLT |
Stop program execution |
Final Output (After Execution)
|
Memory Address |
Data |
|
2000H |
7CH |
|
2001H |
3AH |
✔ Contents successfully exchanged
Register Status (Important)
|
Register |
Value |
|
A |
3AH |
|
B |
3AH |
==================================================================
14. Reverse an
array
Assumptions (Very Important in Exam)
- 2000H
→ Number of elements (N)
- 2001H
onwards → Array elements
- 2100H
onwards → Reversed array
Example Input (Before Execution)
|
Memory Address |
Data |
|
2000H |
05H |
|
2001H |
11H |
|
2002H |
22H |
|
2003H |
33H |
|
2004H |
44H |
|
2005H |
55H |
Array = [11H, 22H, 33H, 44H, 55H]
8085 Assembly
Program
LXI H, 2000H ; HL points to count
MOV C, M ; C ← N
INX H ; HL points to first data
LXI D, 2100H ; DE points to destination
DAD B ; Not used (safe ignore)
MOV A, C
ADD L
MOV L, A
JNC SKIP
INR H
SKIP:
DCX H ; HL points to last element
LOOP:
MOV A, M ; Read element from end
STAX D ; Store in destination
INX D ; Next destination
DCX H ; Previous source
DCR C ; Decrease count
JNZ LOOP
HLT
Processing
(Step-by-Step)
Step 1: Initialization
- HL
→ 2000H (count)
- C
← 05H (number of elements)
- HL
→ 2001H (first element)
- DE
→ 2100H (destination start)
Step 2: HL moved to last element
- Last
element address = 2001H + (5 − 1)
- HL
→ 2005H
Step 3: Loop Execution
|
Iteration |
Source (HL) |
Data |
Destination (DE) |
|
1 |
2005H |
55H |
2100H |
|
2 |
2004H |
44H |
2101H |
|
3 |
2003H |
33H |
2102H |
|
4 |
2002H |
22H |
2103H |
|
5 |
2001H |
11H |
2104H |
Step 4: Program Stops
- Counter
C becomes 00H
- HLT
executed
Output (After Execution)
Memory Contents (Reversed Array)
|
Address |
Data |
|
2100H |
55H |
|
2101H |
44H |
|
2102H |
33H |
|
2103H |
22H |
|
2104H |
11H |
Final Result
Original Array:
11H → 22H → 33H → 44H → 55H
Reversed Array:
55H → 44H → 33H → 22H → 11H
================================================================
15. Sort the array in
ascending order
Problem Statement
Write an 8085 assembly language
program to sort an array of numbers in ascending order using Bubble Sort
technique.
Assumptions
(Memory Map)
|
Memory Location |
Data |
|
2000H |
N (number of elements) |
|
2001H onwards |
Array elements |
|
2001H onwards |
Sorted array (result) |
Example Input:
|
Address |
Data (Hex) |
|
2000H |
05 |
|
2001H |
34 |
|
2002H |
12 |
|
2003H |
56 |
|
2004H |
09 |
|
2005H |
23 |
8085 Assembly
Program
LXI H, 2000H ; HL → count location
MOV C, M ; C = N
DCR C ; Outer loop count = N-1
OUTER: LXI H, 2001H ; Point to first element
MOV B, C ; Inner loop counter
INNER: MOV A, M ; A = current element
INX H
CMP M ; Compare with next element
JC SKIP ; If A < next, no swap
; Swap
MOV D, M
MOV M, A
DCX H
MOV M, D
INX H
SKIP: DCR B
JNZ INNER
DCR C
JNZ OUTER
HLT
Processing
(Step-by-Step Execution)
Initial Array
34
12 56 09 23
Pass 1
- Compare
34 & 12 → Swap → 12 34 56 09 23
- Compare
34 & 56 → No swap
- Compare
56 & 09 → Swap → 12 34 09 56 23
- Compare
56 & 23 → Swap → 12 34 09 23 56
Pass 2
- Compare
12 & 34 → No swap
- Compare
34 & 09 → Swap → 12 09 34 23 56
- Compare
34 & 23 → Swap → 12 09 23 34 56
Pass 3
- Compare
12 & 09 → Swap → 09 12 23 34 56
- Remaining
comparisons → No swap
Pass 4
- No
swaps → Array sorted
Final Output
(Sorted Array)
|
Address |
Data (Hex) |
|
2001H |
09 |
|
2002H |
12 |
|
2003H |
23 |
|
2004H |
34 |
|
2005H |
56 |
=========================================================
16. Sum of N
numbers
Problem Statement
Write an 8085 assembly language
program to find the sum of N numbers stored in consecutive memory locations.
Assumptions
|
Item |
Value |
|
Count (N) |
Stored at 2000H |
|
Data starts from |
2001H onwards |
|
Result (Sum) |
Stored at 2100H |
|
Sum range |
8-bit (no carry handling) |
8085 Program
LDA 2000H ; Load count N
MOV C, A ; Move count to register C
MVI A, 00H ; Clear accumulator
LXI H, 2001H ; Point HL to data start
LOOP: ADD M ; Add data to accumulator
INX H ; Point to next memory location
DCR C ; Decrement count
JNZ LOOP ; Repeat if count ≠ 0
STA 2100H ; Store sum
HLT
Sample Input Data (Memory Map)
|
Memory Address |
Data |
|
2000H |
05H (N = 5) |
|
2001H |
02H |
|
2002H |
04H |
|
2003H |
06H |
|
2004H |
08H |
|
2005H |
0AH |
Step-by-Step Processing (Execution
Trace)
|
Step |
A (Accumulator) |
C (Count) |
HL Address |
Operation |
|
Initial |
00H |
05H |
2001H |
Initialization |
|
1 |
02H |
04H |
2002H |
00 + 02 |
|
2 |
06H |
03H |
2003H |
02 + 04 |
|
3 |
0CH |
02H |
2004H |
06 + 06 |
|
4 |
14H |
01H |
2005H |
0C + 08 |
|
5 |
1EH |
00H |
2006H |
14 + 0A |
Final Output
|
Memory Location |
Result |
|
2100H |
1EH (Decimal 30) |
Sum of 5 numbers = 30
================================================================
17. Find the average
of N numbers
Problem Statement
Write an 8085 program to find the
average of N 8-bit numbers stored in memory.
Assumptions (Standard Lab
Convention)
|
Item |
Address |
|
Count (N) |
2000H |
|
Numbers |
From 2001H onwards |
|
Result (Average) |
2010H |
8085 Assembly
Program
LDA 2000H ; Load count N
MOV C, A ; Counter = N
LXI H, 2001H ; HL points to first number
MVI A, 00H ; Clear accumulator (sum)
ADD_LOOP:
ADD M ; A = A + [HL]
INX H ; Next memory location
DCR C ; Decrease count
JNZ ADD_LOOP ; Repeat until count = 0
; Divide sum by N
MOV B, A ; Store sum in B
LDA 2000H ; Load N
MOV C, A ; C = N
MVI A, 00H ; Clear A (quotient)
DIV_LOOP:
CMP B
JC STORE
SUB C
INR A
JMP DIV_LOOP
STORE:
STA 2010H ; Store average
HLT
Sample Input Data (Example)
|
Address |
Data |
|
2000H |
04H (N = 4) |
|
2001H |
10H (16) |
|
2002H |
20H (32) |
|
2003H |
30H (48) |
|
2004H |
40H (64) |
Processing (Step-by-Step Execution)
Step 1: Sum Calculation
10H + 20H + 30H + 40H
= A0H (160 decimal)
Step 2: Average Calculation
Average = Sum / N
Average = A0H / 04H
Average = 28H (40 decimal)
Output
|
Address |
Result |
|
2010H |
28H (Average) |
The average of the given N numbers
is stored at memory location 2010H.
=========================================================
18. Check a palindrome number
Problem Statement
Write an 8085 microprocessor
program to check whether an 8-bit number is a palindrome or not.
A number is a palindrome if it reads
the same forward and backward
Example: 33H, 55H, 99H
Input / Output Specification
|
Item |
Address |
|
Input number |
2000H |
|
Output result |
2001H |
Output Convention:
- 01H
→ Palindrome
- 00H
→ Not Palindrome
8085 Program
LDA 2000H ; Load number into A
MOV B, A ; Store original number in B
MVI C, 08H ; Initialize counter (8 bits)
MVI A, 00H ; Clear accumulator for reverse
LOOP: RRC ; Rotate right
RAL
; Rotate left to form reversed number
DCR C
JNZ LOOP
CMP B ; Compare reversed number with
original
JZ PALIN
MVI A, 00H ; Not Palindrome
STA 2001H
HLT
PALIN: MVI A, 01H
STA 2001H
HLT
Step-by-Step
Processing (Execution)
Example Input
Memory Location 2000H = 55H
(01010101)
Execution Flow
|
Step |
Instruction |
Register State |
|
1 |
LDA 2000H |
A = 55H |
|
2 |
MOV B,A |
B = 55H |
|
3 |
MVI C,08H |
Counter = 8 |
|
4 |
Rotate loop |
Reverse bits |
|
5 |
CMP B |
Compare reversed with original |
|
6 |
JZ PALIN |
Jump if equal |
Output
Case 1: Palindrome Number
Input: 55H
Output at 2001H = 01H
Case 2: Not a Palindrome Number
Input: 52H
Output at 2001H = 00H
=================================================================
19. Check a positive
or negative number
Problem Statement
Write an 8085 program to check
whether a given 8-bit number is positive or negative.
Concept Used
- In
8085, numbers are represented in 2’s complement.
- The
Most Significant Bit (D7) decides the sign:
- D7
= 0 → Positive number
- D7
= 1 → Negative number
- RAL
(Rotate Accumulator Left) shifts D7 into Carry flag.
Program (8085 Assembly)
LDA 2000H ; Load the number from memory
RAL ; Rotate left, MSB goes to Carry
flag
JC NEG ; If Carry = 1, number is negative
MVI A, 01H ; Positive → store 01H
STA 2001H
HLT
NEG: MVI A, 00H ; Negative → store 00H
STA 2001H
HLT
Processing (Step-by-Step Execution)
Assume two cases:
Case 1: Positive Number
Memory Content:
2000H = 25H → 0010 0101
|
Step |
Instruction |
Operation |
|
1 |
LDA 2000H |
A ← 25H |
|
2 |
RAL |
MSB = 0 → Carry = 0 |
|
3 |
JC NEG |
No jump (Carry = 0) |
|
4 |
MVI A,01H |
Load 01H |
|
5 |
STA 2001H |
Store 01H |
|
6 |
HLT |
Stop |
Case 2: Negative Number
Memory Content:
2000H = F6H → 1111 0110 (−10)
|
Step |
Instruction |
Operation |
|
1 |
LDA 2000H |
A ← F6H |
|
2 |
RAL |
MSB = 1 → Carry = 1 |
|
3 |
JC NEG |
Jump to NEG |
|
4 |
MVI A,00H |
Load 00H |
|
5 |
STA 2001H |
Store 00H |
|
6 |
HLT |
Stop |
Output
|
Memory Location |
Value |
Meaning |
|
2001H |
01H |
Positive number |
|
2001H |
00H |
Negative number |
==============================================================
20. Generate the Fibonacci series
Problem Statement
Write an 8085 microprocessor
program to generate N terms of the Fibonacci series and store them in memory
locations starting from a given address.
Fibonacci Series
0, 1, 1, 2, 3, 5, 8, 13, ...
Each term = sum of previous two
terms.
Assumptions
|
Item |
Value |
|
Number of terms (N) |
Stored at 2000H |
|
Starting memory for series |
2001H onwards |
|
First term |
00H |
|
Second term |
01H |
8085 Program
LXI H, 2001H ; HL points to starting address
MVI A, 00H ; First Fibonacci number = 0
MOV M, A ; Store at 2001H
INX H
MVI B, 01H ; Second Fibonacci number = 1
MOV M, B ; Store at 2002H
INX H
LDA 2000H ; Load N (number of terms)
SUI 02H ; Remaining terms = N - 2
MOV C, A ; Counter in C
LOOP: ADD B ; A = A + B
MOV D, A ; Save new term in D
MOV A, B ; A = previous term
MOV B, D ; B = new term
MOV M, B ; Store term in memory
INX H
DCR C
JNZ LOOP
HLT
Processing (Step-by-Step)
Initial Values
|
Register |
Value |
|
A |
00H |
|
B |
01H |
|
HL |
2001H |
|
C |
N − 2 |
Memory Before Execution
|
Address |
Data |
|
2000H |
08H (example: N = 8 terms) |
Execution Steps
|
Step |
Operation |
Result |
|
1 |
Store 00H |
2001H ← 00 |
|
2 |
Store 01H |
2002H ← 01 |
|
3 |
Add A + B |
00 + 01 = 01 |
|
4 |
Store result |
2003H ← 01 |
|
5 |
Next addition |
01 + 01 = 02 |
|
6 |
Store result |
2004H ← 02 |
|
7 |
Continue loop |
Until C = 0 |
Output (Example)
If N = 8
|
Memory Address |
Data (Hex) |
Decimal |
|
2001H |
00H |
0 |
|
2002H |
01H |
1 |
|
2003H |
01H |
1 |
|
2004H |
02H |
2 |
|
2005H |
03H |
3 |
|
2006H |
05H |
5 |
|
2007H |
08H |
8 |
|
2008H |
0DH |
13 |
===============================================================
21. Square of a
number
Problem Statement
Write an 8085 program to find the
square of an 8-bit number using repeated addition.
The number is stored at memory location 2000H.
Store the result at 2001H (lower byte) and 2002H (higher byte, if any).
Program (8085
Assembly)
LDA 2000H ; Load number into Accumulator
MOV B, A ; Copy number to register B
MOV C, A ; Copy number to register C (counter)
MVI A, 00H ; Clear Accumulator (result = 0)
LOOP: ADD B ; Add number to accumulator
DCR C ; Decrement counter
JNZ LOOP ; Repeat until counter = 0
STA 2001H ; Store lower byte of result
HLT
Processing (Step-by-Step Execution)
Assume:
- Memory
2000H = 04H
|
Step |
Register / Action |
Value |
|
1 |
A ← 2000H |
04H |
|
2 |
B ← A |
04H |
|
3 |
C ← A |
04H |
|
4 |
A ← 00H |
00H |
|
5 |
A ← A + B |
04H |
|
6 |
C ← C − 1 |
03H |
|
7 |
A ← A + B |
08H |
|
8 |
C ← C − 1 |
02H |
|
9 |
A ← A + B |
0CH |
|
10 |
C ← C − 1 |
01H |
|
11 |
A ← A + B |
10H |
|
12 |
C ← C − 1 |
00H |
|
13 |
Loop ends |
— |
|
14 |
Store result |
10H |
Output
|
Memory Location |
Value |
|
2000H |
04H (Input) |
|
2001H |
10H (Square = 16 in decimal) |
✔ Square of 4 = 16
22. Factorial of a
number
Problem Statement
Write an 8085 assembly language
program to find the factorial of an 8-bit number stored at memory location
2000H.
Store the result at 2001H.
Note: Result is valid for small
numbers (≤ 5) since 8085 uses 8-bit registers.
8085 Assembly
Program
LDA 2000H ; Load number (N)
MOV B, A ; Copy N into B register
MVI A, 01H ; Initialize result = 1
LOOP:
MUL: ADD B ; Repeated addition (multiplication)
DCR B ; Decrement counter
JNZ LOOP ; Repeat until B = 0
STA 2001H ; Store factorial result
HLT
Example Execution (Processing)
Assume:
- Memory
Location 2000H = 04H
- We
need to calculate 4! = 4 × 3 × 2 × 1 = 24 (18H)
Step-by-Step Processing Table
|
Step |
Instruction |
A (Accumulator) |
B Register |
Explanation |
|
1 |
LDA 2000H |
04H |
— |
Load number |
|
2 |
MOV B,A |
04H |
04H |
Copy number |
|
3 |
MVI A,01H |
01H |
04H |
Initialize result |
|
4 |
ADD B |
05H |
04H |
Multiply by 4 |
|
5 |
DCR B |
05H |
03H |
Decrement |
|
6 |
ADD B |
08H |
03H |
Multiply by 3 |
|
7 |
DCR B |
08H |
02H |
Decrement |
|
8 |
ADD B |
0AH |
02H |
Multiply by 2 |
|
9 |
DCR B |
0AH |
01H |
Decrement |
|
10 |
ADD B |
0BH |
01H |
Multiply by 1 |
|
11 |
DCR B |
0BH |
00H |
Stop |
|
12 |
STA 2001H |
— |
— |
Store result |
Output
|
Memory Location |
Data |
|
2000H |
04H |
|
2001H |
18H (24 decimal) |
✔ Factorial of 4 successfully
computed.
===========================================================
0 Comments