Adiition of two 16 bit numbers:-
some important instructions which are used to 16 bit prgrams :-
1. LHLD :- load H-L register direct
- This instruction copies the contents of memory location pointed out by 16-bit address into register L.
- It copies the contents of next memory location intoregister H.
- Example: LHLD 2040 H
- The contents of register L are stored into memory location
- The contents of register H are stored into the next memory location..
- Example: SHLD 2550 H
3. XCHG :- Exchange H-L with D-E.
- The contents of register H are exchanged with thecontents of register D.
- The contents of register L are exchanged with thecontents of register E.
- The 16-bit contents of the register pair are added to thecontents of H-L pair.
- The result is stored in H-L pair.
- If the result is larger than 16 bits, then CY is set.
- No other flags are changed.
carry.
- The contents of register or memory and Carry Flag (CY) are added tothe contents of accumulator.
- The result is stored in accumulator.
- If the operand is memory location, its address is specified by H-L pair.
- All flags are modified to reflect the result of the addition.
- Example: ADC B or ADC M
with borrow.
- The contents of the register or memory location and Borrow Flag (i.e.CY) are subtracted from the contents of the accumulator.
- The result is stored in accumulator.
- If the operand is memory location, its address is specified by H-L
- All flags are modified to reflect the result of subtraction.
- Example: SBB B or SBB M
PROGRAM:-
LDA 0000 H
MOV B, A
LDA 0002 H
ADD B
STA 0004 H
LDA 0001 H
MOV B, A
LDA 0003 H
ADC B ( A+B+CY)
STA 0005 H
HLT
2nd method:-
LHLD 0000 H
XCHG (HL to DE)
LHLD 0002H
DAD D (H+D & D+E)
SHLD
HLT
subtraction of two 16 bit number :-
LDA 0002 H (load 8 bit data)
MOV B, A ( move accumulator to register B)
LDA 0000 H
SUB B ( SUB A-B= A)
STA 0004 H (result store in location)
LDA 0003 H
MOV B, A
LDA 0001 H
SBB B (subtract with borrow)
STA 0005 H (store carry)
HLT