GIVEN TWO DATA STORED AT MEMORY LOCATION x AND x+1. PERFORM SUBTRACTION ON m(x) AND m(x+1) AND STORE THE RESULT AT LOCATION x+2.
In 8085 microprocessor, The SUB instruction is used for 2’s complemented method for subtraction. When the first operand is larger then the result will be positive i.e. not enable the carry flag. But When the result will be negative then the result will be 2’s complemented form and the carry flag will be enabled.
Step 1: LXI H,2000h, to load the address in H-L register pair using LXI H from 16-bit location 2000h.
Step 2: MOV A, M to move the value of 2000h memory address value into the accumulator.
Step 3: INX H, to increase the value of the H-L register pair to get the next memory location.
Step 4: MOV B, M to move the value of the 2001h memory location to register B.
Step 5: INX H, done to the H-L pair of the register will be increased and pointed to store the subtraction result.
Step 6: SUB B, for we need to perform subtraction with the value of the accumulator with the content of B register and store the result into the accumulator.
Step 7: MOV M, A; for that value of accumulator value will be stored into the H-L register pair with the pointed location.
Step 8: HLT; to stop the program.
|3003||MOV A, M||7E|
|3005||MOV B, M||46|
|3008||MOV M, A||77|
INPUT AND OUTPUT :
In this program, we perform the subtraction task where we stored two values in different memory locations (2000h and 2001h) and we use the SUB operation in the 8085 microprocessor. Firstly we load the value of memory location to accumulator then the second value load into B register to perform the subtraction (SUB B) in between Accumulator and B register. The resultant value will store at location 2002h.
Which was being pointed by incrementing the value of the H-L register pair (INX H). To store the Accumulator value to a memory location by using MOV M, A. Here just we have to take inputs from memory locations 2000h and 2001h where values are 30h and 20h. Here just we saw that 1’s complement is done. But if the 1st value will smaller than the 2nd value then the value will be subtracted with 2’s complement. As per location 2000h & 2001h store values 30h and 20h respectively. The result will be shown at location 2002 i.e. (30h-20h) = 10h.
YOU MIGHT LIKE: