[PRACTICAL] IMPLEMENT PROGRAM TO ADD/SUBTRACT 16 BIT NUMBERS
Are you looking for a step-by-step guide to Implement program to add/subtract 16 bit numbers? here are the steps to implement program to add/subtract 16 bit numbers.
SAMPLE PROGRAM:
LXI H,0101 LXI D,3520 DAD D HLT //ANSWER IN HL PAIR 3621
Program: 16 bit addition
(C050H) = 15H
(C051H) = 1CH
(C052H) = B7H
(C053H) = 5AH
Result = 1C15 + 5AB7H = 76CCH
(C054H) = CCH
(C055H) = 76H
Program 1:
LHLD C050H : Get first I6-bit number in HL XCHG : Save first I6-bit number in DE LHLD C052H : Get second I6-bit number in HL MOV A, E : Get lower byte of the first number ADD L : Add lower byte of the second number MOV L, A : Store result in L register MOV A, D : Get higher byte of the first number ADC H : Add higher byte of the second number with CARRY MOV H, A : Store result in H register SHLD C054H : Store I6-bit result in memory locations C054H and C0C5H. HLT : Terminate program execution
Program: 16 bit subtraction
(C050H) = 45H
(C051H) = 52H
(C052H) = 14H
(C053H) = 12H
Result = 5245H – 1214H = 4031H
(C054H) = 31H
(C055H) = 40H
Program 2:
LHLD C050H : Get first I6-bit number in HL XCHG : Save first I6-bit number in DE LHLD C052H : Get second I6-bit number in HL MOV A, E : Get lower byte of the first number SUB L : Sub lower byte of the second number MOV L, A : Store result in L register MOV A, D : Get higher byte of the first number SBB H : Sub higher byte of the second number with BORROW MOV H, A : Store result in H register SHLD C054H : Store I6-bit result in memory locations C054H and C0C5H. HLT : Terminate program execution
For more practical related to 885 Programming please visit the 8085 Programming link