8085 program to find 1’s and 2’s complement of 8-bit number
Problem – Write a program to find 1’s and 2’s complement of 8-bit number where starting address is 2000 and the number is stored at 3000 memory address and store result into 3001 and 3002 memory address. Example – Algorithm –
- Load the data from memory 3000 into A (accumulator)
- Complement content of accumulator
- Store content of accumulator in memory 3001 (1’s complement)
- Add 01 to Accumulator content
- Store content of accumulator in memory 3002 (2’s complement)
|2000||LDA||||[A] <- |
|2003||CMA|| ||[A] <- [A^]|
|2007||ADI||01||[A] <- [A] + 01|
- A is an 8-bit accumulator which is used to load and store the data directly
- LDA is used to load accumulator direct using 16-bit address (3 Byte instruction)
- CMA is used to complement content of accumulator (1 Byte instruction)
- STA is used to store accumulator direct using 16-bit address (3 Byte instruction)
- ADI is used to add data into accumulator immediately (2 Byte instruction)
- HLT is used to halt the program
Advantages of using 1’s and 2’s complement:
- They are widely used in digital circuits and computer architecture to represent negative numbers.
- They are simple and efficient methods for representing negative numbers and performing arithmetic operations on them.
- They require no extra hardware or memory to perform the negation operation, unlike other methods such as sign and magnitude.
Disadvantages of using 1’s and 2’s complement:
- The 1’s complement has two representations for zero (+0 and -0), which can lead to confusion and errors.
- The 2’s complement method requires an extra step of adding 1 to the 1’s complement, which may cause overflow errors if the number of bits used is not sufficient.
- The use of 1’s and 2’s complement can make certain operations more complex, such as division and comparison of signed numbers.