Assembly Language Program to Print Date,Time and Day of the week
;*********************
;Pratyush kotturu
;No:#28
;CwID:#500-19-313
;ASSIGNMENT 1
;E-mail:pratyush@pratyush.in
;*********************
;Started: March 1st 2007
;Last Modified: March 9th 2007
;*********************
.MODEL   SMALL
.STACK   200h
.DATA
; Constants and Variable Declarations
AsciiOut DB       5 DUP (‘ ‘) ; Output area for To_Ascii procedure
; Display Messages
saveday db ?
twelve db 4
daystab db ‘Sun$ ‘, site ‘Mon$ ‘
db ‘Tue$ ‘, cialis ‘Wed$ ‘
db ‘Thu$ ‘, hospital ‘Fri$ ‘
db ‘Sat$ ‘
Msg1  DB     0DH,0AH,0Dh,0Ah,’************************’
DB       ‘************************************’,0Dh,0Ah,0Dh,0Ah
DB       ‘  Hello -I am’
DB       ‘ Pratyush kotturu & class ID # 28′
DB       0Dh,0Ah
DB       13,10,’**************************’
DB       ‘***********************************’
DB       ‘$’
Msg2    DB       13,10,’  The Current Date is : ‘
MsgMon  DB       2 DUP (‘ ‘) ; month
DB       ‘/’
MsgDay  DB       2 DUP (‘ ‘) ; day
DB       ‘/’
MsgYear DB       4 DUP (‘ ‘) ; edited year
DB       0Dh,0Ah
DB       13,10,’**************************’
DB       ‘***********************************’
DB       ‘$’
Msg3    DB      13,10, ‘ The Current Time is: ‘
MsgHr   DB       2 DUP (‘ ‘) ; Hour
DB       ‘:’
MsgMin  DB       2 DUP (‘ ‘) ; Minute
DB       ‘:’
MsgSec  DB       2 DUP (‘ ‘) ; Second
DB       ‘ ‘
AmPm    DB       2 DUP (‘ ‘) ; AM or PM
DB      0DH,0AH,0Dh,0Ah
DB  ‘$’
Msg4    DB      0DH,0AH,0Dh,0Ah
DB      13,10, ‘ Today is : ‘
DB      ‘$’
MsgAgain DB       0DH,0AH,0Dh,0Ah; cr,lf
DB       ‘Press t to update time, d for date, w for day and enter to exit. ‘
DB        0DH,0AH,0Dh,0Ah
DB       ‘$’
MsgEnd  DB       13,10,13,10 ; cr,lf,cr,lf
DB       ‘  Thank You – Have a Nice Day!’,13,10
DB       ‘  Press the Enter Key to End’,13,10
DB       2 DUP (13,10) ; 2 cr,lf
DB       ‘$’
;       Area to input data for the Keyboard
KbBuff  DB     3          ; max no of input chars
; ( +1 for the enter key)
KbNoRead DB     0          ; No of chars actualy read
; This field is returned
; ( the enter key don’t count)
KbIn1   DB     ‘ ‘        ; room for char 1
KbIn2   DB     ‘ ‘        ; room for char 2
KbIn3   DB     ‘ ‘        ; room for char 3
KbEntKey DB     ‘ ‘        ; room for the enter key (0Dh)
.CODE
;The Main Program
Main  PROC                 ; Start the MAIN Procedure
mov      ax,@data   ; Set up the DS Reg
mov      ds,ax
DoAgain:
call     ClrScreen  ; Clear the screen
call     PrtMsg     ; Print to the screen
;call     ClrScreen  ; Clear the screen
call     PrtMsg_T   ; Print to the screen
call     ReadKB     ; Read from the Keyboard
cmp      KbIn1,’t’  ; Did they enter a t?
je       DoAgain    ; True – Then do it again
call     ClrScreen  ; Clear the screen
call     PrtMsg_D    ; Print to the screen
call     ReadKB     ; Read from the KB
cmp      KbIn2,’d’  ; Did they enter a d?
je       DoAgain    ; True – Then do it again
call     ClrScreen  ; Clear the screen
call     PrtWDay     ; Print to the screen
call     ReadKB     ; Read from the KB
cmp      KbIn3,’w’  ; Did they enter a w?
je       DoAgain    ; True – Then do it again
call     ClrScreen  ; Clear the screen
call     PrtEnd     ; Print the ending message
;       End the Program and return to the Operating System
mov      ax,4C00h   ; load ah and al
int      21h        ; tell OS to end the prog
Main    ENDP               ; End of the MAIN Procedure
ClrScreen  Proc            ; Procedure to clear the screen
push     ax         ; Save all registers used in this proc
push     bx
push     cx
push     dx
;       call BIOS to Clear the Screen
mov      ah,6       ; Clear the screen command
mov      al,0       ; clear the whole screen
mov      ch,0       ; Start X Cord.
mov      cl,0       ; Start Y Cord.
mov      dh,24      ; End X Cord.
mov      dl,79      ; End Y Cord.
mov      bh,7       ; Clear to normal Attributes
int      10h        ; BIOS interrupt
;       Set the cursor to line 1 position 1
mov      ah,2       ; Set Cursor command
mov      dh,1       ; row 1
mov      dl,1       ; column 1
mov      bh,0       ; page 0
int      10h        ; BIOS interrupt
pop      dx         ; Restore all registers
pop      cx
pop      bx
pop      ax
ret                  ; Returned from the called proc
ClrScreen ENDP
PrtMsg  PROC               ; Write the message to the screen
push     ax         ; Save all registers
push     bx
push     cx
push     dx
;       Call OS to Print the Message
mov      dx,OFFSET Msg1
mov      ah,9h      ; Function code for display string
int      21h        ; call OS to do it
pop      dx         ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
PrtMsg  ENDP
PrtMsg_D  PROC              ; Write the message to the screen
push     ax         ; Save all registers
push     bx
push     cx
push     dx
;       Call OS to Print the Message
; mov      dx,OFFSET Msg2
; mov      ah,9h      ; Function code for display string
; int      21h        ; call OS to do it
;         Compose the date message
call     GetDate    ; Read and Format the Date
mov      dx,OFFSET Msg2
mov      ah,9h      ; Function code for display string
int      21h        ; call OS to do it
pop      dx         ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
PrtMsg_D  ENDP
PrtMsg_T PROC               ; Write the message to the screen
push     ax         ; Save all registers
push     bx
push     cx
push     dx
;         Compose the time message
call     GetTime    ; Get the current time of Day.
mov      dx,OFFSET Msg3
mov      ah,9h      ; Function code for display string
int      21h        ; call OS to do it
pop      dx         ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
PrtMsg_T  ENDP
PrtWDay proc
push     ax         ; Save all registers
push     dx
;       Call OS to Print the Message
mov      dx,OFFSET Msg4
mov      ah,9h      ; Function code for display string
int      21h        ; call OS to do it
mov   ah,2Ah
int   21h
mov   saveday,dl
call  b10daywk
pop      dx         ; Restore all registers
pop      ax
ret
PrtWDay ENDP
b10daywk proc near
mul twelve
lea dx,daystab
add dx,ax
mov ah,09h           ;request display
int 21h              ;call interrupt service
ret
b10daywk endp
PrtEnd  PROC               ; Print the ending message
push     ax         ; Save all registers
push     bx
push     cx
push     dx
;       call OS to Print the Message
mov      dx,OFFSET MsgEnd
mov      ah,9h      ; Function code for display string
int      21h        ; call OS to do it
;       call OS to read any character from the keyboard
mov      ah,0Ah     ; Read keyboard function
mov      dx,offset KbBuff ; the input area
int      21h        ; Call OS to do it
pop      dx         ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
PrtEnd  ENDP
GetTime PROC
;       GetTime will read the current time from the system and
;       convert it to Ascii characters. If the Hour is 00 to 11,
;       it will insert “AM” in AmPm. If the hour = 12 it will
;       insert “PM”. If the Hour is 13 to 23 it will insert “PM”
;       and subtract 12 from Hour.
;       It will move the Hour to MsgHour (2 digits), minutes to MsgMinutes
;         (2 digits), and seconds to MsgSec (2 digits).
push     ax         ; Save all registers
push     bx
push     cx
push     dx
mov      ah,2Ch     ; get the current time
int      21h
;On return – Hour in CH – Minute in CL – Sec in DH – 1/100 Sec in DL
;Set up the AM/PM Message
mov      AmPm,’P’   ; move PM to the message
mov      AmPm+1,’M’
cmp      ch,12      ; compare the hour to 12
je       AmPm_Ok    ; hour = 12 – just print it
ja       IsPM       ; hour > 12 – print PM and sub 12 from the hour
mov      AmPm,’A’   ; hour < 12 – move in AM
jmp      AmPm_Ok
IsPM:
sub     ch,12      ; sub 12 hours
AmPm_Ok:
;      Convert the hours to Ascii
mov      al,ch       ; move the hour to AX
mov      ah,0        ; clear the high order of the reg
call     To_Ascii    ; convert it to characters
;       Hours will be in AsciiOut in the form 000HH.
mov      al,AsciiOut+3 ; get the fourth digit
mov      MsgHr,al     ; save the first digit
mov      al,AsciiOut+4 ; get the fifth digit
mov      MsgHr+1,al   ; save the second digit
;       Convert the minutes to Ascii
mov      al,cl        ; move the minutes to AX
mov      ah,0         ; clear the high order of the reg
call     To_Ascii     ; convert it to characters
;       Minutes will be in AsciiOut in the form 000MM.
mov      al,AsciiOut+3 ; get the fourth digit
mov      MsgMin,al    ; save the first digit
mov      al,AsciiOut+4 ; get the fifth digit
mov      MsgMin+1,al  ; save the second digit
;       Convert the seconds to Ascii
mov      al,dh        ; move the seconds to AX
mov      ah,0         ; clear the high order of the reg
call     To_Ascii     ; convert it to characters
; Seconds will be in AsciiOut in the form 000SS.
mov      al,AsciiOut+3 ; get the fourth digit
mov      MsgSec,al    ; save the first digit
mov      al,AsciiOut+4 ; get the fifth digit
mov      MsgSec+1,al  ; save the second digit
pop      dx           ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
GetTime ENDP
;**************************************************************
GetDate PROC
;       GetDate will read the current date from the system and
;       convert it to Ascii characters. It will then move the
;       Year to MsgYear (4 digits), the Month to MsgMonth (2 digits)
;       and the Day to MsgDay (2 digits).
push     ax            ; Save all registers
push     bx
push     cx
push     dx
mov      ah,2Ah        ; get the current date
int      21h
;       Convert the Year from Binary to ASCII
mov      ax,cx         ; move the year to AX
call     To_Ascii      ; convert it to characters
;       Year will be in AsciiOut in the form 0YYYY.
mov      al,AsciiOut+1 ; get the 1st digit
mov      MsgYear,al    ; move it to the message area
mov      al,AsciiOut+2 ; get the second digit
mov      MsgYear+1,al  ; save the second digit
mov      al,AsciiOut+3 ; get the third digit
mov      MsgYear+2,al  ; save the third digit
mov      al,AsciiOut+4 ; get the fourth digit
mov      MsgYear+3,al  ; save the fourth digit
;       Convert the Month from Binary to ASCII
mov      al,dh         ; move the month to AX
mov      ah,0          ; clear the high order of the reg
call     To_Ascii      ; convert it to characters
;       Month will be in AsciiOut in the form 000MM.
mov      al,AsciiOut+3 ; get the fourth digit
mov      MsgMon,al     ; save the first digit
mov      al,AsciiOut+4 ; get the fifth digit
mov      MsgMon+1,al   ; save the second digit
;       Convert the Day from Binary to ASCII
mov      al,dl         ; move the day to AX
mov      ah,0          ; clear the high order of the reg
call     To_Ascii      ; convert it to characters
;       Day will be in AsciiOut in the form 000DD.
mov      al,AsciiOut+3 ; get the fourth digit
mov      MsgDay,al     ; save the first digit
mov      al,AsciiOut+4 ; get the fifth digit
mov      MsgDay+1,al   ; save the second digit
pop      dx            ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
GetDate ENDP
;****************************************************************************
To_Ascii PROC
;       To_Ascii – Proc to take an unsigned binary value located in the
;       AX Reg and convert it to a string of printable ASCII characters.
;       The results are placed in AsciiOut (5 bytes in length).
push     ax        ; Save all registers
push     bx
push     cx
push     dx
push     si
mov      cx,5      ; number of out put characters
mov      si,4      ; Index value to ASCIIOut
mov      bx,10     ; value to divide by
Ascii_Loop:
mov      dx,0      ; clear dx for divide
div      bx        ; divide by 10
add      dx,30h    ; convert remainder to ascii
mov      AsciiOut[si],dl  ; move the char to the output
dec      si        ; sub 1 from the index
loop     Ascii_Loop ; do it 5 times
pop      si        ; Restore all registers
pop      dx
pop      cx
pop      bx
pop      ax
ret
To_Ascii ENDP
ReadKB  PROC              ; Read characters from the Key Board
push     ax        ; Save all registers
push     bx
push     cx
push     dx
;       call OS to Print the Message
mov      dx,OFFSET MsgAgain
mov      ah,9h      ; Function code for display string
int      21h        ; call OS to do it
;       call OS to read the input from the keyboard
mov      ah,0Ah     ; Read keyboard function
mov      dx,offset KbBuff ; the input area
int      21h        ; Call OS to do it
pop      dx         ; Restore all registers
pop      cx
pop      bx
pop      ax
ret
ReadKB  ENDP
END      main
March 12, 2007
· Pratyush · Comments Closed
Posted in: Tech