# 8085 programs to find 2’s compliment with carry | Set 2

**Problem-1:** Find 2’s compliment of an 8 bit number stored at address 2050. Result is stored at address 3050 and 3051. Starting address of program is taken as 2000.

**Example –**

**Algorithm –**

- We are taking compliment of the number using
**CMA**instruction. - Then adding 01 to the result.
- The carry generated while adding 01 is stored at 3051.

**Program –**

Memory Address | Mnemonics | Comment |
---|---|---|

2000 | LDA 2050 | A←2050 |

2003 | CMA | A←compliment of A |

2004 | INR A | A←A+01 |

2005 | MOV L, A | L←A |

2006 | MVI A 00 | A←00 |

2008 | ADC A | A←A+A+Carry |

2009 | MOV H, A | H←A |

200A | SHLD 3050 | L→3050, H→3051 |

200D | HLT |

**Explanation –** Registers used: **A, H, L**

**LDA 2050**loads content of 2050 in A**CMA**compliments the contents of A**INR A**increases A by 01**MOV L, A**copies contents of A in L**MVI A 00**moves 00 in A**ADC A**adds A, A, Carry and assigns it to A**MOV H, A**copies contents of A in H**SHLD 3050**stores value of H at memory location 3051 and L at 3050**HLT**stops executing the program and halts any further execution

**Problem-2:** Find 2’s compliment of a 16 bit number stored at address 2050 and 2051. Result is stored at address 3050, 3051 and 3052. Starting address of program is taken as 2000.

**Example –**

**Algorithm –**

- We are taking compliment of the numbers using
**CMA**instruction. - Then adding 0001 to the result using
**INX**instruction. - The carry generated while adding 0001 is stored at 3052.

**Program –**

Memory Address | Mnemonics | Comment |
---|---|---|

2000 | LHLD 2050 | L←2050, H←2051 |

2003 | MOV A, L | A←L |

2004 | CMA | A←compliment of A |

2005 | MOV L, A | L←A |

2006 | MOV A, H | A←H |

2007 | CMA | A←Compliment of A |

2008 | MOV H, A | H←A |

2009 | INX H | HL←HL+0001 |

200A | MVI A 00 | A←00 |

200C | ADC A | A←A+A+Carry |

200D | SHLD 3050 | L→3050, H→3051 |

2010 | STA 3052 | A→3052 |

2013 | HLT |

**Explanation –** Registers used: **A, H, L**

**LHLD 2050**loads content of 2051 in H and content of 2050 in L**MOV A, L**copies contents of L in A**CMA**compliments contents of A**MOV L, A**copies contents of A in L**MOV A, H**copies contents of H in A**CMA**compliments contents of A**MOV H, A**copies contents of A in H**INX H**adds 0001 in HL**MVI A 00**moves 00 in A**ADC A**adds A, A, Carry and stores result in A**SHLD 3050**stores value of H at memory location 3051 and L at 3050**STA 3052**stores value of A at memory location 3052**HLT**stops executing the program and halts any further execution

Refer for – 8085 program to find 1’s and 2’s complement of 8-bit number

8085 program to find 1’s and 2’s complement of 16-bit number

## Recommended Posts:

- 8085 program to sum of two 8 bit numbers without carry
- 2's compliment for a givin string using XOR
- 8085 program to find the set bit of accumulator
- 8085 program to find the sum of a series
- 8085 program to find maximum of two 8 bit numbers
- 8085 program to find the sum of first n natural numbers
- 8085 program to find the element that appears once
- 8085 program to find the factorial of a number
- 8085 program to find nth power of a number
- 8085 program to find sum of digits of 8 bit number
- 8085 program to find square of a 8 bit number
- 8085 program to find 1’s and 2’s complement of 16-bit number
- 8085 program to find 1's and 2's complement of 8-bit number
- 8085 program to find larger of two 8 bit numbers
- 8085 program to find the sum of series of even numbers

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.