SUBTRACTION

 

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.

THEORY

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.

ALGORITHM :

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.

IMPLEMENTATION :

LocationMnemonicsHex Code
3000 LXI H 21
30010000
30022020
3003MOV A, M7E
3004INX H23
3005MOV B, M46
3006INX H23
3007SUB B90
3008MOV M, A77
3009HLT76

INPUT AND OUTPUT :

LocationInput
200030
200120
LocationOutput
200210

DISCUSSION :


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:

https://www.shoutcoders.com/microprocessor-8085a-program-given-two-data-stored-at-memory-location-x-and-x1-perform-addition-on-mx-and-mx1-and-store-the-result-at-location-x2/?preview_id=1749&preview_nonce=9d802f4a32&preview=true&_thumbnail_id=1838
https://www.shoutcoders.com/coursera50courses/

Comments

Popular posts from this blog

MEMORY MANAGEMENT NOTE

MULTIPLY WITHOUT CARRY