0
\$\begingroup\$

I have a question on 8085 instruction set. A program to add 6 bytes of data stored in memory starting from 4500h. must use b register to save any carries and finally store the sum and carry at two consecutive memory locations 3000h and 3001h.

I wrote the following for it.

ACI 4500h
ACI 4501h
ACI 4502h
ACI 4503h
ACI 4504h
ACI 4505h
STA 3000h
HLT

So, is this right and even if it is can you make some suggestions to make it better like make a loop instead of repeating ACI six times and so on.

Suggest any think that you think would help me learn more about this program.

Thanks in advance.

\$\endgroup\$
  • \$\begingroup\$ Unfamiliar with the instruction set for 8085, but it seems you don't initialize the register. So you are adding six bytes to whatever is there already. Advantage of a loop is possibly shorter code, but it will execute slower too because more instructions need to be executed. Alse, are you sure you are adding the values at the adress 450x or are you adding the 16-bit values 4500+4501+45.... ? \$\endgroup\$ – jippie Jan 18 '14 at 17:51
  • \$\begingroup\$ Your first instruction should be a clear or load, not an add. ACI is "add immediate" - it will add the 4500h, 4501h, etc., not the contents of those addresses. The ADD instructions are all 8 bit, so you'll need to do a bit more work than your attempt above shows. \$\endgroup\$ – Peter Bennett Jan 18 '14 at 19:56
1
\$\begingroup\$

Ah, more computer archaeology! I'm just going to give you a solution here, since it would take too long to address the misconceptions in your code. Study it and make sure you know exactly what each instruction is doing and why.

        ;; HL points to array of bytes to be added
        ;; DE contains 16-bit sum
        ;; C is loop counter

        lxi     h, 4500h        ; point to first byte
        mov     e, m            ; fetch first byte
        mvi     d, 0            ; clear high byte of sum
        mvi     c, 5            ; add 5 more bytes
loop:
        inx     h               ; point to next byte
        mov     a, m            ; fetch next byte
        add     e               ; add to sum
        mov     e, a
        jnc     skip            ; if carry ...
        inr     d               ; increment high byte of sum
skip:
        dcr     c               ; decrement loop counter
        jnz     loop            ; repeat if not done

        ;; Store the result
        xchg                    ; move sum to HL
        shld    3000h

        hlt
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.