February 04, 2012
Write a program to find the 2’s complement of a number.
Apparatus Used: Microprocessor kit, Keyboards
Assumption: Suppose first number is stored at 2200 H. We have to find 2’s complement of this number and we have to store complemented at 2250 H. For 2’s complement first get 1’s complement then add 1 to get 2’s complement.
Algorithm:
- Store the number in the accumulator.
- Get one’s complement of the number.
- Add 01 to get 2’s complement.
- Store complemented number at given address.
Program:
Memory Add
|
Mnemonics
|
Op-code
|
Comments
|
2000
|
LDA
|
2200 H
|
Load the number in accumulator
|
2002
|
CMA
|
Get first complement
| |
2005
|
ADI
|
01
|
Get 2’s complement
|
200C
|
STA
|
2250
|
Store output
|
200F
|
RST
|
5
|
Set Break-point
|
2010
|
END
|
End the program
|
Description of used instruction:
LDA adr : Load data into register A (accumulator) directly from the address given within the instruction.
CMA: This instruction complements each bit of accumulator. This result of this instruction is complement.
ADI: The 8 bit data are added to the contents of the accumulator and result is placed in the accumulator.
STA: This instruction is used to store the content of accumulator at specified memory address.
RST 5: This instruction is used to set break-point for the execution.
END: This instruction is used to execute the program.
Result:
Input:
2200-88(1000 1000)
Output:
2250-78(0111 1000)
Procedure to look output
- After press ENTER, You will get first screen
- Press G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide Input location for Input (M2200)
- Press ENTER and Provide your Input at location (2200: 88)
- Press SHIFT+4
- Press G and Provide Initial address (as 2000)
- Press SHIFT+4,You will get first screen again
- Press M and Provide address for output (M2050) and press ENTER
- You will get your desired output.
Subscribe to:
Post Comments (Atom)
Wow, amazing blog layout! How lengthy have you ever
ReplyDeletebeen blogging for? you make blogging look easy.
The overall look of your site is great, llet alone the content!
Feel free to visit my webpage :: live code generator