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

(匯編源代碼 )獲取當前系統時間

編輯:匯編語言

;==========================================
;A little assembly app that shows the current date and time.
;It can be done a lot easier, but this way you will
;see how to do some basic memory manipulation, and how to use 'variables'.
;==========================================
.model small
.stack
  ;===========================
;Data segment starts here
;===========================
.data
date_strdb"Current date is: yyyy-mm-dd", 0Ah, 0Dh, "$"
time_strdb"Current time is: hh.mm.ss:xx", 0Ah, 0Dh, "$"
min_sizedw?
padd_chrdb ?
;===========================
;Code segment starts here
;===========================
.code
mainproc
movax, seg @data ;First we get the data segment address
movds, ax ;and store it into ds
  mov[min_size], 02h ;Results should always be at least two digits
mov[padd_chr], '0' ;Use '0' as padding-character
  movah, 2Ah ;Then we call int 21h,2Ah, which will give
int21h ;us the current date
  leadi, date_str ;Then we load the address of the date_str string
adddi, 17 ;and set si to point at the first y in yyyy-...
movax, cx ;Next we mov cx to ax and
calltodec ;call todec
incdi ;We skip the '-' character...
  xorax, ax ;Then we empty ax
moval, dh ;And set the low-byte of ax to dh
calltodec
incdi ;Skip character in string...
  xorax, ax ;Empty ax
moval, dl ;Set low-byte to dl
calltodec ;Convert it to base10
leadi, time_str ;Now we load the time_str string
adddi, 17 ;And set the correct pointer offset
  movah, 2Ch ;And then we call int 21h,2Ch
int21h ;which will give us the current time
xorax, ax ;Empty ax
moval, ch ;Set low-byte to ch
calltodec ;Convert it to base10
incdi ;Skip character
  moval, cl ;Set low-byte to cl
calltodec ;Convert to base10
incdi ;Skip character
  moval, dh ;Set low-byte to dh
calltodec ;Convert to base10
incdi ;Skip character
  moval, dl ;Set low-byte to dl
calltodec ;Convert to base10
movdx, offset date_str;Now load offset of the date_str string into dx
callprint ;And print the (modified) string
  movdx, offset time_str;Load offset of the time_str string into dx
callprint ;And print the (modified) string
  movax, 4C00h ;Do a clean exit(error code=00)
int21h
  ;===================================================================
;todec - converts the contents of ax into base10 ascii character(s)
;    of length bx
;    min_size defines minimum length of result, and padd_char
;    defines the padding character.
;The result(s) are stored at ds:di
;===================================================================
todecproc
pushax ;Save all registers
pushbx
pushcx
pushdx
xorcx,cx ;Empty the POP counter
movbx,10 ;Base divisor
decloop: 
xordx,dx ;Set the high 16-bits to 0
divbx ;Preform division(dx=remainder, ax=quotient)
inccx ;Increase the counter
pushdx ;and save the remainder
cmpax,0 ;If the quotient != 0
jnzdecloop ;then get one more number
movbx, [min_size] ;Load min_size value into bx
movdl, [padd_chr] ;Load padd_chr value into dl
padd_result:
cmpcx, bx ;Is cx >= min_size?
jgepoploop ;If so, proceed
  movbyte ptr ds:[di], dl;Else padd with padd_chr
incdi ;and increase string pointer
decbx ;decrease bx
jmppadd_result ;and test for more padding
  poploop:
popdx ;Get the number of the stack
adddl,'0' ;and add '0' to it
movbyte ptr ds:[di], dl;Modify the string at ds:di
incdi ;Increase the string pointer
deccx ;Decrease the loop counter
jnzpoploop
popdx ;Restore all registers
popcx
popbx
popax
ret  ;And return from call
todecendp
;===========================================================
;print - prints the string pointed to by dx using int 21h,09
;===========================================================
printproc
pushax ;Save ax
pushds ;and ds onto the stack
  movax, @data ;Then get the address of the data segment
movds, ax ;and store it into ds
movax, 0900h 
int21h ;and then print the message pointed to by dx
popds ;Retrieve ds
popax ;and ax from stack
  ret
printendp
  mainendp
endmain

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