Computer Science, asked by amruthaprasad262, 1 year ago

Write a program using 8051 simulator to find 2's complement of a hexadecimal number

Answers

Answered by sudhansu59
0

I hope this might help you.

Attachments:
Answered by aliyasubeer
0

Answer:

8051 simulator to find 2's complement of a hexadecimal number

Explanation:

Address Mnemonics Operand  Opcode                       Comments

2000 LHLD          3000H              2A                     Load HL pair

                                                                                           data from 3000h

2001                                        00

2002                                         30

2003    

2004 MOV             A,L                7D       Move the low-order

                                                                            result from reg.A TO  Reg.L

2005 MOV             L,A                6F       Move the result

                                                                                      from reg.L TO Reg.A

2006 MOV           A,H                 7C      Move the higher order

                                                                                     from reg.H to reg.A

2007 CMA                                   2F   compliment accumulator

2008 MOV            H,A                  67      Move the result

                                                                                  from reg.A TO Reg.H

2009 INX                       H                 23      Increment HL pair to

                                                                                   find 2’s compliment

200A SHLD           3002H                  22      Store the result

                                                                                    at address 3002H

200B                                           02

200C                                            30

200D HLT                                            76             HALT

OUTPUT:

Before execution:

3000H:12H

3001H:05H

After execution:

3002H:EEH

3003H:FAH

Program explanation:

1. This program finds the $2^{\prime} s$ complement of $a$ 16-bit number stored in memory locations  $3000 \mathrm{H}-3001 \mathrm{H}$.

2. There is no direct way to find 2's complement of the 16 -bit number. Therefore, this can be accomplished by finding the 1's complement of two 8-bit numbers and then incrementing to get 2's compliment.

3. Let us assume that the operand stored at memory locations 3000 \mathrm{H}-3001 \mathrm{H}$ is $12 \mathrm{H}-05 \mathrm{H}$.

4. The operand is loaded into$H-L$ pair from memory locations 3000 \mathrm{H}-3001 \mathrm{H}$.

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$\mathrm{H}$ to accumulator.

9. Its complement is found by using CMA instruction.

10. The result obtained is moved back to register

11. H-L pair is incremented to get 2's complement.

12. Now, the final result is in H-L pair.

13. The result is stored from H-L pair to memory locations 3002 \mathrm{H}-3003 \mathrm{H}$.

Similar questions