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

我的博客

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

[2010-09-21 22:33] 习题5.26

图片载入中
编写一个能够显示指定向量号的中断向量的程序。

答:
;----------------------------------------------------;
assume        cs:code,ds:data,ss:stack
data        segment
msg1        db        'Input number of interrupt in hex:$'
msg2        db        'The interrupt vector is:$'
msg3        db        'Input Error!$'
buff        db        3,0,0,0
_ip        dw        0
_cs        dw        0
data        ends
stack        segment stack
        db 128 dup (0)
stack        ends
code        segment
start:
        mov ax,data
        mov ds,ax        
        mov dx,offset msg1
        mov ah,9
        int 21h
        mov dx,offset buff
        mov ah,0ah
        int 21h
;
        call crlf
        mov dx,offset msg2
        mov ah,9
        int 21h

        cmp buff+1,0
        jz over
        cmp buff+1,1
        jz single
        mov al,buff+2
        call pd
        jc errmsg
        mov ah,al
        mov al,buff+3
        call pd
        jc errmsg
        mov cl,4
        shl ah,cl
        add al,ah
        xor ah,ah
        jmp count
single:        
        mov ax,word ptr buff+2
        sub al,30h
        and ax,0ffh
;AL
count:
;ip=N*4,cs=N*4+2
        shl ax,1
        shl ax,1
;
        push ax
        mov ax,0
        mov ds,ax
        pop bx
        lea ax,[bx]
        mov _ip,ax
        lea ax,[bx+2]
        mov _cs,ax
        push _ip
        push _cs
        call show
        jmp over

errmsg:        
        call crlf
        mov dx,offset msg3
        mov ah,9
        int 21h        
;
over:        mov ah,4ch
        int 21h
;
crlf        proc
        mov ah,2
        mov dl,0dh
        int 21h
        mov dl,0ah
        int 21h
        ret
crlf        endp
;
pd        proc
        cmp al,'0'
        jb err
        cmp al,'9'
        ja zm1
        sub al,30h
        jmp ok
zm1:        cmp al,'A'
        jb err
        cmp al,'F'
        ja zm2
        sub al,37h
        jmp ok
zm2:        cmp al,'a'
        jb err
        cmp al,'f'
        ja err
        sub al,57h
        jmp ok
err:        stc
ok:        ret
pd        endp
;
;ax
disphex        proc  
        mov cx,4
d1:        push cx
        mov cl,4
        rol ax,cl
        push ax
        and ax,0fh
        cmp al,10
        jb d10
        mov dl,al
        add dl,37h
        mov ah,2
        int 21h
        jmp jx2
d10:        mov dl,al
        add dl,30h
        mov ah,2
        int 21h
jx2:        pop ax
        pop cx
        loop d1
        ret
disphex        endp
;
show        proc
        push bp
        mov bp,sp
        mov bx,[bp+6]        ;ip
        mov ax,[bx]
        call disphex
        mov dl,':'
        mov ah,2
        int 21h
        mov bx,[bp+4]        ;cs
        mov ax,[bx]
        call disphex
        pop bp
        ret 4
show        endp
;
code        ends
end        start
;----------------------------------------------------;
评论次数(0)  |  浏览次数(591)  |  类型(汇编习题集) |  收藏此文  | 
 
 请输入验证码  (提示:点击验证码输入框,以获取验证码