Assembly source code get times of day (fetch time)

Source: Internet
Author: User
Tags exit command line reset set time

INTRODUCTION

The ' the ' is of the ' a program ' uses ' system time of day. This example uses a conditional assembly to decide between two-to-get the "time of". One way is to use the DOS time function; The other way, illustrated by the second code example, uses the "BIOS time" function. The second example can be used to replace the standard DOS call to get the ' time of '. This second example'll return to the time of faster than the standard DOS call.

The EXAMPLE

This example runs until a set time of day occurs and then terminates. This code gets the ' time ' information from the ' DOS command line input data. If There is bad input data, then a error message was displayed, informing the user what the correct input data format is. While the "program is" waiting for the "Terminate time", it would scan the keyboard for the ' escape key to terminate ' program on user demand.

; Wait for TIME
; This program can be executed inside of a. BAT file to
; Stall execution of the. BAT file until a set time of
;?????????????????????????????????????????????????????????? ???
Conditional assembly flag, 0 to-use DOS, 1 to-use BIOS example
. MODEL Tiny
Use_bios_flag EQU 1
;-----------Stack Area---------------
. STACK 500
;--------------------------------------
. CODE
;************* @@@@@@@@@@@@@@ ***************
Start proc near
MOV bx,80h index command line data
mov al,[bx]; get size of string variable
MOV Ax,cs
mov ds,ax; reset data segment
MOV psp_seg,es; save PSP Address
mov es,ax; reset extra Segment
CMP al,4; Is there data in string
JB Exit_bad; Branch if no data
Inc BX
Inc BX;p oint to start of data
; Get number out of buffer area
Call Get_number
JC Exit_bad Branch If number bad
MOV wait_hour,al save number in hour
CMP al,23;?? Number too large??
JA Exit_bad branch is too large
; Check the number terminating character
CMP Ah, ":"
jne Exit_bad; branch if not:
;p oint to start of next
Inc BX
; Get next number out of the buffer area
Call Get_number
JC Exit_bad Branch If number bad
CMP al,59;?? Number too large??
JA exit_bad; branch if too large
MOV wait_minute,al save number to minute
;d isplay executing wait message
mov ah,9; set DOS function number
Lea Dx,wait_message
int 21H;D OS call to display message
;________________________________
;********** !!!!!!!! **********
Wait_loop:
; scan keyboard for keys
MOV ah,1
int 16H
JZ wait_no_key; branch if no key
MOV ah,0 If here then keyboard data
int 16H; Get key code from buffer
CMP ax,3b00h Check Key code
JE Exit branch if exit key
CMP al,1bh Check for ESC key
JE Exit; branch if ESC key
Wait_no_key:
; Find out what time it is
; Conditional Assembly????????????????????
; Use this code if linking to code in this section
IF Use_bios_flag
Call Get_time_of_day
; Else use this code if calling DOS for time
ELSE
MOV ah,2ch
int 21H;
ENDIF
CMP Ch,wait_hour
Jne Wait_loop Loop if not
CMP Cl,wait_minute
Jne Wait_loop Loop if not
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exit
MOV ah,4ch
int 21h; Terminate program
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Exit_bad:
MOV ah,9
Lea Dx,exit_bad_message
int 21H;D OS call to display message
JMP exit
; ***** ^^^^^^^^ ***** ^^^^^^^^ ****
Get_number:
; On entry BX indexes ASCII Number data into PSP segment area
; On exit if carry clear,
; Register AL has binary number, from 0 to 99
; BX indexes past the number,
; AH has exiting character code indexed by BX
Push DS
MOV ds,psp_seg
MOV AL,[BX]
Inc BX
Call Number_check
JC Get_number_bad
MOV Ah,al
MOV AL,[BX]
Call Number_check
JC Get_number_1
GET_NUMBER_2A:
CMP ah,0
Je get_number_2
Add al,10
Dec AH
JMP get_number_2a
Get_number_2:
Inc BX
MOV Ah,al
MOV AL,[BX]
Get_number_1:
CMP al, ":"
Je get_number_1a
CMP AL,0DH
Jne Get_number_bad
GET_NUMBER_1A:
Xchg Al,ah
Pop ds
CLC; set good number flag
Ret
Get_number_bad:
Pop ds
STC; set bad number flag
Ret
;#################################################
Number_check:
; This code checks for ASCII number in AL
; If it finds a number, then it makes it binary
; and returns with carry clear, else carry set
CMP al, "0"
JB Number_bad
CMP al, "9"
JA number_bad
and AL,0FH
Clc
RET STC
Ret
;*************************
Start ENDP
; +++ This routine combines the data and code into one segment +++
; Define data area
PSP_SEG DW 0
Wait_hour DB 0
Wait_minute DB 0
Wait_message DB 0dh,0ah,0dh,0ah
DB "Wait in progress, press [ESC] to exit", 0dh,0ah
DB "$"
Exit_bad_message DB 0dh,0ah
DB "To use Timewait program enter timeout data"
DB "from command line as example:", 0dh,0ah,0dh,0ah
DB "Timewait 11:30", 0dh,0ah,0dh,0ah
DB "Note, timeout hours vary from 0 to 23,"
DB "and minutes from 0 to", 0dh,0ah
DB "$"
;______________________________________
End Start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.