庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>程序设计>汇编语言>相关源码>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

获取当前系统时间

 作者:本站收集   日期:2005-8-1 15:39:00
字号选择〖 〗/ 双击滚屏 单击停止   

;==========================================
;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_str db "Current date is: yyyy-mm-dd", 0Ah, 0Dh, "$"
time_str db "Current time is: hh.mm.ss:xx", 0Ah, 0Dh, "$"
min_size dw ?
padd_chr db ?


;===========================
;Code segment starts here
;===========================
.code
main proc
mov ax, seg @data ;First we get the data segment address
mov ds, 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

mov ah, 2Ah ;Then we call int 21h,2Ah, which will give
int 21h ;us the current date

lea di, date_str ;Then we load the address of the date_str string
add di, 17 ;and set si to point at the first y in yyyy-...


mov ax, cx ;Next we mov cx to ax and
call todec ;call todec
inc di ;We skip the '-' character...

xor ax, ax ;Then we empty ax
mov al, dh ;And set the low-byte of ax to dh
call todec
inc di ;Skip character in string...

xor ax, ax ;Empty ax
mov al, dl ;Set low-byte to dl
call todec ;Convert it to base10


lea di, time_str ;Now we load the time_str string
add di, 17 ;And set the correct pointer offset

mov ah, 2Ch ;And then we call int 21h,2Ch
int 21h ;which will give us the current time


xor ax, ax ;Empty ax
mov al, ch ;Set low-byte to ch
call todec ;Convert it to base10
inc di ;Skip character

mov al, cl ;Set low-byte to cl
call todec ;Convert to base10
inc di ;Skip character

mov al, dh ;Set low-byte to dh
call todec ;Convert to base10
inc di ;Skip character

mov al, dl ;Set low-byte to dl
call todec ;Convert to base10


mov dx, offset date_str ;Now load offset of the date_str string into dx
call print ;And print the (modified) string

mov dx, offset time_str ;Load offset of the time_str string into dx
call print ;And print the (modified) string

mov ax, 4C00h ;Do a clean exit(error code=00)
int 21h

;===================================================================
;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
;===================================================================
todec proc
push ax ;Save all registers
push bx
push cx
push dx


xor cx,cx ;Empty the POP counter
mov bx,10 ;Base divisor
decloop:
xor dx,dx ;Set the high 16-bits to 0
div bx ;Preform division(dx=remainder, ax=quotient)
inc cx ;Increase the counter
push dx ;and save the remainder
cmp ax,0 ;If the quotient != 0
jnz decloop ;then get one more number


mov bx, [min_size] ;Load min_size value into bx
mov dl, [padd_chr] ;Load padd_chr value into dl
padd_result:
cmp cx, bx ;Is cx >= min_size?
jge poploop ;If so, proceed

mov byte ptr ds:[di], dl ;Else padd with padd_chr
inc di ;and increase string pointer
dec bx ;decrease bx
jmp padd_result ;and test for more padding

poploop:
pop dx ;Get the number of the stack
add dl,'0' ;and add '0' to it
mov byte ptr ds:[di], dl ;Modify the string at ds:di
inc di ;Increase the string pointer
dec cx ;Decrease the loop counter
jnz poploop


pop dx ;Restore all registers
pop cx
pop bx
pop ax
ret ;And return from call
todec endp


;===========================================================
;print - prints the string pointed to by dx using int 21h,09
;===========================================================
print proc
push ax ;Save ax
push ds ;and ds onto the stack

mov ax, @data ;Then get the address of the data segment
mov ds, ax ;and store it into ds
mov ax, 0900h
int 21h ;and then print the message pointed to by dx

pop ds ;Retrieve ds
pop ax ;and ax from stack

ret
print endp

main endp
end main

上一篇:CIH V1.5版本病毒源码    下一篇:简单的取系统时间小程序  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-8-1 15:39:00
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿