Program: ORG 8000 LXI H, 8091H LXI B, 8061H LDA B, 8060H // Result Store MOV D, A LOOP: LDAX B CMP M JNZ SKIP: INX H INX B DCR D JNZ LOOP MVI A, 00H STA, 8070H HLT SKIP: MVI A, FF STA, 8070H HLT

Program: ORG 8000 LXI H, 8091H LXI B, 8061H LDA B, 8060H // Result Store MOV D, A LOOP: LDAX B CMP M JNZ SKIP: INX H INX B DCR D JNZ LOOP MVI A, 00H STA, 8070H HLT SKIP: MVI A, FF STA, 8070H HLT

The Correct Answer and Explanation is:

🔧 Corrected Assembly Code for Clarity:

asmCopyEditLXI H, 8091H       ; HL points to data to be compared
LXI B, 8061H       ; BC points to data list start
LDA 8060H          ; A <- Count (number of bytes to compare)
MOV D, A           ; Store count in D (loop counter)

LOOP: LDAX B       ; A <- [BC] (load byte from data list)
CMP M              ; Compare with value at HL
JNZ SKIP           ; If not equal, jump to SKIP
INX H              ; Increment HL to next value to compare
INX B              ; Increment BC to next byte in list
DCR D              ; Decrement count
JNZ LOOP           ; If more bytes left, continue loop

MVI A, 00H         ; If all matched, store 00H
STA 8070H
HLT

SKIP: MVI A, FFH   ; If mismatch, store FFH
STA 8070H
HLT

Correct Result Stored at 8070H:

  • If all N bytes in memory starting at 8061H match N bytes starting at 8091H, then 8070H = 00H.
  • If any mismatch occurs, then 8070H = FFH.

So, the program performs byte-by-byte comparison of two sequences, and:

  • Stores 00H if all match.
  • Stores FFH if any mismatch.

📘 Textbook-Style Explanation (300 Words):

This 8085 microprocessor program compares two blocks of memory and sets a flag value depending on whether they are identical. The number of bytes to be compared is first loaded from memory address 8060H using the LDA instruction. This value is stored in register D to act as a loop counter.

Two register pairs are initialized using LXI instructions: HL is set to point to the beginning of the first memory block (starting at 8091H), and BC is set to point to the second memory block (starting at 8061H).

Inside the loop, the program fetches a byte from the memory location pointed to by BC using the LDAX B instruction and compares it to the byte pointed to by HL using the CMP M instruction. If the bytes do not match, control jumps to the label SKIP, where the accumulator is loaded with FFH to indicate mismatch, and this value is stored at memory location 8070H using STA.

If the bytes match, both HL and BC are incremented to point to the next bytes, and the counter D is decremented. If D is not zero, the loop repeats. If all comparisons are successful, the loop completes and the accumulator is loaded with 00H, indicating a successful match. This value is stored in memory location 8070H.

Finally, the program halts using HLT. Thus, the memory location 8070H acts as a result flag: 00H if blocks match entirely, or FFH if any mismatch is found.

Scroll to Top