Program to find 1’s complement of an 16-bit number

Q. Write a program and draw a flow chart to find 1’s complement of a 16-bit number.(8085 Microprocessor Program)

Flowchart/Algorithm

Program

Address Mnemonics Operand Opcode Comments
2000 LHLD 3000H 2A Load H-L pair with data from 3000H.
2001     00  
2002     30  
2003 MOV  A, L 7D Move the lower-order from reg. L to reg. A.
2004 CMA 2F Complement accumulator.
2005  MOV  L, A 6F  Move the result from reg. A to reg. L.
2006  MOV  A, H 7C  Move the higher-order from reg. H to reg. A.
2007 CMA   2F Complement accumulator.
2008 MOV H, A 67 Move the result from reg. A to reg. H.
2009 SHLD 3002H 22 Store the result at address 3002H.
200A 02
200B 30
200C HLT 76 HALT

Output

Before Execution:

3000H:    45H

3001H:     6AH

After Execution:

3002H:     7AH

3003H:     95H

Program Explanation

  1. This program finds the 1’s complement of a 16-bit number stored in memory 3000H-3001H.
  2. There is no direct way to find 1’s complement of the 16-bit number. Therefore, this can be accomplished by finding the 1’s complement of two 8-bit numbers.
  3. Let us assume that the operand stored at memory locations 3000H-3001H is 45H-6AH.
  4. The operand is loaded into H-L pair from memory locations 3000H-3001H.
  5. The lower-order is moved from register L to accumulator.
  6. Its complement is found by using CMA instruction.
  7. The result obtained is moved back to register L.
  8. Then, the higher-order is moved from register H to accumulator.
  9. Its complement is found by using CMA instruction.
  10. The result obtained is moved back to register H.
  11. Now, the final result is in H-L pair.
  12. The result is stored from H-L pair to memory locations 3002H-3003H.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need fund to operate the site, and almost all of it comes from our online advertising.

Please add electricalvoice.com to your ad blocking whitelist or disable your adblocking software.

×