程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 匯編語言 >> 匯編源代碼之GET TIME OF DAY(獲取時間)

匯編源代碼之GET TIME OF DAY(獲取時間)

編輯:匯編語言

INTRODUCTION

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

FIRST EXAMPLE

This example runs until a set time of day occurs and then terminates. This code gets the time of day information from the DOS command line input data. If there is bad input data, then an error message is displayed, informing the user what the correct input data format is. While the program is waiting for the terminate time, it will scan the keyboard for an escape key to terminate the 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 day
;?????????????????????????????????????????????????????????? ???
;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      ;point 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 :
   ;point to start of next number
    inc   bx
   ;get next number out of 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
  ;display executing wait message
    mov   ah,9    ;set DOS function number
    lea   dx,wait_message
    int   21H     ;DOS 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       ;get current time of day
ENDIF
    cmp   ch,wait_hour
    jne   wait_loop    ;loop if not time
    cmp   cl,wait_minute
    jne   wait_loop    ;loop if not time
;^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
exit:
    mov   ah,4CH
    int   21h       ;terminate program
;!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
exit_bad:
    mov   ah,9
    lea   dx,exit_bad_message
    int   21H       ;DOS call to display message
    jmp   exit
; ***** ^^^^^^^^ ***** ^^^^^^^^ ****
get_number:
;on entry BX indexes ASCII number data in 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 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 59.",0DH,0AH
    db   "$"
;______________________________________
   end start

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved