《電子技術應用》
您所在的位置:首頁 > 嵌入式技术 > 解决方案 > 汇编源代码之GET TIME OF DAY(获取时间)

汇编源代码之GET TIME OF DAY(获取时间)

2017-07-23
關鍵詞: 汇编语言

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


本站內容除特別聲明的原創文章之外,轉載內容只為傳遞更多信息,并不代表本網站贊同其觀點。轉載的所有的文章、圖片、音/視頻文件等資料的版權歸版權所有權人所有。本站采用的非本站原創文章及圖片等內容無法一一聯系確認版權者。如涉及作品內容、版權和其它問題,請及時通過電子郵件或電話通知我們,以便迅速采取適當措施,避免給雙方造成不必要的經濟損失。聯系電話:010-82306118;郵箱:aet@chinaaet.com。
主站蜘蛛池模板: 国产精品九九久久久久久久| 一区二区三区四区久久| 久久偷窥视频| 日本一区二区久久精品| 亚洲伊人成综合成人网| 91精品在线观| 国产精品久久久久av福利动漫| 在线播放 亚洲| 日韩中文字幕一区二区| 婷婷视频在线播放| 国产美女视频免费| 国产日韩欧美中文在线播放| 精品中文字幕在线观看| 国产欧洲精品视频| 不卡一区二区三区视频| 亚洲一区二区不卡视频| 国产在线精品91| 99久久伊人精品影院| 日韩激情久久| 国产精品一区二区免费看| 天天操天天干天天玩| 日韩中文字幕视频在线| 国产不卡av在线| 欧美日韩无遮挡| 久久久亚洲天堂| 亚洲视频在线观看日本a| 美女视频久久| 国产精品96久久久久久| 久久久久久av| 性高潮久久久久久久久| 国产精品中文字幕在线| 亚洲国产欧美一区二区三区不卡| 日韩中文字幕第一页| 日韩欧美一区二| 国产日韩第一页v| 99精彩视频在线观看免费| 国模吧无码一区二区三区| 国产乱子伦精品| 久久精品视频在线播放| 日产国产精品精品a∨| 91国产在线播放|