汇编学习笔记(三) -- 显示时间

记:
还是从编程论坛看的帖子http://bbs.bccn.net/thread-465605-1-1.html 拿来做了练习
看的时候觉得看懂了 可实际写的时候才知道 纸上得来终觉浅

data segment
    time_str  db '00:00:00', '$'    ; 显示时间的字符串
data ends

code segment
    assume cs:code, ds:data, es:data

    start: 
        mov   ah, 03h           ; 读取光标位置  返回值: dx, cx
        int   10h
        push  cx                ; 保存光标位置
        push  dx

        mov   ah, 01h           ; 设置光标形状
        mov   cx, 2030h         ; ch第7位必须为0  
                                ; (6位:5位)=(1:0)时 光标隐形
        int   10h

        mov   ax, data
        mov   ds, ax
        mov   es, ax

    show_time:
        pop   dx                ; 读取光标位置
        pop   cx
        mov   ah, 02h           ; 设置光标位置
        int   10h
        push  cx                ; 保存光标位置
        push  dx

        mov   ah, 2ch           ; 读取时间
        int   21h

        mov   di, offset time_str
        mov   al, ch            ; 取 时
        call  to_ascii
        mov   al, cl            ; 取 分
        call  to_ascii          
        mov   al, dh            ; 取 秒
        call  to_ascii  

        mov   dx, offset time_str
        mov   ah, 09h
        int   21h

        mov   ah, 01h           ; 读取键盘状态  
                                ; ZF=1 -- 无字符输入  
                                ; 否则 ah=键盘扫描码  
                                ; al=字符ascii码
        int   16h
        jz    show_time
        cmp   al, 1bh           ; 判断是不是 'ESC'
        jnz   show_time

        mov   ah, 4ch
        int   21h

    to_ascii:
        aam                     ; ah=al/10, al=al%10
        or    ax, 3030h         ; ah += 30h, al += 30h   
                                ; 将ah和al中的数字转化为他们的
                                ; ascii形式
        xchg  ah, al            ; 因为intel是高高低低存储 
                                ; 所以将他们交换位置
        stosw                   ; 将ax中的内容存储到 es:di
        inc   di                ; 将 es:di越过 ':'
        ret
code ends
    end start
  • 注: 仅作个人笔记之用 如有错误或不妥 还望不吝赐教

猜你喜欢

转载自blog.csdn.net/u013005025/article/details/52699800