Explanation
Here is a clear and concise breakdown of the 8085 Assembly program:
1. Purpose
This program iterates through an array of 10 numbers starting at memory address 2050H, counts how many numbers are positive and how many are negative, and stores the final counts in memory.
2. Key Concepts
- Sign Flag Manipulation: Using
ORA Ato check whether a number is positive or negative by setting the Sign Flag ($S$) without altering the value in the Accumulator. - Conditional Branching: Using
JM(Jump on Minus) to direct execution based on the sign of the number, andJNZ(Jump if Not Zero) for loop iteration. - Counters and Pointers: Using the
HLregister pair as a memory pointer, registerDas a loop counter, and registersBandCas tally counters.
3. Code Walkthrough
-
Initialization:
LXI H, 2050H: Sets the memory pointer to the start of the data array (2050H).MVI B, 00H&MVI C, 00H: Clears RegisterB(positive counter) and RegisterC(negative counter).MVI D, 0AH: Sets the loop counter to 10 (decimal) in RegisterD.
-
Checking the Sign (
LOOP):MOV A, M: Reads the current number into AccumulatorA.ORA A: Logically ORsAwith itself. This updates the Sign Flag ($S=1$ if negative, $S=0$ if positive/zero).JM NEG: If the number is negative ($S=1$), jump to labelNEG.INR B&JMP NEXT: If positive, incrementBand skip over the negative counter.
-
Negative Handling & Loop Control (
NEG&NEXT):NEG: INR C: Increments the negative count.INX H: Moves pointer to the next memory location.DCR D&JNZ LOOP: Decrements loop counter; if it hasn’t reached zero, it repeats the process.
-
Storing Results & Termination:
STA 2060H: Stores the positive count (from RegisterB) into memory address2060H.STA 2061H: Stores the negative count (from RegisterC) into memory address2061H.HLT: Halts the CPU.
4. Output
2060H: Contains the total count of positive numbers (including zero).2061H: Contains the total count of negative numbers.