2081 3

CSC167 · 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.

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]

MicroprocessorChapter 4: Assembly Language ProgrammingSimple sequence programsNumerical: 8085 assembly sum program

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

  1. Initialize carry register $C = 00H$
  2. Initialize counter $B = 0AH$ (10 items)
  3. Point HL to 6000H
  4. Clear accumulator ($A = 00H$)
  5. Add memory content to A; if carry occurs, increment C
  6. Advance pointer, decrement counter, repeat until zero
  7. 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

InstructionOperation
MVI C, 00HCarry counter initialized to zero
MVI B, 0AHLoop counter = 10
LXI H, 6000HHL points to first data location
SUB AClears A to 00H
ADD MAdds memory content to accumulator
JNC SKIPSkip if no carry produced
INR CIncrement carry register on overflow
INX HAdvance pointer
DCR BDecrement counter
JNZ BACKLoop until all 10 added
STA 9500HStore final sum
MOV A, CMove carry count to A
STA 9501HStore carry byte
HLTStop

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 A clears 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.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.