In this program we will see how to add two 16-bit numbers.
Write8085 Assembly language program to add two 16-bit number stored in memory location 8000H – 8001H and 8002H – 8003H.
In this program we are pointing the operand addresses using HL and DE register pair. Then adding LSBytes by ADD operator, and after that adding MSBytes using ADC operator to consider the carry flag result. The 16-bit result will be stored at BC register, and by checking the carry bit after addition we can simply put 1 into memory.
We are taking two numbersBCAD + FE2D = 1BADA
Address | Data |
---|---|
... | ... |
8000 | AD |
8001 | BC |
8002 | 2D |
8003 | FE |
... | ... |
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 21, 00, 80 | LXI H,8000H | Point to LSB of first operand | |
F003 | 11, 02, 80 | LXI D,8002H | Point to LSB of second address | |
F006 | 1A | LDAX D | Load Acc with content pointed by DE | |
F007 | 86 | ADD M | Add memory element pointed by HL with Acc | |
F008 | 4F | MOV C, A | Store LSB result at C | |
F009 | 23 | INX H | Point to next byte of first operand | |
F00A | 13 | INX D | Point to next byte of second operand | |
F00B | 1A | LDAX D | Load Acc with content pointed by DE | |
F00C | 8E | ADC M | Add memory element pointed by HL with Acc+ Carry | |
F00D | 47 | MOV B,A | Store the MSB at B | |
F00E | 60 | MOV H,B | Move B to H | |
F00F | 69 | MOV L,C | Move C to L | |
F010 | 22, 50, 80 | SHLD 8050H | Store the result at 8050H and 8051H | |
F013 | D2, 1B, F0 | JNC DONE | Skip to end | |
F016 | 3E, 01 | MVI A, 01H | Load 1 to Acc | |
F018 | 32, 52, 80 | STA 8052H | Store Acc content into 8052H | |
F01B | 76 | DONE | HLT | Terminate the program |
Address | Data |
---|---|
... | ... |
8050 | DA |
8051 | BA |
8052 | 01 |
... | ... |