This Program will add an Array of 8 bit Numbers with Carry.
Assume that the size of Array is stored at the location 2050H and Array starts from 3000H.
The Result will be stored from 4000H.
Memory Loc | Hex Code | Label | Mnemonics | Comment |
3050 3051 3052 | 3A 50 20 | START: | LDA 2050H | ;Take the Size of Array in A (Accumulator) |
3053 | 47 | MOV B, A | ;Store the Array Size in B | |
3054 3055 3056 | 21 00 30 | LXI H, 3000H | ;Initialize the Array pointer (HL Register Pair) with Address of First Element | |
3057 3058 | 16 00 | MVI D, 00H | ;Reset the Carry Holder (D Register) for Addition | |
3059 305A | 3E 00 | MVI A, 00H | ;Reset the Result Holder (Accumulator) | |
305B | 86 | LOOP: | ADD M | ;Add Accumulator Content with Each Element of Array |
305C 305D 305E | D2 60 30 | JNC NOCARRY | ;If Carry is not created don't increase Carry Holder | |
305F | 14 | INR D | ;If Carry is generated the Carry Holder will be increased by 1 | |
3060 | 23 | NOCARRY: | INX H | ;Point the next Element of the Array |
3061 | 05 | DCR B | ;Decrease the Loop Scope | |
3062 3063 3064 | C2 5B 30 | JNZ LOOP | ;If all element of the Array is not eveluated go back in Loop | |
3065 3066 3067 | 32 00 40 | STA 4000H | ;Store the LSByte of Result at Memory Location 4000H | |
3068 | 7A | MOV A, D | ;Move the MSByte of Result into A | |
3069 306A 306B | 32 01 40 | STA 4001H | ;Store the MSByte of Result at the Memory Location 4001H | |
306C | 76 | HLT | ;End of the Program |
This Program has a Drawback that, it can perform on Array of size atmost 255.
Comments