beginner 2 steps
Add Two 8-bit Numbers
Read two bytes from memory, add them, and store the result. The smallest complete program that touches memory, registers and flags.
Two numbers are waiting in memory at 2000H and 2001H. Your job is to add
them and leave the answer at 2002H.
That sounds like one instruction, and on a modern processor it nearly would be. On the 8085 it is four ideas stacked on top of each other:
- Memory is not registers. You cannot add two memory locations directly, so values have to be brought into the CPU first.
- The accumulator is special. Arithmetic always involves
A. HLcan be used as a pointer into memory, andMmeans "the byteHLpoints at".- Addition can overflow. Eight bits hold
00HtoFFH; anything larger sets the carry flag.
You will build the program in two steps: first get the operands into registers, then do the arithmetic and store the answer.
Steps
- 1 Load the Operands
- 2 Add and Store the Result