Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

Microprocessor Laboratory

VIEWS: 30 PAGES: 46

									Atria Institute of Technology
    Dept. of Information Science


            Lab Manual


   Microprocessor Laboratory
Atria Institute of Technology                                   Dept. of Information Science

;1A) SEARCH A KEY ELEMENT IN A LIST OF 'N' NUMBERS USING THE
; BINARY SEARCH ALGORITHM
;CHECKED

DATA SEGMENT
   ARRAY DW 05H,16H,20H,21H,38H
   COUNT DW ($-ARRAY)/2            ;NUMBER OF ELEMENT
   KEY DW 38H
   M1 DB 'ELEMENT FOUND$'
   M2 DB 'ELEMENT NOT FOUND$'
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE, DS:DATA

START: MOV AX,DATA
   MOV DS,AX
   MOV CX,01                       ;LOW=1
   MOV DX,COUNT                    ;HIGH=COUNT
   MOV BX,KEY                      ;KEY TO BE SEARCHED
LOOP1:CMP CX,DX
   JG NOTFOUND
   MOV AX,CX
   ADD AX,DX
   SHR AX,01                      ;MID ELEMENT
   MOV BP,AX
   DEC BP
   ADD BP,BP
   CMP BX,ARRAY[BP]
   JGE NEXT
   MOV DX,AX
   DEC DX
   JMP LOOP1
NEXT: JE FOUND                                 Output
   MOV CX,AX
   INC CX                                      MASM <FILE NAME>.ASM
   JMP LOOP1
FOUND: LEA DX,M1                               IF ERRORS / WARNINGS
   MOV AH,09H                                  EDIT <FILE NAME>.ASM; TO OPEN THE FILE
   INT 21H
   JMP TERM                                    MASM <FILE NAME>.ASM; TO COMPILE
NOTFOUND:LEA DX,M2                             LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
   MOV AH,09H
   INT 21H                                     <FILE NAME>.EXE; TO EXECUTE
TERM: MOV AH,4CH                               ELEMENT FOUND.
   INT 21H
CODE ENDS
END START




Microprocessor laboratory                                                                2
Atria Institute of Technology                                                       Dept. of Information Science

;1B) READ THE STATUS OF 8 INPUT BITS FROM THE LOGIC CONTROLLER INTERFACE AND
; DISPLAY FF IF IT IS PARITY BITS OTERWISE DISPLAY 00.ALSO DISPLAY
; NUMBER OF 1'S IN THE INPUT DATA
;CHECKED
DATA SEGMENT
     MSG DB 13,10,"NUMBER OF 1'S: $"
DATA ENDS
CODE SEGMENT
     ASSUME CS:CODE,DS:DATA
 START:MOV AX,DATA                       ;INITIALISE DATA SEGEMNT REGISTER
     MOV DS,AX
     MOV AL,82H                          ;INITIALISE CONTROL WORD REGISTER WITH CONTROL
WORD
     MOV DX,8403H
     OUT DX,AL
     MOV DX,8401H                        ;READ INPUT FROM PORT-B
     IN AL,DX
     MOV BL,AL
     AND AL,AL
     JPE EPARITY
     MOV AL,00                           ;OUTPUT 00 ON PORT-A IF ODD PARITY
     JMP DISP
EPARITY:MOV AL,0FFH                      ;OUTPUT FF ON PORT-A IF EVEN PARITY
  DISP:MOV DX,8400H
     OUT DX,AL
     LEA DX,MSG
     MOV AH,09H
     INT 21H
     MOV AH,08H
     INT 21H
     MOV CX,8                            ;COUNT NUMBER OF ONES
     MOV AL,0
   L1:ROR BL,1
     JC L2
     JMP L3
   L2:INC AL
   L3:LOOP L1
     MOV DX,8400H                        ;OUTPUT NUMBER OF 1'S ON PORT-A
     OUT DX,AL              Output
     MOV DL,AL              MASM <FILE NAME>.ASM
     ADD DL,30H             IF ERRORS / WARNINGS
     MOV AH,02H             EDIT <FILE NAME>.ASM; TO OPEN THE FILE
     INT 21H                MASM <FILE NAME>.ASM; TO COMPILE
     MOV AH,4CH             LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
     INT 21H                <FILE NAME>.EXE; TO EXECUTE
CODE ENDS
 END START                  This interface consists of eight TTL buffered outputs and eight TTL. Buffered inputs.
                            The logic state of each input/output is indicated by a corresponding LED (ON/OFF).
                            The inputs can be read through PORT_B and the outputs can be controlled through
                            PORT_A. The inputs and outputs brought to 26 pin connector. Input LEDs are
                            controlled through Dip-Switches.
                            This interface allows the user to perform experiments to understand some of the basic
                            programming techniques involved in a logic controller. The software exercise could
                            include combinational controllers, sequential controllers, programmable counters, etc.


Microprocessor laboratory                                                                                      3
Atria Institute of Technology                                   Dept. of Information Science

;2A) WRITE ALP MACROS
; (i) TO READ A CHARACTER FROM THE KEYBOARD IN THE MODULE (1)
; (IN A DIFFERENT FILE)
; {ii) TO DISPLAY A CHARACTER IN MODULE (2)(FROM DIFFERNT FILE)
; (iii)USE ABOVE TWO MODULE TO READ A STRING OF CHARACTER FROM
; THE KEYBOARD TERMINAL BY THE CARRIAGE RETURN AND PRINT THE
; STRING ON THE DISPLAY IN THE NEXT LINE
;CHECKED

DATA SEGMENT

   STR DB 80
     DB 0
     DB 80 DUP (0)
DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA
 START: INCLUDE c:\MASM\2A1.MAC         ;INCLUDE READ MACRO
    INCLUDE c:\MASM\2A2.MAC       ;INCLUDE DISPLAY MACRO
    LEA SI,STR
 LOOP1: READ_BYTE                 ;CALL MACRO TO READ CHARACTER
    MOV [SI],AL
    INC SI
    CMP AL,0DH                    ;READ A CHARACTER UNTIL ENTER KEY IS PRESSED
    JNE LOOP1
    MOV AH,03H                    ;GET CURSOR POSITION
    INT 10H
    MOV AH,02H                    ;SET CURSOR POSITION
    INT 10H
    MOV CX,SI
    DEC CX
    LEA SI,STR
 LOOP2: MOV DL,[SI]
    DISPLAY                       ;CALL MACRO TO DISPLAY CHARACTER
    INC SI
    LOOP LOOP2
    MOV AH,4CH
    INT 21H
CODE ENDS
END START                            Output
                                     MASM <FILE NAME>.ASM
                                     IF ERRORS / WARNINGS
                                     EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                     MASM <FILE NAME>.ASM; TO COMPILE
                                     LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                     <FILE NAME>.EXE; TO EXECUTE
                                     ;STRING TYPED TILL ENTER KEY TYPED.




Microprocessor laboratory                                                                4
Atria Institute of Technology                                  Dept. of Information Science

;2B) PERFORM FOLLOWINF FUNCTION USING THE LOGIC CONTROLLER INTERFACE
     (I)BCD UP-DOWN COUNTER (II)RING COUNTER

DATA SEGMENT
MSG1 DB 0AH,0DH,"PRESS ANY KEY TO SEE RING COUNTER $"
MSG2 DB 0AH,0DH,"PRESS ANY KEY TO SEE BCD UP-DOWN COUNTER $"
DATA ENDS

CODE SEGMENT
   ASSUME CS:CODE,DS:DATA
   START:MOV AX,DATA              ;INITIALISE DATA SEGMENT REGISTER
       MOV DS,AX
       LEA DX,MSG1
       MOV AH,09H
       INT 21H
       MOV AH,08H
       INT 21H
       MOV AL,82H                 ;INITIALISE CONTROL WORD REGISTER
       MOV DX,8403H
       OUT DX,AL
       MOV DX,8400H
       MOV AL,1
       MOV CX,08
     L1:OUT DX,AL                 ;DISPLAY RING COUNTER
       CALL DELAY
       SHL AL,1
       LOOP L1
       LEA DX,MSG2
       MOV AH,09H
       INT 21H
       MOV AH,08H
       INT 21H
       MOV AL,00
       MOV CX,10
       MOV DX,8400H
   L2 : OUT DX,AL                 ;DISPLAY BCD UP COUNTER
       CALL DELAY
       INC AL
       LOOP L2
       MOV CX,10
    L3: DEC AL
       OUT DX,AL                  ;DISPLAY BCD DOWN COUNTER
       CALL DELAY
       LOOP L3
        MOV AH,4CH
       INT 21H
   DELAY PROC NEAR
       PUSH AX
       PUSH CX
       PUSH DX
       MOV CX,1FFFH
       MOV DX,0FFFFH
    L5: MOV AX,0FFFFH
    L4: DEC AX


Microprocessor laboratory                                                               5
Atria Institute of Technology                                                          Dept. of Information Science

      JNZ L4
      LOOP L5
      POP DX
      POP CX
      POP AX
      RET
    DELAY ENDP
      CODE ENDS
      END START




                                Output
                                MASM <FILE NAME>.ASM
                                IF ERRORS / WARNINGS
                                EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                MASM <FILE NAME>.ASM; TO COMPILE
                                LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                <FILE NAME>.EXE; TO EXECUTE

                                 This interface consists of eight TTL buffered outputs and eight TTL.
                                Buffered inputs. The logic state of each input/output is indicated by a
                                corresponding LED (ON/OFF). The inputs can be read through PORT_B
                                and the outputs can be controlled through PORT_A. The inputs and
                                outputs brought to 26 pin connector. Input LEDs are controlled through
                                Dip-Switches.

                                This interface allows the user to perform experiments to understand some
                                of the basic programming techniques involved in a logic controller. The
                                software exercise could include combinational controllers, sequential
                                controllers, programmable counters, etc




Microprocessor laboratory                                                                                       6
Atria Institute of Technology                                  Dept. of Information Science

;3A) ASCENDING/DECENDING ORDER USING BUBBLE SORT ALGORITHM
;CHECKED

DATA SEGMENT
ARRAY DB 05H,06h,01H,03H,61H
NOE DB NOE-ARRAY                ;TO FIND NUMBER OF ELEMENT
DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA
   MOV DS,AX
   LEA AX,ARRAY
   MOV BL,NOE
   DEC BL
 LOOP1:MOV CL,BL
   MOV SI,00H
 LOOP2:MOV AH,ARRAY[SI]
   INC SI
   CMP AH,ARRAY[SI]
   JLE LOOP3                    ;ASCENDING ORDER(FOR DECENDING ORDER USE JGE )
   XCHG AH,ARRAY[SI]
   MOV ARRAY[SI-1],AH
 LOOP3:loop loop2
   DEC BL
   JNZ LOOP1
   MOV AH,4CH
   INT 21H                       Output
CODE ENDS                        MASM <FILE NAME>.ASM
END START
                                 IF ERRORS / WARNINGS
                                 EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                 MASM <FILE NAME>.ASM; TO COMPILE
                                 LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                 TD <FILE NAME>.EXE; TO EXECUTE
                                 01,03,05,06,61,05 (NUMBER OF ELEMENTS)




Microprocessor laboratory                                                               7
Atria Institute of Technology                                                 Dept. of Information Science

;3B) READ THE STATUS OF TWO 8 BIT INPUT (X & Y) FROM LOGIC
; CONTROLLER INTERFACE AND DISPLAY X * Y

DATA SEGMENT
   MSG1 DB 0AH,0DH,'ENTER X FROM LOGIC CONTROLLER AND PRESS ANY KEY$'
   MSG2 DB 0AH,0DH,'ENTER Y FROM LOGIC CONTROLLER AND PRESS ANY KEY$'
DATA ENDS
CODE SEGMENT
    ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
   MOV DS,AX                       ;INITIALISE DATA SEGMENT REGISTER
   MOV DX,8403H
   MOV AL,82H                      ;INITIALISE CONTROL WORD
   OUT DX,AL
   LEA DX,MSG1
   MOV AH,09H
   INT 21H
   MOV AH,08                       ;DISPLAY MESSAGE1 & WAIT UNTIL ANY KEY IS PRESSED
   INT 21H
   MOV DX,8401H
   IN AL,DX                        ;READ X FROM PORT-A
   MOV BL,AL
   LEA DX,MSG2                     ;DISPLAY MESSAGE2 & WAIT UNTIL ANY KEY IS PRESSED
   MOV AH,09H
   INT 21H
   MOV AH,08H
   INT 21H
   MOV DX,8401H
   IN AL,DX                        ;READ Y FROM PORT-A
   MOV AH,00
   MUL BL                          ;MULTIPLY X & Y
   MOV DX,8400H
   OUT DX,AL                       ;DISPLAY OUTPUT ON PORT-A
   MOV AH,4CH
   INT 21H
CODE ENDS                       Output
   END START                    MASM <FILE NAME>.ASM
                                IF ERRORS / WARNINGS
                                EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                MASM <FILE NAME>.ASM; TO COMPILE
                                LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                <FILE NAME>.EXE; TO EXECUTE

                                          This interface consists of eight TTL buffered outputs and eight TTL.
                                  Buffered inputs. The logic state of each input/output is indicated by a
                                  corresponding LED (ON/OFF). The inputs can be read through PORT_B
                                  and the outputs can be controlled through PORT_A. The inputs and outputs
                                  brought to 26 pin connector. Input LEDs are controlled through Dip-
                                  Switches.


                                    This interface allows the user to perform experiments to understand some
                                  of the basic programming techniques involved in a logic controller. The
                                  software exercise could include combinational controllers, sequential
                                  controllers, programmable counters, etc.

Microprocessor laboratory                                                                                 8
Atria Institute of Technology                                Dept. of Information Science

;4A) READ AN ALPHANUMERIC CHARACTER AND DISPLAY ITS EQUIVALENT
; ASCII CODE AT THE CENTER OF THE SCREEN.

;CHECKED

CODE SEGMENT

ASSUME CS:CODE

   MOV AH,08H
   INT 21H
   PUSH AX
   MOV AH,07H                   ;CLEAR SCREEN
   MOV AL,00
   MOV BH,0FH                   ;PAGE
   MOV CL,00
   MOV CH,00
   MOV DH,24D                   ;ROW
   MOV DL,79D                   ;COLUMN
   INT 10H
   MOV AH,02H                   ;ACTIVATE THE CURSOR
   MOV BH,00                    ;PAGE
   MOV DH,00                    ;X
   MOV DL,00                    ;Y
   INT 10H
   MOV DH,12                    ;PLACE CURSOR AT THE CENTER OF THE SCREEN
   MOV DL,40                    ;DECIMAL
   MOV AH,02H                   ;DECIMAL
   INT 10H
   POP AX
   MOV BL,AL
   AND AL,0F0H                  ;CONVERTION
   MOV CL,04
   ROR AL,CL
   CMP AL,0AH
   JL NEXT1
   ADD AL,07
NEXT1: ADD AL,30H
   MOV DL,AL
   MOV AH,02H                   ;FUNCTION TO DISPLAY ON SCREEN
   INT 21H
   MOV AL,BL
   AND AL,0FH
   CMP AL,0AH
   JL NEXT2                         Output
   ADD AL,07H
NEXT2: ADD AL,30H                   MASM <FILE NAME>.ASM
   MOV DL,AL                        IF ERRORS / WARNINGS
   MOV AH,02H
   INT 21H                          EDIT <FILE NAME>.ASM; TO OPEN THE FILE
   MOV AH,4CH                       MASM <FILE NAME>.ASM; TO COMPILE
   INT 21H
CODE ENDS                           LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
END                                 <FILE NAME>.EXE; TO EXECUTE


Microprocessor laboratory                                                             9
Atria Institute of Technology                                    Dept. of Information Science

;4B) DISPLAY MESSAGE FIRE AND HELP ALTERNALITY WITH FLICKERING EFFECTS
; ON A 7-SEGMNET DISPLAY INTERFACE FOE A SUITABLE PERIOD OF TIME.
; ENSURE AFLASHING RATE THAT MAKES IT EASY TO READ BOTH THE
; MESSAGS (EXAMINER DOES NOT SPECIFY THESE DELAY VALUE NOR
; IT IS NECESSARY FOR THE STUDENT TO COMPUTE THESE VALUES).

DATA SEGMENT
   N1 DB 86H,88H,0F9H,8EH       ;CODE FOR "ERIF"
   N2 DB 8CH,0C7H,86H,89H       ;CODE FOR "PLEH"
DATA ENDS

CODE SEGMENT

ASSUME CS:CODE;DS:DATA

 START:MOV AX,DATA
   MOV DS,AX                    ;INITIALISE DATA SEGMENT REGISTER
   MOV DX,8403H
   MOV AL,80H                   ;INITIALISE CONTROL WORD REGISTER
   OUT DX,AL
   MOV CX,04                    ;INITIALISE NUMBER OF TIMES TO REPEAT THE MESSAGE
 AGAIN:LEA SI,N1                ;LOAD FIRST MESSAGE
   PUSH CX
   CALL DISPLAY                 ;DISPLAY FIRST MESSAGE
   CALL DELAY
   LEA SI,N2                    ;LOAD SECOND MESSAGE
   CALL DISPLAY                 ;DISPLAY SECOND MESSAGE
   CALL DELAY
   POP CX
   LOOP AGAIN                   ;REPEAT COUNT FOR N TIMES
   MOV AH,4CH
   INT 21H

  DISPLAY PROC NEAR             ;PROCEDURE TO DISPLAY MESSAGE
    PUSH AX
    PUSH BX
    PUSH CX
    PUSH DX
    MOV CX,04H                  ;INITIALISE CX WITH NUMBER OF DIGITS
 LOOP2:MOV BL,08H               ;INITIALISE BL WITH 8 BITS FOR EACH SEGMENT
    MOV AL,[SI]                        ;LOAD FIRST CHARACTER OF THE MESSAGE
 LOOP3:MOV DX,8401H
    ROL AL,01H                  ;BRING THE MSB TO LSB POSITION
    OUT DX,AL                   ;OUT ON PORT-B
    MOV BH,AL
    MOV DX,8402H
    MOV AL,0FFH                 ;APPLY HIGH(FF) CLOCK PULSE THROUGH PORT-A
    OUT DX,AL
    MOV AL,00H                  ;APPLY LOW(00) CLOCK PULSE THROUGH PORT-A
    OUT DX,AL
    DEC BL
    JZ DOWN1                    ;REPEAT FOR 8 BITS
    MOV AL,BH
    JMP LOOP3


Microprocessor laboratory                                                                 10
Atria Institute of Technology                                                             Dept. of Information Science

 DOWN1:INC SI
   LOOP LOOP2                                   ;REPEAT FOR 4 DIGITS
   POP DX
   POP CX
   POP BX
   POP AX
   RET
DISPLAY ENDP

DELAY PROC NEAR
   PUSH AX
   PUSH CX
   PUSH DX
   MOV CX,0FFFH
   MOV DX,0FFF
 L5:MOV AX,0FFFFH
 L4:DEC AX
   JNZ L4
   LOOP L5
   POP DX
   POP CX
   POP AX
   RET
DELAY ENDP

CODE ENDS
  END START



              Output

              MASM <FILE NAME>.ASM
              IF ERRORS / WARNINGS
              EDIT <FILE NAME>.ASM; TO OPEN THE FILE
              MASM <FILE NAME>.ASM; TO COMPILE
              LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
              <FILE NAME>.EXE; TO EXECUTE
              After execution of this program it displays suitable message of FIRE & HELP starting
              from left to right (left entry) on a 7-segment display interface for a suitable period of
              time




Microprocessor laboratory                                                                                          11
Atria Institute of Technology                                  Dept. of Information Science

;5A)REVERSE A GIVEN STRING AND CHECK WHETHER IT IS A PALINDROME
;    OR NOT.
;CHECKED

PRINTSTRING MACRO NUM,MES
MOV AH,NUM
LEA DX,OFFSET MES
INT 21H
ENDM

DATA SEGMENT
M1 DB 0AH,0DH,'ENTER A STRING : $'
M2 DB 0AH,0DH,'REVERSED STRING : $'
M3 DB 0AH,0DH,'STRING IS PALINDROME $'
M4 DB 0AH,0DH,'STRING IS NOT PALINDROME $'
BUFF DB 80
  DB 00
  DB 80
DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA
   MOV DS,AX
   PRINTSTRING 09H,M1               ;DISPLAY THE MESSAGE M1
   PRINTSTRING 0AH,BUFF             ;GET THE STRING
   PRINTSTRING 09H,M2               ;DISPLAY THE MESSAGE M2
   LEA BX,BUFF+2                    ;GET START ADDRESS
   MOV CH,00H
   MOV CL,BUFF+1
   MOV DI,CX
   DEC DI
   MOV SI,00H
   PUSH CX

FRI: MOV DL,[BX+DI]                 ;PROCEDURE REVERSE
   MOV AH,02H
   INT 21H
   DEC DI
   LOOP FRI
   POP CX
   MOV DI,CX
   DEC DI
BACK: MOV AL,[BX+DI]                ;PROCEDURE: PALINDROME GETS RIGHT
   MOV AH,[BX+SI]                   ;GET LEFT CHARACTER
   CMP AL,AH
   JNZ LAST
   DEC DI
   INC SI
   LOOP BACK
   PRINTSTRING 09H,M3
   JMP EXIT


Microprocessor laboratory                                                               12
Atria Institute of Technology                       Dept. of Information Science

 LAST: PRINTSTRING 09H,M4
 EXIT: MOV AH,4CH
    INT 21H
CODE ENDS
END START


        Output
        MASM <FILE NAME>.ASM
        IF ERRORS / WARNINGS
        EDIT <FILE NAME>.ASM; TO OPEN THE FILE
        MASM <FILE NAME>.ASM; TO COMPILE
        LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
        <FILE NAME>.EXE; TO EXECUTE
        ENTER A STRING: MADAM
        REVERSED STRING; MADAM
        STRING IS A PALINADROME




Microprocessor laboratory                                                    13
Atria Institute of Technology                                      Dept. of Information Science

;5B) ASSUME ANY SUITABLE MESSAGE OF 12 CHARACTER LENGTH AND DISPLAY
; IT IN THE ROLLING FASHION ON A SEGMENT DISPLAY INTERFACE
; FOR A SUITABLE PERIOD OF TIME

DATA SEGMENT
   N1 DB 86H,88H,0F9H,8EH,0FFH,0FFH,0FFH,0FFH,8CH,0C7H,86H,89H
DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA
   START:MOV AX,DATA
      MOV DS,AX                      ;INITIALISE DATA SEGMENT REGISTER
      MOV DX,8403H
      MOV AL,80H                     ;INITIALISE CONTROL WORD REGISTER
       OUT DX,AL
      MOV CX,2                       ;INITIALISE NUMBER OF TIMES TO DISPLAY MESSAGE
   AGAIN:MOV BX,12                   ;LOAD NUMBER OF CHARACTER
      MOV SI,OFFSET N1
       PUSH CX
    L1: CALL DISP                    ;DISPLAY THE CHARACTER
       CALL DELAY
       INC SI
       DEC BX
      JNZ L1
       POP CX
       LOOP AGAIN                    ;REPEAT THE DISPLAY FOR N TIMES
      MOV AH,4CH
       INT 21H

DISP PROC NEAR
       PUSH AX
       PUSH BX
       PUSH CX
       PUSH DX
       MOV BL,08H                    ;INITIALISE BL WITH 8 BITS FOR EACH SEGMENT
       MOV AL,[SI]                   ;GET FIRST CHARACTER
      L2:ROL AL,01                   ;MOVE MSB TO LSB POSITION
       MOV DX,8401H
       OUT DX,AL                     ;SENT FIRST CHARACTER TO PORT-B
       PUSH AX
       MOV AL,0FFH                   ;APPLY CLOCK PULSE(HIGH=FF) TO PORT-C
       MOV DX,8402H
       OUT DX,AL
       MOV AL,00H                    ;APPLY CLOCK PULSE(LOW=00) TO PORT-C
       OUT DX,AL
       DEC BL
       POP AX
       JZ L3
       JMP L2                        ;REPEAT FOR 8 BITS
     L3: POP DX
       POP CX
       POP BX
       POP AX


Microprocessor laboratory                                                                   14
Atria Institute of Technology                                                             Dept. of Information Science

       RET
DISP ENDP

DELAY PROC NEAR
      PUSH AX
      PUSH BX
      PUSH DX
      PUSH CX
      MOV DX,0FFFFH
      MOV CX,0FFFH
    L5: MOV AX,0FFFFH
    L4: DEC AX
      JNZ L4
      LOOP L5
      POP DX
      POP CX
      POP BX
      POP AX
      RET
DELAY ENDP
CODE ENDS
      END START




      Output

      MASM <FILE NAME>.ASM
      IF ERRORS / WARNINGS
      EDIT <FILE NAME>.ASM; TO OPEN THE FILE
      MASM <FILE NAME>.ASM; TO COMPILE
      LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
      <FILE NAME>.EXE; TO EXECUTE

      After execution of this program it displays suitable message of 12 character length in
      the rolling fashion on a 7-segment display interface for a suitable period of time




Microprocessor laboratory                                                                                          15
Atria Institute of Technology                             Dept. of Information Science

;6A) READ TWO STRINGS,STORE THEM IN LOCATIONS STR1 AND STR2. CHECK
; WHETHER THEY ARE EQUAL OR NOT AND DISPLAY APPROPRIATE MESSAGES.
; ALSO DISPLAY THE LENGTH OF THE STORED STRINGS.
;checked
;MACRO TO DISPLAY THE STRING AND TO READ THE STRING

IO MACRO FUN,MSG
    MOV AH,FUN
    MOV DX,OFFSET MSG
    INT 21H
ENDM

;MACRO TO DISPLAY A CHARACTER
; ( DL CONTAINS THE CHARACTER TO BE DISPLAYED )
CONVERT MACRO
     LOCAL NEXT1
     CMP DL,0AH
     JL NEXT1
     ADD DL,07H
     NEXT1:ADD DL,30H
     MOV AH,02H
     INT 21H
ENDM

PUTCHAR MACRO P1
   MOV DL,P1
   AND DL,0F0H
   MOV CL,04
   ROR DL,CL
   CONVERT
   MOV DL,P1
   AND DL,0FH
   CONVERT
ENDM

DATA SEGMENT
   MSG1 DB "ENTER THE STRING 1 :$"
   BUFF1 DB 80
      DB 00
      DB 80 DUP(?)

    MSG2 DB 0AH,0DH,"ENTER THE STRING 2 :$"
    BUFF2 DB 80
      DB 00
      DB 80 DUP(?)

   MSGEQ DB 0AH,0DH,"STRINGS ARE EQUAL $"
   MSGNEQ DB 0AH,0DH,"STRINGS ARE NOT EQUAL $"
   MSGLEN1 DB 0AH,0DH,"LENGTH OF THE STRING 1 = $"
   MSGLEN2 DB 0AH,0DH,"LENGTH OF THE STRING 2 = $"
DATA ENDS
CODE SEGMENT

ASSUME CS:CODE,DS:DATA


Microprocessor laboratory                                                          16
Atria Institute of Technology                                     Dept. of Information Science

START: MOV AX,DATA
   MOV DS,AX
   MOV ES,AX                      ;FOR STRING MANIPULATION

    IO 09H,MSG1
    IO 0AH,BUFF1

    IO 09H,MSG2
    IO 0AH,BUFF2
    ;COMPARE THE LENGTH OF THE TWO STRINGS
    MOV AL,BUFF1+1
    CMP AL,BUFF2+1
    JNE NEQUAL

    ;STORE THE NUMBER OF CHARACTERS TO BE COMPARED

    MOV CL,BUFF1+1
    MOV CH,00

    ;COMPARE TWO STRINGS STR1 AND STR2

    MOV SI,OFFSET BUFF1+2
    MOV DI,OFFSET BUFF2+2
    CLD          ;CLEAR DIRECTION FLAG
    REPE CMPSB
    JNE NEQUAL
    IO 09H,MSGEQ
    JMP DIS_LEN
NEQUAL: IO 09H,MSGNEQ
DIS_LEN:IO 09H,MSGLEN1
    PUTCHAR BUFF1+1
    IO 09H,MSGLEN2
    PUTCHAR BUFF2+1
    MOV AH,4CH
    INT 21H
CODE ENDS                            Output
END START
                                     MASM <FILE NAME>.ASM
                                    IF ERRORS / WARNINGS
                                    EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                    MASM <FILE NAME>.ASM; TO COMPILE
                                    LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                    <FILE NAME>.EXE; TO EXECUTE
                                    ENTER THE STRING1 : MANGO
                                    ENTER THE STRING2 : APPLE
                                    STRING ARE NOT EQUAL
                                    LENGTH OF STRING1 : 5
                                    LENGTH OF STRING2 : 5




Microprocessor laboratory                                                                  17
Atria Institute of Technology                                     Dept. of Information Science

;6B) CONVERT A 16 BIT BINARY VALUE(ASSUMED TO BE UNSIGNED INTEGER) TO BCD
; AND DISPLAY IT FROM LEFT TO RIGHT AND RIGHT TO LEFT FOR SPECIFIED
; NUMBER OF TIMES ON A 7-SEGMENT DISPLAY INTEGER

DATA SEGMENT

SDIGIT DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,90H
NUM DW 00FH
RL DB 12 DUP(?)
TEMP DW ?
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
    MOV AX,DATA
    MOV DS,AX
    MOV CX,2                          ;INITIALISE NUMBER OF TIMES TO SCROLL THE MESSAGE
    MOV TEMP,CX
 START:MOV SI,OFFSET RL               ;STORE 4 BLACKS IN RIGHT TO LEFT ARRAY
    MOV CX,4
  L1:MOV AL,0FFH
    MOV [SI],AL
    INC SI
    LOOP L1
    ADD SI,4
    MOV AL,80H
    MOV DX,8403H
    OUT DX,AL
    XOR DX,DX                         ;CONVERT BINARY NUMBER TO BCD NUMBER
    MOV AX,NUM
    MOV CX,100
    DIV CX
    AAM
    XCHG AX,DX
    AAM
    PUSH AX
    PUSH DX
    CALL TRANS                        ;GET 7 SEGMENT VALUE FOT FOURTH BCD DIGIT
    DEC SI
    MOV [SI],AL                       ;SAVE IT IN ARRAY
    CALL DISP                         ;DISPLAY IT ON SEVEN SEGMENT LED FROM LEFT TO RIGHT
    CALL DELAY                        ;DELAY TO HAVE SCROLLING EFFECT
    POP DX
    POP AX
    MOV AL,AH
    PUSH AX
    PUSH DX
    CALL TRANS                        ;GET 7 SEGMENT VALUE FOR THIRD BCD DIGIT
    DEC SI
    MOV [SI],AL
    CALL DISP
    CALL DELAY
    POP DX
    POP AX
    MOV AL,DL


Microprocessor laboratory                                                                  18
Atria Institute of Technology                                 Dept. of Information Science

    PUSH AX
    PUSH DX
    CALL TRANS                  ;GET 7 SEGMENT VALUE FOR SECOND BCD DIGIT
    DEC SI
    MOV [SI],AL
    CALL DISP
    CALL DELAY
    POP DX
    POP AX
    MOV AL,DH
    PUSH AX
    PUSH DX
    CALL TRANS                  ;GET 7 SEGMENT VALUE FOR FIRST BCD DIGIT
    DEC SI
    MOV [SI],AL
    CALL DISP
    CALL DELAY
    MOV CX,4                    ;SCROLL 4 BCD DIGITS BY SENDING 4 BLANKS
    MOV AL,0FFH
    ADD SI,4
  L2:CALL DISP
    CALL DELAY
    MOV [SI],AL
    INC SI
    LOOP L2
    MOV SI,OFFSET RL            ;SCROLL BCD FROM RIGHT TO LEFT
    ADD SI,4
    MOV DI,0
  L3:MOV CX,4
  L4:MOV AL,[SI]
    CALL DISP
    DEC SI
    LOOP L4
    CALL DELAY
    INC DI
    MOV SI,OFFSET RL
    ADD SI,DI
    ADD SI,4
    CMP DI,8
    JNE L3
    MOV CX,TEMP
    DEC CX
    MOV TEMP,CX
    JNZ FAR PTR START           ;REPEAT SCROLLING FOR SPECIFIED NUMBER OF TIMES
    MOV AH,4CH
    INT 21H
TRANS PROC NEAR                 ;PROCEDURE FOR CONVERTING BCD DIGIT
    MOV BX,OFFSET SDIGIT        ;TO SEVEN SEGMENT VALUE
    XLAT
    RET
TRANS ENDP
DISP PROC NEAR                  ;PROCEDURE TO DISPLAY SEVEN SEGMENT VALUE
    PUSH AX
    PUSH BX


Microprocessor laboratory                                                              19
Atria Institute of Technology                                                            Dept. of Information Science

    PUSH CX
    PUSH DX
    MOV CX,8
 AGAIN:ROL AL,1                                 ;BRING MSB TO LSB
    MOV DX,8401H
    OUT DX,AL
    PUSH AX
    MOV AL,0FFH                                 ;SEND HIGH CLOCK PULSE
    MOV DX,8402H
    OUT DX,AL
    MOV AL,00H                                  ;SEND LOW CLOCK PULSE
    OUT DX,AL
    POP AX
    LOOP AGAIN
    POP DX
    POP CX
    POP BX
    POP AX
    RET
DISP ENDP
DELAY PROC NEAR
    PUSH AX
    PUSH DX
    PUSH CX
    MOV DX,0FFFFH
    MOV CX,0FFFH
  L5: MOV AX,0FFFFH
  L6: DEC AX
    JNZ L6
    LOOP L5
    POP DX
    POP CX
    POP AX
    RET
DELAY ENDP
CODE ENDS
END

     Output

     MASM <FILE NAME>.ASM
     IF ERRORS / WARNINGS
     EDIT <FILE NAME>.ASM; TO OPEN THE FILE
     MASM <FILE NAME>.ASM; TO COMPILE
     LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
     <FILE NAME>.EXE; TO EXECUTE

     After execution of this program it displays 65535 on a 7-segment display(SSD) from left to right and right to
     left because the binary input is FFFFH.




Microprocessor laboratory                                                                                            20
Atria Institute of Technology                               Dept. of Information Science

;7A) READ YOUR NAME FOM THE KEYBOARD AND DISPLAY IT AT A SPECIFIED
   ; LOCATION ON THE SCREEN IN FRONT OF THE MESSAGE "WHAT IS YOUR
   ; NAME ?". YOU MUST CLEAR THE ENTIRE SCREEN BEFORE DISPLAY.
   ;CHECKED
   ;MACRO TO PLACE THE CURSOR

   PLACE MACRO X,Y
      MOV AH,02H
      MOV DH,X
      MOV DL,Y
      INT 10H
   ENDM

   ;MACRO TO DISPLAY STRING

   DIS_MSG MACRO P1
       MOV AH,09H
       LEA DX,P1
       INT 21H
   ENDM

   ;MACRO TO READ STRING

   READ_STRING MACRO P2
      MOV AH,0AH
      LEA DX,P2
      INT 21H
   ENDM

   DATA SEGMENT


      M2 DB 'WHAT IS YOUR NAME ?$'
      STR DB 50
        DB 00
        DB 50 DUP(0)
   DATA ENDS

   CODE SEGMENT

   ASSUME DS:DATA,CS:CODE

   START: MOV AX,DATA
      MOV DS,AX

        MOV AH,07H                   ;CLEAR SCREEN
        MOV AL,00
        MOV BH,0FH                   ;PAGE
        MOV CL,00
        MOV CH,00                    ;ROW
        MOV DH,24H                   ;COLUMN
        MOV DL,79H
        INT 10H                      ;ACTIVATE THE CURSOR
        MOV AH,02H


Microprocessor laboratory                                                            21
Atria Institute of Technology                                     Dept. of Information Science

        MOV BH,00
        MOV DH,00
        MOV DL,00                    ;TO PLACE THE CURSOR IN PATICULAR POSITION
        PLACE 0AH,05H
        DIS_MSG M2
        READ_STRING STR
        MOV AH,4CH
        INT 21H

   CODE ENDS
   END START


      Output
      MASM <FILE NAME>.ASM
      IF ERRORS / WARNINGS
      EDIT <FILE NAME>.ASM; TO OPEN THE FILE
      MASM <FILE NAME>.ASM; TO COMPILE
      LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
      <FILE NAME>.EXE; TO EXECUTE
      WHAT IS YOUR NAME ? PRITI




Microprocessor laboratory                                                                  22
Atria Institute of Technology                                                        Dept. of Information Science

;7b)Drive a stepper motor interface to rotate the mtor in clockwise
; direction by N steps(N is specified by examiner). Introduce
; suitable delay between successive steps (Any arbitrary value
; for the delay may be assumed by the student

DATA SEGMENT

N DW 05

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

STaRT: MOV AX,DATA
    MOV DS,AX
    MOV DX,8403H
    MOV AL,80H                               ;INITIALIZE CONTROL WORD REGISTER
    OUT DX,AL
    MOV DX,8400H
    MOV AL,88h                               ;INITIALISE THE MODE
    MOV Cx,N                                 ;ROTATE FOR N STEPS
  L1: OUT DX,AL                              ;ROTATE THE MOTOR
    PUSH CX
    CALL DELAY
    ROR AL,01
    POP CX
    LOOP L1
    MOV AH,4CH
    INT 21H

DELAY PROC NEAR
    PUSH AX
    PUSH DX
    MOV CX,20H
  L2: MOV AX,0FFFFH
  L3: DEC AX
    JNZ L3
    LOOP L2
    POP DX
    POP AX
    RET                                   Output
DELAY ENDP                                MASM <FILE NAME>.ASM
CODE ENDS                                 IF ERRORS / WARNINGS
END START                                 EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                          MASM <FILE NAME>.ASM; TO COMPILE
                                          LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                          <FILE NAME>.EXE; TO EXECUTE

                                          In this stepper motor programs only CPU would use port A of 8255
                                          PPI. To send the data to the stepper motors port A must be
                                          programmed as an output. Stepper motor rotates for each step in Anti-
                                          clockwise direction


Microprocessor laboratory                                                                                         23
Atria Institute of Technology                                   Dept. of Information Science

;8A) COMPUTE THE FACTORIAL OF A POSITIVE INTEGER 'N' USING
; RECURSIVE PROCEDURE.
;CHECKED


DATA SEGMENT
  N DW 05
  RES DW ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
  MOV DS,AX
  MOV CX,N
  CMP CX,00
  MOV AX,01H
  JE RESULT
  CALL FACT

RESULT:MOV RES,AX                 ;RESULT IS STORED IN RES LOCATION
  MOV AH,4CH
  INT 21H

FACT PROC NEAR
  CMP CX,01H
  JE NEXT

  PUSH CX
  DEC CX
  CALL FACT
  POP CX
  MUL CX
  RET
NEXT:MOV AX,01H
  RET
FACT ENDP

CODE ENDS
END START

                                 Output
                                 MASM <FILE NAME>.ASM
                                 IF ERRORS / WARNINGS
                                 EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                 MASM <FILE NAME>.ASM; TO COMPILE
                                 LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                 <FILE NAME>.EXE; TO EXECUTE
                                 INPUT IS IN DECIMAL; 04
                                 OUTPUT IN HEXADECIMAL; 18


Microprocessor laboratory                                                                24
Atria Institute of Technology                                                       Dept. of Information Science

;8b)Drive a stepper motor interface to rotate the motor in
; anticlockwise direction by N steps(N is specified by examiner).
; Introduce suitable delay between successive steps (Any arbitrary
; value for the delay may be assumed by the student).

DATA SEGMENT

N DW 05

DATA ENDS

CODE SEGMENT

ASSUME CS:CODE, DS:DATA

SATRT: MOV AX,DATA
    MOV DS,AX
    MOV DX,8403H                             ;INTIALIZE THE CONTROL WORD
    MOV AL,80H
    OUT DX,AL
    MOV DX,8400H
    MOV AL,                                  ;INITALISE THE STEP MODE
    MOV CH,N                                 ;ROTATE FOR N STEPS
  L1: OUT DX,AL
    PUSH CX
    CALL DELAY
    ROL AL.01                                ;ANTICLOCKWISE DIRECTION
    POP CX
    LOOP L1
    MOV AH,4CH
    INT 21H

DELAY PROC NEAR
   PUSH AX
   PUSH DX
   MOV CX,20H
 L2: MOV AX,0FFFFH
 L3: DEC AX
   JNZ L3
   LOOP L2
   POP DX                       Output
   POP AX                       MASM <FILE NAME>.ASM
   RET                          IF ERRORS / WARNINGS
DELAY ENDP                      EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                MASM <FILE NAME>.ASM; TO COMPILE
CODE ENDS                       LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
END START                       <FILE NAME>.EXE; TO EXECUTE

                                In this stepper motor programs only CPU would use port A of 8255 PPI. To send the
                                data to the stepper motors port A must be programmed as an output. Stepper motor
                                rotates for each step in clockwise direction




Microprocessor laboratory                                                                                       25
Atria Institute of Technology                                   Dept. of Information Science

;9A) COMPUTE NCR USING RECURSIVE PROCEDURE. ASSUME THAT 'N' AND 'R'
; ARE NON-NEGATIVE NUMBER
;CHECKED

DATA SEGMENT
   N DB 05H
   R DB 03H
   NCR DB ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA
   MOV DS,AX
   MOV NCR,00
   MOV AL,N
   MOV BL,R
   CALL NCRP
   MOV AH,4CH
   INT 21H
NCRP PROC
   CMP BL,00
   JE RES

    CMP bL,aL
    JE RES
    dec al

   CMP BL,01
   JE RESULT
    CMP AL,BL
   JE RESULT
   PUSH AX
   PUSH BX
   CALL NCRP
   POP BX
   POP AX
   DEC BL
   PUSH AX
                                                Output
   PUSH BX
   CALL NCRP                                    MASM <FILE NAME>.ASM
   POP BX
                                                IF ERRORS / WARNINGS
   POP AX
   RET                                          EDIT <FILE NAME>.ASM; TO OPEN THE FILE
 RES: INC NCR
                                                MASM <FILE NAME>.ASM; TO COMPILE
   RET
RESULT:INC NCR                                  LINK <FILE NAME>.OBJ; TO LINK OBJECT
   ADD NCR,AL
                                                FILE
   RET
NCRP ENDP                                       <FILE NAME>.EXE; TO EXECUTE
                                                INPUT : 05 03
CODE ENDS
END START                                       OUTPUT : 0A


Microprocessor laboratory                                                                26
Atria Institute of Technology                                                      Dept. of Information Science

;9b) Drive a stepper motor interface to rotate the motor in clockwise
; and anticlockwise direction by N steps(N is specified by examiner).
; Introduce suitable delay between successive steps (Any arbitrary
; value for the delay may be assumed by the student

DATA SEGMENT
N DW 05

DATA ENDS
CODE SEGMENT

ASSUME CS:CODE, DS:DATA

SATRT: MOV AX,DATA
    MOV DS,AX
    MOV DX,8403H
    MOV AL,80H
    OUT DX,AL
    MOV DX,8400H
    MOV AL,
    MOV CH,N
  L1: OUT DX,AL
    PUSH CX
    CALL DELAY
    ROR AL.01                               ;CLOCKWISE ROTATION
    POP CX
    LOOP L1
    MOV DX,8400H
    MOV AL,
    MOV CH,N
  L2: OUT DX,AL
    PUSH CX
    CALL DELAY
    ROL AL.01                               ;ANTICLOCKWISE ROTATION
    POP CX
    LOOP L2
    MOV AH,4CH
    INT 21H

DELAY PROC NEAR                                  Output
   PUSH AX                                       MASM <FILE NAME>.ASM
   PUSH DX                                       IF ERRORS / WARNINGS
   MOV CX,20H                                    EDIT <FILE NAME>.ASM; TO OPEN THE FILE
 L4: MOV AX,0FFFFH                               MASM <FILE NAME>.ASM; TO COMPILE
 L3: DEC AX                                      LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
   JNZ L3                                        <FILE NAME>.EXE; TO EXECUTE
   LOOP L4
   POP DX                                        In this stepper motor programs only CPU would use port A of 8255
   POP AX                                        PPI. To send the data to the stepper motors port A must be
   RET                                           programmed as an output. Stepper motor rotates for each step in
DELAY ENDP                                       Anti-clockwise and clockwise direction

CODE ENDS
END START


Microprocessor laboratory                                                                                     27
Atria Institute of Technology                                          Dept. of Information Science

;10A) FIND OUT WHETHER A GIVEN SUB-STRING IS PRESENT OR NOT IN A 'N'
; STRING OF CHARACTERS.

;MACRO DEFINITION
;CHECKED
DIS_MSG MACRO PL
    MOV AH,09H
    LEA DX,PL
    INT 21H
ENDM

DATA SEGMENT
   STR DB 'RAJIV GANDHI INSTITUTE OF TECHNOLOGY'
   LEN1 DW LEN1-STR
   SSTR DB 'R'
   M1 DB 'SUB STRING IS FOUND.$'
   M2 DB 'SUB STRING IS NOT FOUND.$'
DATA ENDS

CODE SEGMENT

ASSUME CS:CODE,DS:DATA

START: MOV AX,DATA
   MOV DS,AX
   MOV ES,AX
   MOV CX,LEN1
   LEA SI,STR
LOOP1: LEA DI,SSTR
LOOP3: MOV AL,[SI]
   INC SI
   DEC CX
   CMP AL,[DI]
   JNE LOOP2
   INC DI
   CMP DI,OFFSET M1
   JE MES1
   JMP LOOP3

LOOP2: CMP CX,0H
   JNE LOOP1
   CMP DI,OFFSET M1
   JE MES1
                                             Output
 l1: DIS_MSG M2                              MASM <FILE NAME>.ASM
    JMP TER
MES1: DIS_MSG M1                             IF ERRORS / WARNINGS
                                             EDIT <FILE NAME>.ASM; TO OPEN THE FILE
 TER: MOV AH,4CH
   INT 21H                                   MASM <FILE NAME>.ASM; TO COMPILE
CODE ENDS                                    LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
END START
                                             <FILE NAME>.EXE; TO EXECUTE
                                             SUBSTR IS NOT FOUND


Microprocessor laboratory                                                                       28
Atria Institute of Technology                                      Dept. of Information Science

;10B) SCAN A 8X3 KEYPAD FOR CLOSURE & STORE THE CODE OF THE
; KEY PRESSED IN A MEMORY LOCATION OR DISPLAY ON SCREEN.
; ALSO DISPLAY ROW & COLUMN NUMBER OF THE KEY PRESSED.

;CHECKED
DATA SEGMENT
KEYS DB '0123456789ABCDEFGHIJKLMNO'
MSG1 DB 0AH,0DH,'THE ROW NUMBER IS:$'
ROW DB ?
MSG2 DB 0AH,0DH,'THE COLUMN NUMBER IS:$'
COL DB ?


DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
   MOV DS,AX                       ;INITIALISE DATA SEGMENT
   MOV AL,90H                      ;INITIALISE CONTROL WORD REGISTER
   MOV DX,8403H
   OUT DX,AL
SCANC1:MOV DX,8402H                ;SCAN COLUMN-1
   MOV AL,01
   OUT DX,AL
   MOV DX,8400H                    ;READ INPUT PORT-A
   IN AL,DX
   CMP AL,00                       ;IF KEY PRESSED GOTO COL1
   JNZ COL1
SCANC2:MOV DX,8402H
   MOV AL,02                       ;SCAN COLUMN-2
   OUT DX,AL
   MOV DX,8400H
   IN AL,DX                                ;READ INPUT PORT-A
   CMP AL,00
   JNZ COL2                        ;IF KEY PRESSED GOTO COL2
SCANC3:MOV DX,8402H
   MOV AL,04                       ;SCAN COLUMN-3
   OUT DX,AL
   MOV DX,8400H
   IN AL,DX                        ;READ INPUT PORT-A
   CMP AL,00
   JNZ COL3                        ;IF KEY PRESSED GOTO COL3
   JMP SCANC1                      ;IF NO KEY PRESSED SCAN AGAIN
 COL1:CALL DELAY                   ;CALL DELAY FOR DEBOUNCING EFFECT
   MOV COL,31H                     ;INITIALISE COLUMN WITH ASCII CODE OF KEY PRESSED
   MOV CL,30H                      ;INITIALISE CL WITH ASCII CODE OF ROW
   MOV SI,OFFSET KEYS                     ;INITIALISE SI WITH ASCII CODE ADDRESSS OF FIRST
COLUMN
  L1:SHR AL,01                     ;CHECK FOR ROW KEY PRESSED
   JC DISP                         ;IF YES DISPLAY
   INC SI
   INC CL
   JMP L1                          ;REPEAT THE CHECK FOR KEY PRESSED(FOR ROW)


Microprocessor laboratory                                                                   29
Atria Institute of Technology                                  Dept. of Information Science

 COL2:CALL DELAY                ;CALL DELAY FOR DEBOUNCING EFFECT
    MOV COL,32H                 ;INITIALISE COLUMN WITH ASCII CODE 2
    MOV CL,30H                  ;INITIALISE CL WITH ASCII CODE OF ROW
    MOV SI,OFFSET KEYS          ;INITIALISE SI WITH ASCII CODE ADDRESSS OF SECOND
COLUMN
    ADD SI,08H
  L2:SHR AL,01                  ;CHECK FOR ROW KEY PRESSED
    JC DISP                     ;IF YES DISPLAY
    INC SI
    INC CL
    JMP L2                      ;REPEAT THE CHECK FOR KEY PRESSED(FOR ROW)
 COL3:CALL DELAY                ;CALL DELAY FOR DEBOUNCING EFFECT
    MOV COL,33H                 ;INITIALISE COLUMN WITH ASCII CODE 3
    MOV CL,30H                  ;INITIALISE CL WITH ASCII CODE OF ROW
    MOV SI,OFFSET KEYS          ;INITIALISE SI WITH ASCII CODE ADDRESSS OF THIRD
COLUMN
    ADD SI,10H
  L3:SHR AL,01                  ;CHECK FOR ROW KEY PRESSED
    JC DISP                     ;IF YES DISPLAY
    INC SI
    INC CL
    JMP L3                      ;REPEAT THE CHECK FOR KEY PRESSED(FOR ROW)
 DISP: MOV DL,[SI]              ;DISPLAY CODE OF KEY PRESSED
    MOV AH,02
    INT 21H
    MOV ROW,CL                  ;LOAD THE ROW NUMBER
    LEA DX,MSG1
    MOV AH,09H
    INT 21H
    MOV DL,ROW                  ;DISPLAY ROW NUMBER
    MOV AH,02
    INT 21H
    LEA DX,MSG2
    MOV AH,09H
    INT 21H
    MOV DL,COL
    MOV AH,02                   ;DISPLAY COLUMN NUMBER
    INT 21H
    MOV AH,4CH
    INT 21H

DELAY PROC NEAR
   PUSH AX




Microprocessor laboratory                                                               30
Atria Institute of Technology                                  Dept. of Information Science

   PUSH CX                      Output
   PUSH DX                      MASM <FILE NAME>.ASM
   MOV CX,20                    IF ERRORS / WARNINGS
  L5:MOV AX,0FFFFH              EDIT <FILE NAME>.ASM; TO OPEN THE FILE
  L4:DEC AX                     MASM <FILE NAME>.ASM; TO COMPILE
   JNZ L4                       LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
   LOOP L5                      <FILE NAME>.EXE; TO EXECUTE
   POP DX
   POP CX                       Run1
   POP AX                       Press any key from KB_INTERFACE
   RET                          Entered key is : 0
DELAY ENDP                      Row Number is : 1
                                Column Number is : 1
CODE ENDS                       Press ‘C’ from system Keyboard to continue C
   END START                    (C wont appear on the screen)

                                Run12
                                Press any key from KB_INTERFACE
                                Entered key is : 8
                                Row Number is : 2
                                Column Number is : 1
                                Press ‘C’ from system Keyboard to continue C




Microprocessor laboratory                                                               31
Atria Institute of Technology                       Dept. of Information Science

;11A) GENERATE THE FIRST 'N' FIBONACCI NUMBERS.
;CHECKED

DATA SEGMENT
   FIB DB 10 DUP(0)
DATA ENDS

CODE SEGMENT

   ASSUME CS:CODE,DS:DATA
   START: MOV AX,DATA
       MOV DS,AX
       MOV SI,OFFSET FIB
       MOV AL,00H
       MOV BL,01H
       MOV [SI],AL
       MOV CL,08H
       INC SI
       MOV [SI],BL
   NEXT: INC SI
       ADD AL,BL
       MOV [SI],AL
       MOV BL,[SI]
       MOV AL,[SI-1]
       LOOP NEXT
       MOV AH,4CH
       INT 21H
CODE ENDS
END START


           Output
           MASM <FILE NAME>.ASM
           IF ERRORS / WARNINGS
           EDIT <FILE NAME>.ASM; TO OPEN THE FILE
           MASM <FILE NAME>.ASM; TO COMPILE
           LINK <FILE NAME>.OBJ; TO LINK OBJECT
           FILE
           TD <FILE NAME>.EXE; TO EXECUTE
           01 01 02 03 05 08 0D




Microprocessor laboratory                                                    32
Atria Institute of Technology                                   Dept. of Information Science

;11B) SCAN A 8X3 KEYPAD FOR KEY CLOSURE AND SIMULATE ADD AND SUBTRACT
; OPERATION AS IN A CALCULATOR
;CHECKED

DATA SEGMENT
KEYS DB '0123456789#+-######='
NUM1 DB ?
NUM2 DB ?
OPCODE DB ?
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA
    MOV DS,AX                    ;INITIALISE DATA SEGMENT
 DIG1:CALL SCAN                  ;SCAN KEYPAD FOR FIRST DIGIT
    MOV AL,[SI]
    MOV BL,AL                    ;STORE THE ASCII VALUE
    .IF AL>2FH && AL<3AH         ;CHECK WHETHER IT IS NUMERIC DIGIT OR NOT
    CALL DISP                    ;DISPLAY THE DIGIT
    CALL DELAY                   ;DELAY TO GET OPERATOR + OR -
    JMP STN1                     ;STORE NUMBER1
    .ENDIF
    JMP DIG1                     ;IF NOT NUMERIC DIGIT SCAN AGAIN
 DIG2:CALL SCAN                  ;SCAN KEYPAD FOR SECOND DIGIT
    MOV AL,[SI]
    MOV BL,AL                    ;STORE THE ASCII VALUE
    .IF AL>2FH && AL<3AH         ;CHECK WHETHER IT IS NUMERIC DIGIT OR NOT
    CALL DISP                    ;DISPLAY THE DIGIT
    CALL DELAY                   ;DELAY TO GET SECOND DIGIT
    JMP STN2                     ;STORE NUMBER2
    .ENDIF
    JMP DIG2                     ;IF NOT NUMERIC DIGIT SCAN AGAIN
 STN1:SUB BL,30H
    MOV AL,10
    MUL BL
    MOV NUM1,AL                  ;STORE THE NUMBER1 IN MEMORY
 OP1 :CALL SCAN                  ;SCAN KEYPAD FOR + AND - OPERATOR
    MOV AL,[SI]
   .IF AL=='+' || AL=='-'
    MOV OPCODE,AL
    CALL DISP                    ;DISPLAY THE OPERATOR
    CALL DELAY
    JMP DIG2
    .ENDIF
    JMP OP1
 STN2:SUB BL,30H
    MOV AL,10
    MUL BL
    MOV NUM2,AL                  ;STORE THE NUMBER2 IN MEMORY
  OP2:CALL SCAN                  ;SCAN FOR = OPERATOR
    MOV AL,[SI]
    .IF AL=='='                  ;IF YES DISPLAY THE OPERATOR
    CALL DISP


Microprocessor laboratory                                                                33
Atria Institute of Technology                                 Dept. of Information Science

   CALL DELAY
   JMP DISPRE                   ;GO AND DISPLAY THE RESULT
   .ENDIF
   JMP OP2
DISPRE:MOV AL,NUM1              ;GET THE NUMBER1
   MOV BL,NUM2                  ;GET THE NUMBER1
   MOV AH,00
   MOV BH,00
   MOV CL,OPCODE
   .IF CL=='+'                  ;IF OPERATOR IS + ADD TWO NUMBER
   ADD AX,BX
   .ENDIF
   .IF CL=='-'                  ;IF OPERATOR IS - SUBTRACT NUMBER
   CMP AL,BL                    ;IF NUM1>NUM2 GO AND SUBTRACT NUM2 FROM NUM1
   JB MINUS
   SUB AX,BX                    ;ELSE SUBTRACT NUM1 FROM NUM2
   JMP NEXT
MINUS: PUSH AX
   MOV AL,'-'                   ;DISPLAY - SIGN INFORNT OF THE RESULT
   CALL DISP                    ;IF NUM1>NUM2
   POP AX
   SUB BX,AX                    ;SUBTRACT NUM2 FROM NUM1
   MOV AX,BX
   .ENDIF
NEXT: MOV AH,00                 ;CONVERT BINARY INTO BCD
   AAM
   CMP AH,09
   JA ABOVE                     ;IF BCD NUMBER IS GREATER THAN 9 DO CONVERTION
   ADD AX,3030H                 ;GET THE ASCII VALUE OF THE RESULT
   PUSH AX                      ;DISPLAY THE RESULT
   MOV DL,AL
   MOV AH,02H
   INT 21H
   POP AX
   MOV DL,AH
   MOV AH,02H
   INT 21H
   JMP TER
ABOVE:MOV AL,AH                 ;DO CONVERTION FOR RESULT GREATER THAN 9
   MOV AH,00
   AAM
   XCHG AH,AL
   ADD AX,3030H
   PUSH AX
   MOV DL,AL
   MOV AH,02
   INT 21H
   POP AX
   MOV DL,AH
   MOV AH,02H
   INT 21H

 TER: MOV AH,4CH
   INT 21H


Microprocessor laboratory                                                              34
Atria Institute of Technology                               Dept. of Information Science

SCAN PROC NEAR
   MOV AL,90H
   MOV DX,8403H
   OUT DX,AL
SCANC1:MOV DX,8402H             ;SCAN COLUMN1 OF KEYPAD
   MOV AL,01
   OUT DX,AL
   MOV DX,8400H
   IN AL,DX
   CMP AL,00
   JNZ COL1
SCANC2:MOV DX,8402H             ;SCAN COLUMN2 OF KEYPAD
   MOV AL,02
   OUT DX,AL
   MOV DX,8400H
   IN AL,DX
   CMP AL,00
   JNZ COL2
SCANC3:MOV DX,8402H
   MOV AL,04                    ;SCAN COLUMN3 OF KEYPAD
   OUT DX,AL
   MOV DX,8400H
   IN AL,DX
   CMP AL,00
   JNZ COL3
   JMP SCANC1
 COL1:CALL DELAY                ;DELAY FOR KEY DEBOUNCING EFFECT
   MOV SI,OFFSET KEYS
  L1:SHR AL,01                  ;FIND ROW
   JC back
   INC SI
   JMP L1
 COL2:CALL DELAY
   MOV SI,OFFSET KEYS
   ADD SI,08H
  L2:SHR AL,01
   JC BACK
   INC SI
   JMP L2
 COL3:CALL DELAY
   MOV SI,OFFSET KEYS
   ADD SI,10H
  L3:SHR AL,01
   JC BACK
   INC SI
   JMP L3
BACK: RET
SCAN ENDP

DISP PROC NEAR                  ;DISPLAY PROCEDURE FOR DIGIT OR OPERATOR
    PUSH AX
    PUSH DX
    MOV DL,AL
    MOV AH,02


Microprocessor laboratory                                                            35
Atria Institute of Technology                  Dept. of Information Science

    INT 21H
    POP DX
    POP AX
    RET
DISP ENDP

DELAY PROC NEAR
   PUSH AX
   PUSH CX
   PUSH DX
   MOV CX,20
   L5:MOV AX,0FFFFH
   L4:DEC AX
   JNZ L4
   LOOP L5
   POP DX
   POP CX
   POP AX
   RET
DELAY ENDP

CODE ENDS
   END START


Output
MASM <FILE NAME>.ASM
IF ERRORS / WARNINGS
EDIT <FILE NAME>.ASM; TO OPEN THE FILE
MASM <FILE NAME>.ASM; TO COMPILE
LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
<FILE NAME>.EXE; TO EXECUTE
RUN1:
Enter Expression(op1 operator op2 =) 9+9=18
 RUN2:
Enter Expression(op1 operator op2 =) 3+9=12
RUN3:
Enter Expression(op1 operator op2 =) 9-6=03
RUN4:
Enter Expression(op1 operator op2 =) 6-9=-03
RUN1:
Enter Expression(op1 operator op2 =)
9*9= 81
ERROR




Microprocessor laboratory                                               36
Atria Institute of Technology                                    Dept. of Information Science

;12a) READ THE CURRENT TIME FROM THE SYSTEM AND DISPLAY IT IN
; STANDARD FORMAT ON THE SCREEN.
;CHECKED

;MACRO DEFINITION

PUTCHAR MACRO VAL
   MOV AH,02H
   MOV DL,VAL
   INT 21H
ENDM
CODE SEGMENT
ASSUME CS:CODE
START: MOV AH,2CH
   INT 21H

    MOV AL,CH                    ;DISPLAY HOUR
    CALL DISPLAY
    PUTCHAR ':'

    MOV AL,CL                    ;DISPLAY MINUTES
    CALL DISPLAY
    PUTCHAR ':'

    MOV AL,DH                    ;DISPLAY SECONDS
    CALL DISPLAY

    MOV AH,4CH
    INT 21H
DISPLAY PROC                     ;PROCEDURE TO DISPLAY THE TIME IN
                                 ;STANDARD FORMAT
    MOV AH,00
    MOV BL,0AH                   ;DIVISOR / CONVERT TO BASE 10
    DIV BL
    ADD AX,3030H
    MOV BX,AX
    PUTCHAR BL
    PUTCHAR BH
    RET
DISPLAY ENDP
                                       Output
CODE ENDS
                                       MASM <FILE NAME>.ASM
END START
                                       IF ERRORS / WARNINGS
                                       EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                                       MASM <FILE NAME>.ASM; TO COMPILE
                                       LINK <FILE NAME>.OBJ; TO LINK OBJECT
                                       FILE
                                       <FILE NAME>.EXE; TO EXECUTE
                                       ; CURRENT SYSTEM TIME HH:MM:SS
                                       04:05:40


Microprocessor laboratory                                                                 37
Atria Institute of Technology                                               Dept. of Information Science

;12B) GENERATE A SINEWAVE USING DAC INTERFACE(THE OUTPUT OF THE
; DAC IS TO BE DISPLAYED ON A CRO

DATA SEGMENT
   DEV DW 80H,96H,0ABH,0C0H,0D2H,0E2H,0EFH,0F8H,0FEH,0FFH,0FEH,0F8H,0EFH,0E2H,0D2H,
      0C0H,0ABH,96H,80H,6AH,54H,40H,2EH,1EH,11H,08H,02H,00H,02H,08H,11H,1EH,2EH,
      40H,54H,6AH
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA                       ;INITIALISE DATA SEGMENT
   MOV DS,AX
   MOV DX,8403H                          ;INITIALISE CONTROL WORD
   MOV AL,80H
   OUT DX,AL
   MOV DX,8400H
   MOV BX,0FFFFH                         ;INITIALISE BX WITH N0. OF WAVES TO BE GENERATED
  L2:MOV CX,36                           ;INITIALISE CX WITH NUMBER DEV
   LEA SI,DEV
  L1:MOV AL,[SI]                         ;GET FIRST DEV
   OUT DX,AL                             ;SENT TO DAC
   INC SI                                ;GET NEXT DEV
   LOOP L1                               ;REPEAT FOR 36 DEV
   DEC BX
   JNZ L2                                ;REPEAT FOR BX NUMBER OF WAVEFORM
   MOV AH,4CH
   INT 21H
CODE ENDS
END START



                                Output

                                Note :
                                Amplitude of sine wave vary from 0 to 5V.
                                F(x)= 80H + 80h sin(x)
                                (dc level) (amplitude)
                                where 0 <= X <= 360 degree
                                V = 2.5 + 2.5 SIN (0)




Microprocessor laboratory                                                                            38
Atria Institute of Technology                                    Dept. of Information Science

;13A). PROGRAM TO SIMULATE A DECIMAL UP-COUNTER TO DISPLAY 00-99.
;CHECKED

CODE SEGMENT
ASSUME CS : CODE
START :
   MOV AL,30H                    ;OUTER LOOP
LOOP2:
   MOV DL,AL
   MOV AH,02H                    ;DISPLAY PURPOSE
   INT 21H
   PUSH AX
   MOV BL,30H                    ;INNER LOOP
LOOP1:
   MOV DL,BL
   mov ah,02h
   INT 21H
   INC BL
   CALL DELAY
   MOV AH,03H                    ;SET CURSOR POINT
   INT 10H
   MOV AH,02H
   MOV DL,01H                    ;COLUMN SETTING
   INT 10H
   CMP BL,39H
   JLE LOOP1
   MOV AH,02H
   MOV DL,00H                    ;COLUMN SETTING
   INT 10H
   POP AX
   INC AL
   CMP AL,39H
   JLE LOOP2
   MOV AH,4CH
   INT 21H
DELAY PROC
   PUSH CX
   PUSH BX
   MOV CX,0FFFH                  ;OUTER LOOP
N3: MOV BX,0FFFFH                ;INNER LOOP
N4: DEC BX
   JNZ N4
   LOOP N3                         Output
   POP BX
   POP CX                          MASM <FILE NAME>.ASM
   RET                             IF ERRORS / WARNINGS
DELAY ENDP
CODE ENDS                          EDIT <FILE NAME>.ASM; TO OPEN THE FILE
END START                          MASM <FILE NAME>.ASM; TO COMPILE
                                   LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                                   <FILE NAME>.EXE; TO EXECUTE
                                   OUTPUT : COUNTERFROM 00 TO 99


Microprocessor laboratory                                                                 39
Atria Institute of Technology                                           Dept. of Information Science

;13B) GENERATE A HALF RECTIFIED SINE WAVE FROM USING DAC
; INTERFACE(THE OUTPUT OF THE DAC IS TO BE DISPLAYED ON A CRO)

DATA SEGMENT
   DEV DB 80H,96H,0ABH,0C0H,0D2H,0E2H,0F8H,0FEH,0FFH,0FEH,0F8H,0E2H,0D2H,0C0H,0ABH,96H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
   MOV DS,AX
   MOV DX,8403H
   MOV AL,80H
   OUT DX,AL
   MOV DX,8400H
   MOV BX,0FFFFH
  L2:MOV CX,18
   LEA SI,DEV
  L1:MOV AL,[SI]
   OUT DX,AL
   INC SI
   LOOP L1
   MOV DX,8400H
   MOV CX,18
   MOV AL,80H
  L3:OUT DX,AL
   LOOP L3
   DEC BX
   JNZ L2
   MOV AH,4CH
   INT 21H
CODE ENDS
END START


                            Output

                            MASM <FILE NAME>.ASM
                            IF ERRORS / WARNINGS
                            EDIT <FILE NAME>.ASM; TO OPEN THE FILE
                            MASM <FILE NAME>.ASM; TO COMPILE
                            LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
                            <FILE NAME>.EXE; TO EXECUTE




Microprocessor laboratory                                                                        40
Atria Institute of Technology                                Dept. of Information Science

;14A) READ A PAIR OF INPUT COORDINATE IN BCD AND MOVE THE CURSOR
; TO THE SPECIFIED LOCATION ON THE SCREEN

;CHECKED
DISP MACRO MSG
    MOV AH,09H
    LEA DX,MSG
    INT 21H
ENDM

DATA SEGMENT
   MSG1 DB 10,13,'ENTER THE ROW NUMBER:$'
   MSG2 DB 10,13,'ENTER THE COLUMN NUMBER:$'
   MSG3 DB 10,13,'PRESS ANY KEY TO QUIT $'
   ROW DB ?
   COL DB ?
DATA ENDS
CODE SEGMENT

   ASSUME CS:CODE,DS:DATA
 START:MOV AX,DATA
   MOV DS,AX
   MOV AH,07H
   MOV AL,00
   MOV BH,0FH
   MOV CL,00
   MOV CH,00
   MOV DH,24
   MOV DL,79
   INT 10H
   MOV AH,02H
   MOV BH,00
   MOV DH,00

    MOV DL,00
    INT 10H
    DISP MSG1
    CALL READ
    MOV ROW,AL
    DISP MSG2
    CALL READ
    MOV COL,AL
    DISP MSG3
    MOV AH,2
    MOV DH,ROW
    MOV DL,COL
    INT 10H
    MOV AH,8
    INT 21H
    MOV AH,4CH
    INT 21H

READ PROC
   MOV AH,1


Microprocessor laboratory                                                             41
Atria Institute of Technology                          Dept. of Information Science

   INT 21H
   AND AL,0FH
   MOV BL,AL
   MOV AH,1
   INT 21H
   AND AL,0FH
   MOV AH,BL
   AAD
   RET
READ ENDP

CODE ENDS
END START


          Output
          MASM <FILE NAME>.ASM
          IF ERRORS / WARNINGS
          EDIT <FILE NAME>.ASM; TO OPEN THE FILE
          MASM <FILE NAME>.ASM; TO COMPILE
          LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
          <FILE NAME>.EXE; TO EXECUTE
          ENTER THE ROW NUMBER[MIN:00 MAX:24]; 12
          ENTER THE COLUMN NUNBER[MIN:00 MAX:79]; 67
          PRESS ANY KEY TO QUIT
          ; SEE THE CURSOR BLINKING POSITION AS
          OUTPUT OF THE PROGRAM




Microprocessor laboratory                                                       42
Atria Institute of Technology                                       Dept. of Information Science

;14B) GENERATE A FULL RECTIFIED SINE WAVE FROM USING DAC
; INTERFACE(THE OUTPUT OF THE DAC IS TO BE DISPLAYED ON A CRO)

DATA SEGMENT
DEV DB
80H,96H,0ABH,0C0H,0D2H,0E2H,0EFH,0F8H,0FEH,0FFH,0FEH,0F8H,0EFH,0E2H,0D2H,0C0H,0ABH,96H
DATA ENDS

CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START:MOV AX,DATA
   MOV DS,AX
   MOV DX,8403H
   MOV AL,80H
   OUT DX,AL
   MOV DX,8400H
   MOV BX,0FFFFH
  L2:MOV CX,18
   LEA SI,DEV
  L1:MOV AL,[SI]
   OUT DX,AL
   INC SI
   LOOP L1
   DEC BX
   JNZ L2
   MOV AH,4CH
   INT 21H
CODE ENDS
END START




              Output

              MASM <FILE NAME>.ASM
              IF ERRORS / WARNINGS
              EDIT <FILE NAME>.ASM; TO OPEN THE FILE
              MASM <FILE NAME>.ASM; TO COMPILE
              LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
              <FILE NAME>.EXE; TO EXECUTE




Microprocessor laboratory                                                                    43
Atria Institute of Technology                                         Dept. of Information Science

;15A) .PROGRAM TO CREATE A FILE
        ;CHECKED

       DIS_MSG MACRO PI
           MOV AH,09H
           LEA DX,PI
           INT 21H
       ENDM

       DATA SEGMENT
       STR1 DB 'C:\SAT1.TXT$'
       M1 DB 'FILE CREATED SUCESSFULLY$'
       M2 DB 'ERROR$'

       DATA ENDS

       CODE SEGMENT
       ASSUME CS:CODE,DS:DATA
       START:MOV AX,DATA
          MOV DS,AX
          MOV AH,5BH
          MOV CX,00H
          LEA DX,STR1
          INT 21H
          JC STOP
          DIS_MSG M1
          JMP TER1
        STOP: DIS_MSG M2
        TER1: MOV AH,4CH
          INT 21H
       CODE ENDS
       END START


            Output
            MASM <FILE NAME>.ASM
            IF ERRORS / WARNINGS
            EDIT <FILE NAME>.ASM; TO OPEN THE FILE
            MASM <FILE NAME>.ASM; TO COMPILE
            LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
            <FILE NAME>.EXE; TO EXECUTE
            FILE IS CREATED
            ; GO TO THE SPECIFIED PATH EITHER C: OR D: AND CHECK FOR EX:
            D:\SAT1.TXT$, CHECK FOR SAT1.TXT IN D:\




Microprocessor laboratory                                                                      44
Atria Institute of Technology                                 Dept. of Information Science

;15B) PROGRAM TO DRIVE AN EVELATOR TO SERVICE OF MULTIPLE CHOICE REQUEST

DATA SEGMENT
  MSG DB 10,13,"PRESS ANY KEY TO EXIT$"
  FLOOR DB 00H,03H,06H,09H,0E0H,0D3H,0B6H,79H
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE;DS:DATA
START:MOV AX,DATA
  MOV DS,AX

  MOV DX,8403H
  MOV AL,82H
  OUT DX,AL

  MOV AH,9
  LEA DX,MSG
  INT 21H
  MOV BL,0 ;ELEVATOR AT THE GROUND FLOOR
LOOP1:
  MOV AL,BL
  OR AL,0F0H ;CLEAR REQUEST (ONLY UPPER 4 BITS ARE USED)

  MOV DX,8400H
  OUT DX,AL

  LEA SI,FLOOR

LOOP2:
  CALL KBHIT

  MOV DX,8401H ;GETS THE STATUS OF REQUEST KEYS
  IN AL,DX

  OR AL,0F0H ;ENSURE A KNOWN VLAUE FOR THE UNCONNECTED BITS

  MOV CL,AL
  SUB AL,0FFH ;ANY REQUEST?
  JZ LOOP2 ;NO LOOP BACK

LOOP3:
  MOV AL,CL
  ROR AL,1 ;DETERMINE THE FLOOR WHERE SERVICE IS REQUIRED
  MOV CL,AL
  JNC DECIDE
  INC SI
  JMP LOOP3

DECIDE:
 CALL DELAY
 MOV AL,[SI] ;GETS THE FLOOR NUMBER
 SUB AL,BL ;SUBTRACT CURRENT FLOOR NUMBER
 JS DOWN ;ELEVATOR GOES DOWN
 JZ RESET ;NO MOVEMENT FOR THE ELEVATOR


Microprocessor laboratory                                                              45
Atria Institute of Technology                                               Dept. of Information Science

UP:
  INC BL ;EVELATOR GOES UP
  MOV AL,BL
  OR AL,0F0H

  MOV DX,8400H
  OUT DX,AL
  JMP DECIDE

DOWN:
  DEC BL ;EVELATOR DOWN
  MOV AL,BL
  OR AL,0F0H

  MOV DX,8400H
  OUT DX,AL
  JMP DECIDE

RESET:
  ADD SI,4
  MOV AL,[SI]

  MOV DX,8400H
  OUT DX,AL;CORESPONDING REQUEST INDICATOR LED TURN OFF
  JMP LOOP1

 KBHIT:
  MOV AH,1
  INT 16H
  JNZ EXIT
  RET

EXIT: MOV AH,4CH
   INT 21H
DELAY PROC NEAR

   PUSH CX                      Output
   PUSH BX                      MASM <FILE NAME>.ASM
   MOV BX,01FFH                 IF ERRORS / WARNINGS
B2: MOV CX,0FFFFH               EDIT <FILE NAME>.ASM; TO OPEN THE FILE
B1: LOOP B1                     MASM <FILE NAME>.ASM; TO COMPILE
   DEC BX                       LINK <FILE NAME>.OBJ; TO LINK OBJECT FILE
   JNZ B2                       <FILE NAME>.EXE; TO EXECUTE
   POP BX
   POP CX                       The elevator is made to stay initially in ground floor. Port B is
   RET                          sampled for a request. When a request is recognized the
DELAY ENDP                      elevator moves to that floor and the request is reset. It remains
CODE ENDS                       sin that floor unless there is a request from any of the other
END START                       floors. Priorities are set.

                                The program DECIDE determines the direction in which the
                                elevator has to move. The program RESET resets the request
                                and the elevator moves to the required floor. The program is
                                executed as an infinite loop. In order to terminate the program
                                press any key.

Microprocessor laboratory                                                                            46

								
To top