Open In App

8085 program to find 1’s and 2’s complement of 16-bit number

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

Prerequisite – 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 16-bit number where starting address is 2000 and the number is stored at 3000 memory address and store result into 3002 and 3004 memory address. Example – Algorithm –

  1. Load a 16-bit number from memory 3000 into a register pair (H-L)
  2. Move content of register L to accumulator
  3. Complement content of accumulator
  4. Move content of accumulator to register L
  5. Move content of register H to accumulator
  6. Complement content of accumulator
  7. Move content of accumulator to register H
  8. Store content of register pair in memory 3002 (1’s complement)
  9. Increment content of register pair by 1
  10. Store content of register pair in memory 3004 (2’s complement)
  11. Stop

Program –

Memory Mnemonics Operands Comment
2000 LHLD [3000] [H-L] <- [3000]
2003 MOV A, L [A] <- [L]
2004 CMA   [A] <- [A^]
2005 MOV L, A [L] <- [A]
2006 MOV A, H [A] <- [H]
2007 CMA   [A] <- [A^]
2008 MOV H, A [H] <- [A]
2009 SHLD [3002] 1’s complement
200C INX H [H-L] <- [H-L] + 1
200D SHLD [3004] 2’s complement
2010 HLT   Stop

Explanation –

  1. A is an 8-bit accumulator which is used to load and store the data
  2. LHLD is used to load register pair H-L direct using 16-bit address (3 Byte instruction)
  3. MOV is used to transfer the data from accumulator to register(any) or register(any) to accumulator (1 Byte)
  4. CMA is used to complement content of accumulator (1 Byte instruction)
  5. SHLD is used to store data from register pair H-L into memory direct using 16-bit address (3 Byte instruction)
  6. INX is used to increase H-L register pair by 1 (1 Byte instruction)
  7. 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.

Previous Article
Next Article

Similar Reads

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 accumulatorStore content of accumulator in memory 3
2 min read
8085 program to find 2's complement of the contents of Flag Register
Problem – Write an assembly language program in 8085 microprocessor to find 2's complement of the contents of Flag Register. Example - Algorithm – Initialize the value of Stack Pointer (SP) to 3999 Push the contents of PSW (Register pair formed by Accumulator and Flag Register) into the memory stack Pop the contents from the stack into register pai
2 min read
Interface 8255 with 8085 microprocessor for 1’s and 2’s complement of a number
Introduction : The 8255 is a programmable peripheral interface chip that can be interfaced with the 8085 microprocessor to perform various input/output operations. One of the operations that can be performed using the 8255 and the 8085 microprocessor is finding the 1's and 2's complement of a number. The 1's complement of a binary number is obtaine
4 min read
Difference between 1's Complement representation and 2's Complement representation Technique
Prerequisite - Representation of Negative Binary Numbers 1's complement of a binary number is another binary number obtained by toggling all bits in it, i.e., transforming the 0 bit to 1 and the 1 bit to 0. Examples: Let numbers be stored using 4 bits 1's complement of 7 (0111) is 8 (1000) 1's complement of 12 (1100) is 3 (0011) 2's complement of a
3 min read
8085 programs to find 2's complement with carry | Set 2
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 - We are taking complement of the number using CMA instruction.Then adding 01 to the result.The carry generated while adding 01 is stored at 3051. Program - Memory Add
3 min read
8085 program to find sum of digits of 8 bit number
Problem: Write an assembly language program in 8085 microprocessor to find the sum of digits of an 8-bit number. Example: Assumptions: Addresses of input data and output data are 2050 and 3050 respectively. Algorithm: Load value stored at memory location 2050 in accumulator AMove the value of accumulator A in register B to process 43H.Perform maski
5 min read
8085 program to find square of a 8 bit number
Problem - Write an assembly language program in 8085 microprocessor to find square of 8 bit number. Example - Assumption - Addresses of input data and out data are 2050 and 3050 respectively. Approach - Combine the content of registers H and L, the resultant content can be used to indirectly point to memory location and that memory location is spec
2 min read
8085 program to find minimum value of digit in the 8 bit number
Problem - Write an assembly language program in 8085 microprocessor to find minimum value of digit in the 8 bit number. Example - Assume 8 bit number is stored at memory location 2050, and minimum value digit is stored at memory location 3050. Algorithm - Load the content of memory location 2050 in accumulator A.Move the content of A in register B.
3 min read
8085 program to convert an 8 bit number into Grey number
Prerequisite - Binary to/from Gray Code Problem - Write an assembly language program in 8085 which convert an 8 bit number into grey number Example - Assumption - 8 bit number (input) is stored at memory location 2050 and output to be stored at memory location 3050. Algorithm - Load the content of memory location 2050 in AccumulatorReset carry flag
2 min read
8085 program to count number of ones in the given 8-bit number
Problem – Write a program to count number of ones in the given 8-bit number use register B to display the count of ones where starting address is 2000 and the number is stored at 3000 memory address and store result into 3001 memory address. Example – Algorithm – Move 00 to register B immediately for countMove 08 to register C immediately for shift
3 min read