Thursday, May 28, 2020

16 bit programs of 8085, addition, subtraction, multiplication and division of two 16 bit number.






  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 into
    register H.
  • Example: LHLD 2040 H
2.SHLD:-Store H-L registers direct.
  • The contents of register L are stored into memory location 
           specified by the 16-bit address.
  • 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 the
    contents of register D.
  • The contents of register L are exchanged with the
    contents of register E.
4. DAD:- Add register pair to H-L pair.
  • The 16-bit contents of the register pair are added to the
    contents 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.
5. ADC:- Add register or memory to accumulator with
carry.
  • The contents of register or memory and Carry Flag (CY) are added to
    the 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
6SBB:- Subtract register or memory from accumulator
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
















No comments:

Post a Comment