How to add four data bytes using Stack in Intel 8085?

139 views Asked by At

I need to add 4 bytes of data 03H, 02H, 05H, 01H using the stack and store the result in 3350H in the i8085 microprocessor. The data bytes come from 4 contiguous memory locations starting 3300H. How to go about doing this? So far I have done this:

LXI SP,3599H    ;Stack initialised
MVI L,00H   
PUSH H
POP PSW         ;Flags Cleared
LXI H,3300H
PUSH H
INX H
PUSH H
INX H
PUSH H
INX H
PUSH H
MVI A,00H
POP B
ADD B
POP B
ADD B
POP B
ADD B
POP B
ADD B
STA 3350H
HLT    

I'm sure this isn't a good method because there is a lot ot repeating. Can there be some sort of loops to make it work better?

1

There are 1 answers

0
Bob Jarvis - Слава Україні On BEST ANSWER

The only way the "use the stack" bit seems to make sense is to set SP to 3300H, pop the data from the stack (3300H and 3301H) into a register pair (let's say BC), add B to A, add C to A, pop the next two data bytes into BC (3302H and 3303H), repeat the adds, then store A into 3350H. That way you're "using the stack" to get the data out of memory into registers so you can perform the math. Zero A before doing anything.

Best of luck.