Skip to main content

Posts

Showing posts with the label 8085

8085 Programming : store the nos in a memory loc. In the reverse order in another memory location

               MVI C, 0AH  ; Initialize counter                   LXI H, 2200H  ; Initialize source memory pointer                   LXI D, 2309H  ; Initialize destination memory pointer    BACK:    MOV A, M  ; Get byte from source memory block                   STAX D  ; Store byte in the destination memory block                   INX H  ; Increment source memory pointer                   DCX D  ; Decrement destination memory pointer                    DCR C  ; Decrement counter                    JNZ BACK  ; If counter  0 repeat                   HLT ; Terminate program execution

8085 Programming : In a set of nos add only the odd nos

                 LDA 2200H              MOV C, A  ; Initialize counter              LXI H, 2201H  ; Initialize pointer              MVI E, 00  ; Sumlow = 0              MOV D, E ; Sumhigh = 0   BACK:      MOV A, M  ; Get the number              ANI 01H   ; Mask Bit1 to Bit7              JZ SKIP                  ; Do not add if number is even              MOV A, E  ; Get the lower byte of sum                    ADD M     ; Sum = sum + data              MOV E, A   JNC SKIP  ; Store result in E register              INR D   ; Add carry to MSB of SUM   SKIP:        INX H   ; Increment pointer              DCR C     ; Decrement counter             JNZ BACK  ; Check if counter 0 repeat             MOV A, E             STA 2300H  ; Store lower byte             MOV A, D             STA 2301H ; Store higher byte            HLT ; Terminate program execution     

8085 Programming : In a set of nos add only the even nos

            LDA 2200H         MOV C, A  ; Initialize counter               MVI B, 00H ; sum  =  0         LXI H, 2201H ; Initialize pointer   BACK: MOV A, M  ; Get the number         ANI, 01H   ; Mask Bit1 to Bit7         JNZ SKIP  ; Don’t add if number is ODD         MOV A, B  ; Get the sum         ADD M  ; SUM = SUM + data         MOV B, A  ; Store result in B register   SKIP:   INX  H        ; increment pointer         DCR C ; Decrement counter         JNZ BACK  ; if counter 0 repeat         STA 2210H ; store sum         HLT    ; Terminate program execution  

8085 Programming : To find the no of 1’s in the byte

            MVI B,00H                 MVI C,08H                MOV A,D    BACK: RAR                JNC SKIP                INR B    SKIP:   DCR C                JNZ BACK                HLT       

8085 Programming : Block data transfer

              MVI C, 0AH  ; Initialize counter                  LXI H, 2200H  ; Initialize source memory pointer                  LXI D, 2300H  ; Initialize destination memory pointer    BACK:   MOV A, M  ; Get byte from source memory block                  STAX D  ; Store byte in the destination memory block                  INX H  ; Increment source memory pointer                  INX D  ; Increment destination memory pointer                   DCR C  ; Decrement counter                   JNZ BACK  ; If counter  0 repeat                  HLT ; Terminate program execution   

8085 Programming : Adding 2 Hexa-Decimal nos with carry

             LDA 2200H                 MOV C,A ; Initialize counter                 LXI H, 2201H ; Initialize pointer                 SUB A  ; Sum low = 0                 MOV B,A ;  Sumhigh  = 0    BACK:  ADD M ; Sum = sum + data                 JNC SKIP                 INR B   ; Add carry to MSB of SUM   SKIP:    INX H   ; Increment pointer               DCR C ; Decrement counter               JNZ BACK  ; Check if counter 0 repeat               STA 2300H              MOV A,B  ; Store lower byte               STA 2301H  ; Store higher byte               HLT   ; Terminate program execution

8085 Programming : Adding 2 Hexa-decimal nos without carry

  LDA 2200              MOV C, A ;  Initialize counter              SUB A  ;  sum = 0              LXI H, 2201H ;  Initialize pointer BACK:  ADD M   ; SUM = SUM + data              INX H  ;  increment pointer              DCR C ;  Decrement counter              JNZ BACK ;  if counter  0 repeat              STA 2300H ;  store sum              HLT          

8085 Programming: Adding 2 BCD nos without carry

MOV A, L ; Get lower 2 digits of no. 1    ADD E ; Add two lower digits    DAA  ; Adjust result to valid BCD    STA 2300H ; Store partial result    MOV A, H ; Get most significant 2 digits of no. 2    ADC D ; Add two most significant digits     DAA  ; Adjust result to valid BCD     STA 2301H ; Store partial result    HLT ; Terminate program execution   

8085 Programming : ADDITION OF 16BIT NUMBERS

ADDITION OF TWO 16BIT NUMBERS SUM 16 BITS OR MORE Manually strore 1st 16 bit no in the memory location C050 & C051 in reverse order Manually store 2nd 16 bit no in the memory location C052 & C053 in reverse order Result is stored in C053, C054 & C055 in reverse order           LHLD C050          XCHG          LHLD C052          MVI C,00          DAD D          JNC AHEAD          INR C AHEAD:   SHLD C054         MOV A,C         STA C056         HLT EXAMPLE-> A645+9B23=014168 STORE-> C050=45,C051=A6,C052=23,C053=9B Answer-> C054=68,C055=41,C056=01 // 45H,A6H,23H,9BH

8085 Programming : 8 BIT DECIMAL SUBSTRACTION

  If 2nd no is greater than 1st no then the answer will in 2's complement Manually strore 1st 8 bit no in the memory location C050 Manually store 2nd 8 bit no in the memory location C051 Result is stored in C052   LXI H,C051   MVI A,99   SUB M   INR A   DCX H   ADD M   DAA   STA C052   HLT  EXAMPLE-> 99-48=51  STORE-> C050=99,C051=48 OUTPUT: C052=51

8085 Programming: Exchange the contents of memory locations

Exchange the contents of memory locations 2000H and 4000H. Program 1: LDA 2000H : Get the contents of memory location 2000H into accumulator MOV B, A : Save the contents into B register LDA 4000H : Get the contents of memory location 4000H into accumulator STA 2000H  : Store the contents of accumulator at address 2000H MOV A, B : Get the saved contents back into A register STA 4000H : Store the contents of accumulator at address 4000H Program 2: LXI H 2000H : Initialize HL register pair as a pointer to memory location 2000H. LXI D 4000H : Initialize DE register pair as a pointer to memory location 4000H. MOV B, M  : Get the contents of memory location 2000H into B register. LDAX D : Get the contents of memory location 4000H into A register. MOV M, A : Store the contents of A register into memory location 2000H. MOV A, B : Copy the contents of B register into accumulator. STAX D : Store the contents of A register into memory location 4000H. HLT : Terminate program execution. Note: In Pr

8085 Programming: Store 8 bit data in Memory

Program 1: MVI A, 52H : Store 32H in the accumulator STA 4000H : Copy accumulator contents at address 4000H HLT : Terminate program execution Program 2: LXI H : Load HL with 4000H MVI M : Store 32H in memory location pointed by HL register pair (4000H) HLT : Terminate program execution Note: The result of both programs will be the same. In program 1 direct addressing instruction is used, whereas in program 2 indirect addressing instruction is used.

8085 Programming: 8 BIT MULTIPLICATION: PRODUCT 16-BIT

       LHLD 2501        XCHG        LDA 2503        LXI H,0000        MVI C,08 LOOP:     DAD H        RAL        JNC AHEAD        DAD D AHEAD:  DCR C        JNZ LOOP        SHLD 2504        HLT LSB OF MULTIPLICAND - 84H, MSB OF MULTIPLICAND - 00H ,MULTIPLIER - 56H ANSWER AT ADDRESS 2504 - 58H, LSBs OF PRODUCT AT ADDRESS 2505 - 2CH, MSB sOF PRODUCT

8085 Programming: 8 BIT DIVISION

      LHLD 2501       LDA 2503       MOV B,A       MVI C,08 LOOP:   DAD H      MOV A,H      SUB B      JC AHEAD      MOV H,A      INR L AHEAD: DCR C       JNZ LOOP       SHLD 2504       HLT INPUT: LSB OF DIVIDEND - 9BH, MSB OF DIVIDEND - 48H , DIVISOR - 1AH ANSWER AT ADDRESS 2504 - F2H, QUOTIENT AT ADDRESS 2505 - 07H, REMAINDER

8085 Programming: 2's COMPLEMENT OF AN 8-BIT NUMBER

The number to be complemented is stored in C050. Answer is stored in C051   LDA C050   CMA   INR A   STA C051   HLT EXAMPLE-> C050=96 Answer-> C051=6A

8085 Programming: 2's COMPLEMENT OF A 16-BIT NUMBER

The 16bit number is stored in C050,C051. The answer is stored in C052,C053   LXI H,C050   MVI B,00   MOV A,M   CMA   ADI 01   STA C052   JNC GO   INR B GO:   INX H   MOV A,M   CMA   STA C053   HLT EXAMPLE-> C050=8C,C051=5B Answer-> C052=74,C053=A4

8085 Programming: 1's COMPLEMENT OF AN 8-BIT NUMBER

The number to be complemented is stored in C050. Answer is stored in C051   LDA C050   CMA   STA C051   HLT EXAMPLE-> C050=96 Answer-> C051=69

8085 Programming: 1's COMPLEMENT OF A 16-BIT NUMBER

The 16bit number is stored in C050,C051 The answer is stored in C052,C053   LXI H,C050   MOV A,M   CMA   STA C052   INX H   MOV A,M   CMA   STA C053   HLT  EXAMPLE-> C050=85,C051=54  Answer-> C052=7A,C053=AB

8085 Programming :