Open In App

8085 programs to find 2’s complement with carry | Set 2

Last Updated : 07 May, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Problem-1: Find 2’s complement 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 – 

  1. We are taking complement of the number using CMA instruction.
  2. Then adding 01 to the result.
  3. The carry generated while adding 01 is stored at 3051.

Program – 
 

Memory Address Mnemonics Comment
2000 LDA 2050 A←2050
2003 CMA A←complement 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 

  1. LDA 2050 loads content of 2050 in A
  2. CMA complements the contents of A
  3. INR A increases A by 01
  4. MOV L, A copies contents of A in L
  5. MVI A 00 moves 00 in A
  6. ADC A adds A, A, Carry and assigns it to A
  7. MOV H, A copies contents of A in H
  8. SHLD 3050 stores value of H at memory location 3051 and L at 3050
  9. HLT stops executing the program and halts any further execution

Problem-2: Find 2’s complement 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 – 
 

  1. We are taking complement of the numbers using CMA instruction.
  2. Then adding 0001 to the result using INX instruction.
  3. 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←complement of A
2005 MOV L, A L←A
2006 MOV A, H A←H
2007 CMA A←Complement 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 
 

  1. LHLD 2050 loads content of 2051 in H and content of 2050 in L
  2. MOV A, L copies contents of L in A
  3. CMA complements contents of A
  4. MOV L, A copies contents of A in L
  5. MOV A, H copies contents of H in A
  6. CMA complements contents of A
  7. MOV H, A copies contents of A in H
  8. INX H adds 0001 in HL
  9. MVI A 00 moves 00 in A
  10. ADC A adds A, A, Carry and stores result in A
  11. SHLD 3050 stores value of H at memory location 3051 and L at 3050
  12. STA 3052 stores value of A at memory location 3052
  13. HLT stops executing the program and halts any further execution

Advantages :

  • It is a simple and efficient method to find the 2’s complement of a binary number using the carry.
     
  • It is faster than the traditional method of finding the 2’s complement by inverting all bits and adding 1.
     
  • It requires fewer instructions and registers compared to other methods.
     

Disadvantages :

  • It may be slightly more difficult to understand for beginners who are not familiar with the concept of binary arithmetic.
     
  • It can only be used with binary numbers and not with other number systems such as decimal or hexadecimal.
     
  • It may not work correctly for signed numbers if the carry flag is not properly set or cleared.

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
 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads