Sunday, April 24, 2011

MICROPROCESSOR LAB PROGRAMS - 2

ENCODER (3 to 8):


            Q0 = D1 + D3 + D5 + D7  (8050)
            Q1 = D2 + D3 + D6 + D7 (8051)
            Q2 = D4 + D5 + D6 + D7 (8052)
            The gaps between may not be accurate
ADDRESS
HEXCODE
LABEL
MNEMONICS
8000


MVI D,80
8001



8002


MVI B,01
8003



8004


LXIH 9000
8005



8006



8007



8008

L
MOV A,D
8009


ANA B
800A


MOV M,A
800B


INR L
800C


MOVA,B
800D


RLC
800E


MOV B,A
800F


JNC L
8010



8011



8012



8013


LXIH 9001
8014



8015



8016



8014


MOV A,M
8015


LXIH 9003
8013



8014



8015



8016


ORA M
8017


LXIH 9005
8018



8019



801A



801B


ORA M
801C


LXIH 9007
801D



801E



801F



8020


ORA M
8021


STA 8050
8022



8023



8024



8025


LXIH 9002
8026



8027



8028



8029


MOV A,M
802A


LXIH 9003
802B



802C



802D



802E


ORA M
802F


LXIH 9006
8030



8031



8032



8033


ORA M
8034


LXIH 9007
8035



8036



8037



8038


ORA M
8039


STA 8051
803A



803B



803C



803D


LXIH,9004
803E



803F



8040



8041


MOV A,M
8042


LXIH 9005
8043



8044



8045



8046


ORA M
8047


LXIH 9006
8048



8049



804A



804B


ORA M
804C


LXIH, 9007
804D


ORA M
804E


STA 8052
804F


HLT
BEFORE EXECUTION:                                             AFTER EXECUTION:
A-80                                                                                        8050 -1
9000 -9007 =00                                                                       8051 - 1
                                                                                                8052  - 1                     

TO DISPLAY THE VALUE OF ( X^2-4*X+4)/4


lxi h,9000
mov a,m
mov b,a
mov c,a
mvi a,00
l:
add b
dcr c
jnz l
inx h
mov m,a
mov c,a
mov a,b
rlc
rlc
inx h
mov m,a
mov b,a
mov a,c
sub b
adi 04
inx h
mov m,a
rrc
rrc
inx h
mov m,a
hlt

TO CALCULATE THE VALUE OF 1^2+2^2+…. n^2, AND TO STORE THEM IN CONTINUOUS MEMORY LOCATIONS AND THEIR SUM IN THE NEXT LOCATION:


lxi h,9000
mvi c,03
mvi a,01
L:
  mov d,a
  mov e,a
  L1:
     add d
     dcr e
     jnz L1
  sub d
  mov m,a
  inx h
  inr d
  mov a,d
  dcr c
  jnz L
lxi h,9000
mvi c,03
mvi a,00
L2:
   add m
   inx h
   dcr c
   jnz L2
mov m,a
hlt                   

ENCODER AND DECODER PROGRAM:


LXI D,A000
MVI A,01
CPI 01
JZ 8000 [ENCODER]
JMP 9000 [DECODER]
ENCODER:

LXI H,8070
MOV B,M
MVI A,90
OUT 31
MOV E,M
LDAX D
OUT 30
INX H
MVI A,90
OUT 31
MOV E,M
LDAX D
OUT 30
MOV A,B
CMA
ANA M
ORA B
STA B000
MOV C,A
MOV A,94
OUT 31
MOV E,C
LDAX D
OUT 30
MOV A,M
CMA
MOV C,A
MOV A,B
CMA
ANA C
INX H
MOV A,92
OUT 31
MOV E,M
LDAX D
OUT30
ANA M
ORA B
STA B001
MOV C,A
MOV A,94
OUT 31
MOV E,C
LDAX D
OUT 30
HLT

DECODER:

LXI H,9070
MOV B,M
MVI A,94
OUT 31
MOV E,M
LDAX D
OUT 30
INX H
MVI A,95
OUT 31
MOV E,M
LDAX D
OUT30
MOV A,B
ANA M
STA B000
MOV C,A
MVI A,90
OUT 31
MOV E,C
LDAX D
OUT 30
MOV A,B
CMA
ANA M
STA B001
MOV C,A
MVI A,91
OUT 31
MOV E,C
LDAX D
OUT 30
MOV A,M
CMA
ANA B
STA B002
MOV C,A
MVI A,92
OUT 31
MOV E,C
LDAX D
OUT 30
MOV A,B
CMA
MOV C,A
MOV A.M
CMA
ANA C
STA B003
MOV C,A
MVI A,93
OUT 31
MOV E,C
LDAX D
OUT 30
HLT
                                                                                                             
                                                                                                                           
                         


RESULT:
ENCODER: INPUTS- 80703; 80712; 80721             OUTPUTS- B000:Y1; B001:Y0
     X3
     X2
     X1
      X0  
      Y1
     Y0
      1
      X
      X
      X
       1
      1
      0
      1
      X
      X
       1
      0
      0
      0
      1
      X
       0
      1
      0
      0
      0
      X
       0
      0
DECODER:   INPUTS- 90701; 90710        OUTPUTS- B000:Y3; B001:Y2; B002:Y1; B003:Y0
      X1
      X0
      Y3
      Y2
      Y1
      Y0
       0
       0
       0
        0
       0          
        1
       1
       0
       0
        0
       1
        0
       0
       1
       0
        1
       0
        0
       1
       1
       1
        0
       0
        0

AND OR NOT:


 LXI H 8050H
 MOV D M
 INX H
 MOV B M
 INX H
 MOV A M
 CPI 01h
 JZ AND
 INX H
 MOV A M
 CPI 01h
 JZ OR
 INX H
 MOV A M
 CPI 01h
 JZ NOT
 L1: MVI A 90h
 OUT 31h
 MVI A 60h
 OUT 30h
 HLT
 L2: MVI A 90h
 OUT 31h
 MVI A F3h
 OUT 30h
 HLT
 AND: MOV A D
 ANA B
 CPI 01h
 JZ L1
 JC L2
 HLT
 OR: MOV A D
 ORA B
 CPI 01h
 JZ L1
 JC L2
 HLT
 NOT: MOV A D
 CPI 01h
 JZ L2
 JC L1
 HLT
ADDRESS
HEXCODE
LABEL
MNEMONICS
8000
21

LXI H,8060
8001
60


8002
80


8003
7E

MOV A,M
8004
FE

CPI 01
8005
01


8006
CA

JZ L
8007
15


8008
80


8009
FE

CPI 00
800A
00


800B
C2

JNZ L1
800C
14


800D
80


800E
21

LXI H,8065
800F
65


8010
80


8011
CD

CALL 803E
8012
3E


8013
80


8014
76
L1
HLT
8015
21
L
LXI H,806A
8016
6A


8017
80


8018
CD

CALL 803E
8019
3E


801A
80


801B
76

HLT


WRITE A PROGRAM TO DISPLAY EVEN NUMBERS IF  0 IS GIVEN AS INPUT 0R TO DISPLAY 0DD NUMBERS IF 1 IS GIVEN AS INPUT:

ADDRESS
HEXCODE
LABEL
MNEMONICS
803E
OE

MVI C,05
803F
05


8040
06

MVI  B,90
8041
90


8042
04
L3
INR B
8043
78

MOV A,B
8044
D3

OUT 31
8045
31


8046
7E

MOV A,M
8047
D3

OUT 30
8048
30


8049
23

INX H
804A
OD

DCR C
804B
C2

JNZ  L3
804C
42


804D
80


804E
C9

RETURN
-



8060-GET INPUT
8065-CODE’0’-F3
8066-CODE’2’-B5
8067-CODE’4’-66
8068-CODE’6’-D7
8069-CODE-‘8’-F7
806A-CODE’1’-60
806B-CODE’3’-F4
806C-CODE’5’-D6
806D-CODE’7’-70
806E-CODE’9’-76

FULL ADDER USING INPUT VALUES IN HEX FORM:


LXI H,8050
MVI C,00
MOV B,M
MOV A,B
SUB C
JZ  L1
INR C
MOV A,B
SUB C
JZ L2
INR C
MOV A,B
SUB C
JZ L3
INR C
MOV A,B
SUB C
JZ L4
INR C
MOV A,B
SUB C
JZ L5
INR C
MOV A,B
SUB C
JZ L6
INR C
MOV A,B
SUB C
JZ L7
INR C
MOV A,B
SUB C
JZ L8

MEMORY LOCATION DATA:
L1:
                               LXI H,9700
                               CALL 9800
                               HLT
L2:                                    
                               LXI H,9706
                               CALL 9800
                               HLT

L3:
                               LXI H,970C
                               CALL 9800
                               HLT

L4:
                               LXI H,9712
                               CALL 9800
                               HLT

L5:
                               LXI H,9718
                               CALL 9800
                               HLT

L6:
                               LXI H,971E
                               CALL 9800
                               HLT

L7:
                               LXI H,9724
                               CALL 9800
                               HLT

L8:
                               LXI H,972A
                               CALL 9800
                               HLT
DELAY PROGRAM:
9800:
MVI D,90
MOV A,D
OUT 31
MOV A,M
OUT 30
INR D
INX H
MVI A,96
SUB D
JNZ L
RET
MEMORY LOCATIONS:
9700-   F3                    9710-   60                    9720-F3
9701-   F3                    9711-   F3                    9721-60
9702-   F3                    9712-   F3                    9722-F3
9703-F3                       9713-   F3                    9723-60
9704-F3                       9714-   60                    9724-F3
9705-F3                       9715-   60                    9725-60
9706-F3                       9716-F3                      9726-60
9707-F3                       9717-60                       9727-F3
9708-F3                       9718-   F3                    9728-F3
9709-60                       9719-   60                    9729-60
970A-60                   971A-      F3                    972A-F3
970B-F3                      971B-  F3                    972B-60
970C-F3                      971C-  60                    972C-60
970D-F3                      971D-  F3                    972D-60
970E-60                      971E-  F3                    972E-60
970F-F3                      971F-   60                    972F-60
Where F3 & 60 are the equivalent codes for displaying 0 & 1on the 7-segment display.BCD addition with display of inputs and output            
MVI C,00
LXI H,9000
MVI D,00
MVI E,09
MVI A,91
OUT 31
MOV A,D
MOV L,A
MOV A,M
OUT 30
MVI A,93
OUT 31
MOV A,E
MOV L,A
MOV A,M
OUT 30
MOV A,D
ADD E
CPI 09
JNC   L1
MOV L,A
MVI A,95
OUT 31
MOV A,M
OUT 30
JMP  Z
L1: INR C
      SUI 01
      MOV L,A
      MVI A,95
     OUT 31
     MOV A,M
     OUT 30
     MOV L,C
     MVI A,94
     OUT 31
     MOV A,M
     OUT 30
Z:  HLT
B.E:-                                                                                    A.E:-

8

9
1
7
INPUTS:-D-08, E-09                                                      
9000-F3
9001-60
9002-B5
9003-F4
9004-66
9005-D6
9006-D7                                                                                            
9007-70                                                                                             
9008-F7                                                                                            
9009-F6                                                                                            

EQUATION:

lxi h,9000
lxi b,8050
ldax b
mov d,a
mov c,a
mvi a,00
L:
add d
dcr c
jnz L
mov m,a
mov a,d
rlc
inx h
mov m,a
adi 03
inx h
mov m,a
rrc
rrc
inx h
mov m,a
hlt

PROGRAGM OF SQUARE ROOT:

      LXI H, 8050
      MVI E, OO
L3  INR E
      MOV D, E
      MVI A, OO
L1  ADD E
      DCR D
      JNZ  L1
     MOV A, E
     STA 8051
     HLT

AFTER EXECUTION:
09- 03

5 comments:

  1. but orientation of the blog elements is not good... change it in monetize option in blogger home...

    ReplyDelete

LinkWithin

Related Posts Plugin for WordPress, Blogger...