Vous êtes sur la page 1sur 23

Programs

using
DOS Interrupt Functions
Presentation by:

C. Thiruvenkatesan
Associate Professor / ECE
SSN College of Engineering

Programs for
1. Displaying System Time
2. Displaying System Date
3. Displaying System Day
4. Password Checking
using
DOS Interrupt Functions

DOS Interrupts Used:


INT 21 H / AH=2C H - GET SYSTEM TIME
Return: CH = Hour CL = Minute DH = Second DL = 1/100 seconds
INT 21 H / AH=2A H - GET SYSTEM DATE
Return: CX = Year (1980-2099). DH = Month. DL = Day. AL = Day of week (00h=Sunday)
INT 21 H / AH=02 H - DISPLAY OUTPUT (a single character)
Outputs the character in DL to the standard output device.
INT 21 H / AH= 09H DISPLAY OUTPUT (STRING)
Sends the characters in the string to the standard output device.
The character string in memory must be terminated by a $ (24H).
INT 21 H / AH=08 H - Wait for console input without echo
Terminates the current process and transfers control to the invoking process.
INT 21 H / AH=4C H - TERMINATE A PROCESS (EXIT)
Terminates the current process and transfers control to the invoking process.

START:
; Hour Part
HOUR:

Title
Program to Display System Time in HH/MM/SS format
.MODEL SMALL
.DATA
.CODE
MOV AX, @DATA
MOV DS, AX
MOV AH, 2CH
INT 21H
MOV AL, CH
AAM
MOV BX, AX
CALL DISP
MOV DL, ':'
MOV AH, 02H
INT 21H

; To get System Time


; Hour is in CH

; To Print ":" in DOS

; Minutes Part
MINUTES:

; Seconds Part
Seconds:

MOV AH, 2CH


INT 21H
MOV AL, CL
AAM
MOV BX, AX
CALL DISP
MOV DL, ':'
MOV AH, 02H
INT 21H
MOV AH, 2CH
INT 21H
MOV AL, DH
AAM
MOV BX, AX
CALL DISP

; To get System Time


; Minutes is in CL

; To Print ":" in DOS

1
; To get System Time
; Seconds is in DH

; To terminate the Program


MOV AH, 4CH
INT 21H
; Display Part
DISP PROC
MOV DL, BH
ADD DL, 30H
MOV AH, 02H
INT 21H
MOV DL, BL
ADD DL, 30H
MOV AH, 02H
INT 21H
RET
DISP ENDP
END START

; To Terminate the Program

; Since the values are in BX, BH Part


; ASCII Adjustment
; To Print in DOS

; Since the values are in BX, BL Part


; ASCII Adjustment
; To Print in DOS

; End Display Procedure


; End of MAIN

Title Program to Display System Date in DD/MM/YYYY format


.MODEL SMALL
.DATA
.CODE
START: MOV AX, @DATA
MOV DS, AX
; Date Part
Date: MOV AH, 2AH
INT 21H
MOV AL, DL
AAM
MOV BX, AX
CALL DISP
MOV DL, '/'
MOV AH, 02H
INT 21H

; To get System Date


; Date is in DL

; To Print ":" in DOS

; Month Part
Month: MOV AH, 2AH
INT 21H
MOV AL, DH
AAM
MOV BX, AX
CALL DISP
MOV DL, '/'
MOV AH, 02H
INT 21H

; To get System Date


; Month is in DH

; To Print ":" in DOS

; Year Part
Year:
MOV AH, 2AH
INT 21H
MOV AL, 14H
AAM
MOV BX, AX
CALL DISP

; To get System Date

; Year is in CX, first part

MOV AH, 2AH


; To get System Date
INT 21H
ADD CX, 0F830H ; To negate the effects of 16-bit value
MOV AL, CL
; Year is in CX, second part
AAM
MOV BX, AX
CALL DISP

; To terminate the Program


MOV AH, 4CH
INT 21H
; Display Part
DISP PROC
MOV DL, BH
ADD DL, 30H
MOV AH, 02H
INT 21H
MOV DL, BL
ADD DL, 30H
MOV AH, 02H
INT 21H
RET
DISP ENDP
END START

; To Terminate the Program

; Since the values are in BX, BH Part


; ASCII Adjustment
; To Print in DOS
; BL Part
; ASCII Adjustment
; To Print in DOS

; End Display Procedure


; End of MAIN

Title An Assembly Language Program to Display System Day


.MODEL SMALL
.DATA
DMSG0 DB 10,13,'SUNDAY ','$'
DMSG1 DB 10,13,'MONDAY ','$'
DMSG2 DB 10,13,'TUESDAY ','$'
DMSG3 DB 10,13,'WEDNESDAY','$'
DMSG4 DB 10,13,'THURSDAY ','$'
DMSG5 DB 10,13,'FRIDAY ','$'
DMSG6 DB 10,13,'SATURDAY ','$'

.CODE
START: MOV AX, @DATA
MOV DS, AX
MOV AH, 2AH
; To get System Date
INT 21H
CMP AL, 00H
; Day is in AL
JNE NXT1
MOV DX, OFFSET DMSG0
CALL DISP
NXT1: CMP AL, 01H
; Day is in AL
JNE NXT2
MOV DX, OFFSET DMSG1
CALL DISP
NXT2: CMP AL, 02H
; Day is in AL
JNE NXT3
MOV DX, OFFSET DMSG2
CALL DISP

NXT3:

NXT4:

NXT5:

NXT6:

CMP AL, 03H


; Day is in AL
JNE NXT4
MOV DX, OFFSET DMSG3
CALL DISP
CMP AL, 04H
; Day is in AL
JNE NXT5
MOV DX, OFFSET DMSG4
CALL DISP
CMP AL, 05H
; Day is in AL
JNE NXT6
MOV DX, OFFSET DMSG5
CALL DISP
CMP AL, 06H
; Day is in AL
JNE TERMI
MOV DX, OFFSET DMSG6
CALL DISP

; To terminate the Program


TERMI: MOV AH, 4CH
; To Terminate the Program
INT 21H
; Display Part
DISP
PROC
MOV AH, 09H
INT 21H
RET
DISP
ENDP
END START

; To Print in DOS

3
; End Display Procedure
; End of MAIN

Program to Display System Time in HH/MM/SS format

1
Program to Display System Date in DD/MM/YYYY format

2
Program to Display System Day

TITLE

Program to Check whether the Password entered is correct or not

;; PASSWORD IS SSNECE
DATA

DATA

SEGMENT
PASSWORD DB 'SSNECE'
LEN EQU ($-PASSWORD)
RMSG1 DB 10,13,'ENTER YOUR PASSWORD: $'
CMSG2 DB 10,13,01,' GOOD, CORRECT PASSWORD ! ! ',02,'$'
ICMSG3 DB 10,13,'SORRY, INCORRECT PASSWORD!$'
NEW DB 10,13,'$'
INST DB 10 DUP(0)
ENDS

CODE

SEGMENT
ASSUME CS:CODE, DS:DATA
START: MOV AX, DATA
MOV DS, AX
LEA DX, RMSG1
MOV AH, 09H
INT 21H
MOV SI, 00H
BACK1: MOV AH, 08H
INT 21H
CMP AL, 0DH
; check for carriage return
JE SKIP1
MOV [INST+SI], AL
MOV DL,'*'
MOV AH, 02H
INT 21H
INC SI
JMP BACK1

SKIP1:

MOV BX, 00H


MOV CX, LEN
CHECK: MOV AL, [INST+BX]
MOV DL, [PASSWORD+BX]
CMP AL, DL
JNE FAIL
INC BX
LOOP CHECK
LEA DX, CMSG2
MOV AH, 09H
INT 21H
JMP FINISH

FAIL:

LEA DX, ICMSG3


MOV AH, 09H
INT 21H
FINISH: MOV AH, 4CH
INT 21H
CODE ENDS
END START
END