(汇编源代码 )获取当前系统时间

;==========================================
;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

时间: 2016-04-30

(汇编源代码 )获取当前系统时间的相关文章

c++-如何用C++获取当前系统时间

问题描述 如何用C++获取当前系统时间 如何用C++获取当前系统时间,望大神给出具体的执行步骤,还有头文件,谢谢大神们 解决方案 #include <time.h> #include <stdio.h> int main( void ) { time_t t = time(0); char tmp[64]; strftime( tmp, sizeof(tmp), "%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t) ); pu

C++获取当前系统时间的方法总结_C 语言

本文实例讲述了C++获取当前系统时间的方法.分享给大家供大家参考.具体如下: 方案- 优点:仅使用C标准库:缺点:只能精确到秒级 #include <time.h> #include <stdio.h> int main( void ) { time_t t = time(0); char tmp[64]; strftime(tmp,sizeof(tmp),"%Y/%m/%d %X %A 本年第%j天 %z",localtime(&t)); puts(

C# 当前系统时间获取及时间格式详解_C#教程

C# 当前系统时间获取及时间格式       最近学习C# 的知识,对获取系统时间和时间格式进行了总结,这是本文在网上整理的详细资料,大家看下! --DateTime 数字型 System.DateTime currentTime=new System.DateTime(); 取当前年月日时分秒 currentTime=System.DateTime.Now; 取当前年 int 年=currentTime.Year; 取当前月 int 月=currentTime.Month; 取当前日 int

VC++ 获取系统时间的方法汇总_C 语言

1.使用CTime类(获取系统当前时间,精确到秒) CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime();//获取系统日期 str=tm.Format("现在时间是%Y年%m月%d日 %X"); MessageBox(str,NULL,MB_OK); a,从CTimet中提取年月日时分秒 CTime t = CTime::GetCurrentTime(); int d=t.GetDay(); //获得几号 int y=t.

Java获取系统时间

1. SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");String datetime = tempDate.format(new java.util.Date()); 2. Calendar now=Calendar.getInstance();String time=now.get(Calendar.YEAR)+"-"+(now.get(Calendar.MONTH)+

(汇编源代码 )简单的取系统时间小程序

code segmentassume cs:codestart: mov ah,2ch :2ch号功能调用,取系统时间:ch,cl,dh中分别存放时分秒 int 21h call disptime:调用disptime子程序显示时间exit: mov ax,4c00h :结束程序,返回DOS int 21h disptime proc mov al,ch :小时的值赋给al cbw :al扩展成ax,用做除法的被除数 call bindec mov dl,':' :显示":" mov

ndk-通过NDK获取手机信息(版本号,sdk版本,包名,屏幕的宽高,系统时间,ip)

问题描述 通过NDK获取手机信息(版本号,sdk版本,包名,屏幕的宽高,系统时间,ip) 5C 通过NDK获取手机信息(版本号,sdk版本,包名,屏幕的宽高,系统时间,ip)求大神解答 解决方案 http://www.2cto.com/kf/201506/407260.htmlhttp://www.xuebuyuan.com/1006760.html

VC获取系统时间、程序运行时间

1.使用CTime类 CString str; //获取系统时间 CTime tm; tm=CTime::GetCurrentTime(); str=tm.Format("现在时间是%Y年%m月%d日 %X"); MessageBox(str,NULL,MB_OK); 2: 得到系统时间日期(使用GetLocalTime) SYSTEMTIME st; CString strDate,strTime; GetLocalTime(&st); strDate.Format(&quo

Dos下获取系统时间的代码

dos下获取系统时间的实现代码,需要的朋友可以参考下   复制代码 代码如下:   rem DOS get current time  rem =======================  rem get yyyy/mm/dd  set mydate=%DATE:~0,10%  echo %mydate%  rem =======================  rem get yyyy  set yyyy=%DATE:~0,4%  echo %yyyy%  rem ===========