汇编网首页登录博客注册
masmaster的学习博客
博客首页博客互动【做检测题】论坛求助

我的博客

个人首页 |  我的文章 |  我的相册 |  我的好友 |  最新访客 |  文章收藏 |  论坛提问 |  友情链接 |  给我留言  
图片载入中
文章收藏

[2010-09-22 10:29] 习题5.27

写一个程序采用十六进制数的形式显示所按键的扫描码和对应的ASCII码。当连续两次按回车则终止程序。

答:
;----------------------------------------------------;
assume        cs:code,ds:data,ss:stack
data        segment
msg1        db        'ScanAsc:$'
msg2        db        'Over$'
data        ends
stack        segment stack
        db 128 dup (0)
stack        ends
code        segment
start:        
        mov ax,data
        mov ds,ax

L:        
        mov dx,offset msg1
        mov ah,9
        int 21h

        mov ah,0
        int 16h
        push ax
        cmp al,0dh
        jz a
b:        
        pop dx
        call disphex
        call crlf
        jmp L
a:
        mov ah,0
        int 16h
        cmp al,0dh
        jz over
        push ax
        jmp b
        
over:        mov dx,offset msg2
        mov ah,9
        int 21h
        mov ah,4ch
        int 21h
;
crlf        proc
        mov ah,2
        mov dl,0dh
        int 21h
        mov dl,0ah
        int 21h
        ret
crlf        endp
;
disphex        proc uses dx
        mov cx,4
d1:        push cx
        mov cl,4
        rol dx,cl
        push dx
        and dx,0fh
        cmp dl,10
        jb d10
        add dl,37h
        mov ah,2
        int 21h
        jmp jx2
d10:        add dl,30h
        mov ah,2
        int 21h
jx2:        pop dx
        pop cx
        loop d1
        ret
disphex        endp
;
code        ends
end        start
;----------------------------------------------------;
评论次数(0)  |  浏览次数(518)  |  类型(汇编习题集) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码