+ -
当前位置:首页 → 问答吧 → 菜鸟求助:如何用汇编语言显示0到60数字???

菜鸟求助:如何用汇编语言显示0到60数字???

时间:2010-11-07

来源:互联网

请问大家如何用汇编语言编写显示从0到60变化的数字??

作者: a870089402   发布时间: 2010-11-07

调用dos中断或bios中断

作者: lizi5803   发布时间: 2010-11-07

Assembly code

assume    cs:code
code    segment
start:
    mov ax,0b800h      ;定义显示缓冲区
    mov ds,ax

    mov di,160*12+40*2 ;显示位置
    mov ah,2           ;字符属性
    mov bx,0           ;起始数字
    mov cx,10          ;除数
s:
    cmp bx,60          ;如果bx等于60则结束程序
    ja over
    cmp bx,9           ;如果bx>9,则处理2位数字
    ja s1
    mov al,bl          ;显示数字
    add al,30h         ;
    mov [di],ax        ;
    inc bx             ;指向下一个数字
    call sleep         ;暂停一下
    jmp s              ;继续显示
s1:    
    xor dx,dx          ;如果bx大于9,则
    xor ah,ah          ;将BCD码转换成ASCII
    mov al,bl          ;并显示在指定位置
    div cx
    mov ah,2           ;字符属性
    add al,30h         ;
    mov [di],ax        ;显示十位
    add dl,30h
    mov al,dl
    mov [di+2],ax      ;显示个位
    inc bx             ;指向下一数字
    call sleep         ;暂停一会儿
    jmp s              ;继续显示
over:
    mov ah,4ch
    int 21h
;这个子程序时根据空循环编写的, 时间上
;未必精准, 当然也可以用dos的1ah中断。
sleep    proc uses ax dx
    mov dx,1000h      ;数字越大暂停时间越长
    mov ax,0h         ;可自行调节
_s:    sub ax,1
    sbb dx,0
    cmp ax,0
    jne _s
    cmp dx,0
    jne _s
    ret
sleep    endp
;
code    ends
end    start


建议此程序在纯dos模式运行。

作者: masmaster   发布时间: 2010-11-07

热门下载

更多