Tuesday 28 November 2017

8085 program for 2's complement of a number

8085 program for 2's complement of a number


Finding Two's complement of a number, 2's complement program in 8085
2's complement of 8 bit number in 8085

Statement: Find the 2's complement of the number stored at memory location 4200H and store the complemented number at memory location 4300H.

Sample problem:

       (4200H) = 55H
               Result = (4300H) = AAH + 1 = ABH

Source program:

LDA 4200H            : Get the number
CMA                      : Complement the number
ADI, 01H               : Add one in the number
STA 4300H            : Store the result
HLT                       : Terminate program execution
 

8085 program to find one's complement of a number

8085 program to find one's complement


Finding one's complement of a number

Statement: Find the l's complement of the number stored at memory location 4400H and store the complemented number at memory location 4300H.

Sample problem:                                                                       

       (4400H) = 55H
               Result = (4300B) = AAB                                       
Source program:                                                       

LDA 4400B  : Get the number
CMA            : Complement number
STA 4300H  : Store the result
HLT              : Terminate program execution

8085 Program to Add contents of two memory locations in 8085 Processor

Add contents of two memory locations
Statement: Add the contents of memory locations 40001H and 4001H and place the result in the memory locations 4002Hand 4003H.
Sample problem:       

       (4000H) = 7FH
       (400lH)  = 89H
Result    = 7FH + 89H = lO8H
       (4002H) = 08H
       (4003H) = 0lH

Source program:

       LXI H, 4000H  : HL Points 4000H
       MOV A, M       : Get first operand
       INX H             : HL Points 4001H
       ADD M           : Add second operand
       INX H             : HL Points 4002H
       MOV M, A       : Store the lower byte of result at 4002H
       MVI A, 00       : Initialize higher byte result with 00H
       ADC A           : Add carry in the high byte result
       INX H             : HL Points 4003H
       MOV M, A       : Store the higher byte of result at 4003H
       HLT               : Terminate program execution

8085 Program to Exchange contents of memory locations 8085 Microprocessor

Program to Exchange contents of memory locations 8085 Microprocessor

Statement: 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 4000Hinto 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.

In Program 1, direct addressing instructions are used, whereas in Program 2, indirect addressing instructions are used.

8085 Program to store 8 bit data in memory of 8085 microprocessor

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

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 Program to find square of a number in 8085

Program to find square of a number in 8085


LXI H, 6200H        : Initialize lookup table pointer
               LXI D, 6100H                : Initialize source memory pointer
               LXI B, 7000H        : Initialize destination memory pointer
       BACK: LDAX D                : Get the number
               MOV L, A                : A point to the square
               MOV A, M                : Get the square
               STAX B                : Store the result at destination memory location
               INX D                : Increment source memory pointer
               INX B                        : Increment destination memory pointer
               MOV A, C
               CPI 05H                : Check for last number
               JNZ BACK                : If not repeat
               HLT                        : Terminate program execution

8085 Program to find factorial of a number in 8085

Program to find factorial of a number in 8085

Here is a program to find factorial of a number in 8085

MVI B, 03H
MOV C, B
DCR C
LOOP1:
MOV E, C
SUB A
LOOP2:
ADD B
DCR E
JNZ LOOP2
MOV B, A
DCR C
JNZ LOOP1
STA 8000H
HLT

Advanced Code


MEMORY
LABEL
MNEMONIC
HEX CODE
COMMENT
4200
LXI H,4100
21

Load the number to the HL pair
4201
00
4202
41
4203
MVI C,M
4E
Copy the number to register C
4204
MVI E,M
5E
Copy memory content to E
4205
DCR E
1D
Decrement E
4206
LOOP1
INX H
23
Increment memory
4207
DCR C
0D
Decrement C
4208
MOV M,C
71
Copy content of C to memory
4209
JNZ LOOP1
C2

Jump on non-zero to label LOOP1
420A
06
420B
42
420C
LXI H,4100
21
Load the number whose factorial is to be found in HL pair
420D
00
420E
41
420F
LOOP2
MOV A,M
7E
Copy memory content to accumulator
4210
INX H
23
Increment memory
4211
MOV B,M
46
Copy memory content to B
4212
MOV C,A
4F
Copy accumulator content to C
4213
MVI A,00
3E
Initialize A with 0
4214
00
4215
GO
ADD B
80
[A] ß [A] + [B]
4216
DCR C
0D
Decrement C
4217
JNZ GO
C2

Jump on non-zero to label GO
4218
15
4219
42
421A
MOV M,A
77
Copy accumulator content to memory
421B
DCR E
1D
Decrement E
421C
JNZ LOOP2
C2

Jump on non-zero to label LOOP2
421D
0F
421E
42
421F
STA 4500
32
Store accumulator content to memory
4220
00
4221
45
4222
HLT
76
Program ends
Tuesday 14 November 2017

BCD to binary conversion in 8085

bcd to binary conversion in 8085bcd to binary conversion in 8085


Sample Problem:
(2200H) = 67H
(2300H) = 6 x OAH + 7 = 3CH + 7 = 43H
Source Program:
       LDA 2200H                : Get the BCD number
       MOV B, A                : Save it
       ANI OFH                : Mask most significant four bits
       MOV C, A                : Save unpacked BCDI in C register
       MOV A, B                : Get BCD again
       ANI FOH                : Mask least significant four bits
       RRC                        : Convert most significant four bits into unpacked BCD2
       RRC
       RRC
       RRC
       MOV B, A                : Save unpacked BCD2 in B register
       XRA A                        : Clear accumulator (sum = 0)
       MVI D, 0AH                : Set D as a multiplier of 10
Sum:   ADD D                : Add 10 until (B) = 0
       DCR B                        : Decrement BCD2 by one
       JNZ SUM                : Is multiplication complete? i if not, go back and add again
       ADD C                : Add BCD1
       STA 2300H                : Store the result
       HLT                        : Terminate program execution
Monday 13 November 2017

BCD to HEX conversion in 8085 Micoprocessor

bcd to hex conversion in 8085



Algorithm
1. Initialize memory pointer to 4150 H
2. Get the Most Significant Digit (MSD)
3. Multiply the MSD by ten using repeated addition
4. Add the Least Significant Digit (LSD) to the result obtained in previous step
5. Store the HEX data in Memory

Program

     LXI H,5000
     MOV A,M      ;Initialize memory pointer
     ADD A        ;MSD X 2
     MOV B,A      ;Store MSD X 2
     ADD A        ;MSD X 4
     ADD A        ;MSD X 8
     ADD B        ;MSD X 10
     INX H        ;Point to LSD
     ADD M        ;Add to form HEX
     INX H
     MOV M,A      ;Store the result
     HLT

Result
Input:
Data 0: 02H in memory location 5000
Data 1: 09H in memory location 5001
Output:
Data 0: 1DH in memory location 5002
Sunday 12 November 2017

How to Find Subtraction of two 8 bit numbers 8085 Microprocessor

SUBTRACTION OF TWO 8 BIT NUMBERS | How to Find Subtraction of two 8 bit numbers 8085 Microprocessor


AIM:
     To perform the subtraction of two 8 bit numbers using 8085.
   
ALGORITHM:
     1. Start the program by loading the first data into Accumulator.
        Move the data to a register (B register).
     2. Get the second data and load into Accumulator.
     3. Subtract the two register contents.
     4. Check for carry.
     5. If carry is present take 2’s complement of Accumulator.
     6. Store the value of borrow in memory location.
     7. Store the difference value (present in Accumulator) to a memory
     8. location and terminate the program.
 
PROGRAM:
          MVI C, 00I Initialize C to 00
          LDA 4150     Load the value to Acc.
          MOV B, A    Move the content of Acc to B register.
          LDA 4151     Load the value to Acc.
          SUB B
          JNC LOOP   Jump on no carry.
          CMA           Complement Accumulator contents.
          INR A         Increment value in Accumulator.
          INR C         Increment value in register C
LOOP: STA 4152   Store the value of A-reg to memory address.
          MOV A, C    Move contents of register C to Accumulator.
          STA 4153    Store the value of Accumulator memory address.
          HLT         Terminate the program.
OBSERVATION:
            Input: 06 (4150)
                    02 (4251)
            Output: 04 (4152)
                    01 (4153)
                 
RESULT:
     Thus the program to subtract two 8-bit numbers was executed
Saturday 11 November 2017

ADDITION OF TWO 8 BIT NUMBERS

ADDITION OF TWO 8 BIT NUMBERS


AIM:
 To perform addition of two 8 bit numbers using 8085.
ALGORITHM:
 1) Start the program by loading the first data into Accumulator.
 2) Move the data to a register (B register).
 3) Get the second data and load into Accumulator.
 4) Add the two register contents.
 5) Check for carry.
 6) Store the value of sum and carry in memory location.
 7) Terminate the program.

PROGRAM:

 MVI C, 00   'Initialize C register to 00
 LDA 4150   'Load the value to Accumulator.
 MOV B, A   'Move the content of Accumulator to B register.
 LDA 4151   'Load the value to Accumulator.
 ADD B    'Add the value of register B to A
 JNC LOOP   'Jump on no carry.
 INR C     'Increment value of register C
 LOOP: STA 4152  'Store the value of Accumulator (SUM).
 MOV A, C   'Move content of register C to Acc.
 STA 4153   'Store the value of Accumulator (CARRY)
 HLT    'Halt the program.

OBSERVATION:

 Input: 80 (4150)
  80 (4251)
 Output: 00 (4152)
  01 (4153)
RESULT:
 Thus the program to add two 8-bit numbers was executed.

How to Find 8085 division of two 8 bit numbers

DIVISION OF TWO 8 BIT NUMBERS How to Find 8085 division of two 8 bit numbers


AIM:
     To perform the division of two 8 bit numbers using 8085.
    
ALGORITHM:
     1) Start the program by loading HL register pair with address of memory location.
     2) Move the data to a register(B register).
     3) Get the second data and load into Accumulator.
     4) Compare the two numbers to check for carry.
     5) Subtract the two numbers.
     6) Increment the value of carry .
     7) Check whether repeated subtraction is over and store the value of product and
        carry in memory location.
     8) Terminate the program.
    
PROGRAM:
               LXI  H, 4150
               MOV  B,M      Get the dividend in B – reg.
               MVI  C,00       Clear C – reg for qoutient
               INX  H
               MOV A,M       Get the divisor in A – reg.
NEXT:     CMP B             Compare A - reg with register B.
               JC  LOOP         Jump on carry to LOOP
               SUB  B             Subtract A – reg from B- reg.
               INR C               Increment content of register C.
               JMP NEXT      Jump to NEXT
 LOOP:    STA 4152         Store the remainder in Memory
               MOV A,C
               STA 4153         Store the quotient in memory
               HLT                  Terminate the program.


OBSERVATION:  
    Input:
 F (4150)
 FF (4251)
    Output:
 01 (4152) ---- Remainder
     FE (4153) ---- Quotient
    
RESULT:
Thus the program to divide two 8-bit numbers was executed.

How to Find LARGEST NUMBER IN AN ARRAY OF DATA

LARGEST NUMBER IN AN ARRAY OF DATA


AIM:
     To find the largest number in an array of data using 8085 instruction set.
    
ALGORITHM:
     1) Load the address of the first element of the array in HL pair
     2) Move the count to B – reg.
     3) Increment the pointer
     4) Get the first data in A – reg.
     5) Decrement the count.
     6) Increment the pointer
     7) Compare the content of memory addressed by HL pair with that of A - reg.
     8) If Carry = 0, go to step 10 or if Carry = 1 go to step 9
     9) Move the content of memory addressed by HL to A – reg.
     10) Decrement the count
     11) Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
     12) Store the largest data in memory.
     13) Terminate the program.
    
PROGRAM:
             LXI H,4200 Set pointer for array
             MOV B,M    Load the Count
             INX H         Set 1st element as largest data
             MOV A,M
             DCR B          Decrements the count
LOOP:  INX H
             CMP M           f A- reg > M go to AHEAD
             JNC AHEAD
             MOVA,M   Set the new value as largest
AHEAD:DCR B
             JNZ LOOP     Repeat comparisons till count = 0
             STA 4300     Store the largest value at 4300
             HLT


OBSERVATION:
                  
    Input: 05 (4200) ----- Array Size
                  
    Output: 0A (4201)
                F1 (4202)
               1F (4203)
                26 (4204)
                FE (4205)
                FE (4300)
   
RESULT:
Thus the program to find the largest number in an array of data was executed
 
;