-2

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?

Pallab Ganguly
  • 3,023
  • 2
  • 10
  • 10
  • 2
    Two questions: 1) Are you going to handle the overflow? 2) Why using the stack? I know this is an assignment but I'm missing how the stack could reasonably be used, unless... you are require to write a routine. – Margaret Bloom Jan 01 '17 at 12:56
  • No it is assumed that the values are small enough so that there isn't any overflow – Pallab Ganguly Jan 01 '17 at 12:59

1 Answers1

0

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.