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

我的博客

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

[2010-09-13 12:17] 习题4.30

图片载入中
请编写一个能够按DEBUG的D命令格式显示内存单元内容的小型工具。

答:
;-----------------------------------------------------
assume        cs:code,ss:stack
stack        segment stack
        dw 128 dup (0)
stack        ends
code        segment
start:
        mov bx,0
        mov si,bx
        mov cx,8
s0:        push cx
        mov dx,ds
        call wordhex
        mov dl,':'
        mov ah,2
        int 21h
        mov dx,bx
        call wordhex
        call space
        call space
        mov di,si
        mov cx,16
s1:
        mov dl,[si]
        call bytehex
        call space
        inc si 
;
        push cx
        mov ax,si
        mov cx,16
        xor dx,dx        
        div cx
        pop cx
        cmp dx,0
        jz s10 
;
        loop s1
s10:        call space
        call space
s11:        mov dl,[di]
        call ascii
        inc di
        cmp di,si
        jz s12
        jmp s11

s12:        call crlf
        add bx,16
        pop cx
        loop s0
;        
s2:        mov dl,'-'
        mov ah,2
        int 21h
        mov ah,1
        int 21h
        cmp al,'d'
        jz jx
        cmp al,'q'
        jz done
        jmp s3
jx:        call crlf
        add cx,8
        jmp s0
s3:        call crlf
        jmp s2
done:
        mov ah,4ch
        int 21h
;sub-proc
;
crlf        proc
        mov ah,2
        mov dl,0dh
        int 21h
        mov dl,0ah
        int 21h
        ret
crlf        endp
space        proc
        mov ah,2
        mov dl,20h
        int 21h
        ret
space        endp
;
;input:DX
;output:display word hex
wordhex        proc uses ax bx cx  
        mov cx,4
        mov ah,2        ;No.2 func
whex:        push cx
        mov cl,4
        rol dx,cl
        push dx
        and dx,0fh
        cmp dl,10
        jb whex1
        add dl,37h
        int 21h
        jmp whex2
whex1:        add dl,30h
        int 21h
whex2:        pop dx
        pop cx
        loop whex
        ret
wordhex        endp
;
;input:DL
;output:display byte-hex
bytehex        proc uses ax bx cx
        mov cx,2
        mov ah,2        ;No.2 func
        xor dh,dh
bhex:        push cx
        mov cl,4
        rol dl,cl
        push dx
        and dl,0fh
        cmp dl,10
        jb bhex1
        add dl,37h
        int 21h
        jmp bhex2
bhex1:        add dl,30h
        int 21h
bhex2:        pop dx
        pop cx
        loop bhex
        ret
bytehex        endp
;
;input:DL
;output:display ascii
ascii        proc uses ax bx cx
        mov ah,2        ;No.2 func
        cmp dl,20h
        jb dot
        cmp dl,7eh
        ja dot
        int 21h
        ret
dot:        mov dl,2eh
        int 21h
        ret
ascii        endp
;
code        ends
end        start
;-----------------------------------------------------
评论次数(1)  |  浏览次数(619)  |  类型(汇编习题集) |  收藏此文  | 

[  masmaster   发表于  2010-09-14 10:51  ]

跟真的debug的D命令比, 丝毫不差! 自己庆祝一下。

 
 请输入验证码  (提示:点击验证码输入框,以获取验证码