关闭

汇编学习(八)8086汇编拾遗 (7)

152人阅读 评论(0) 收藏 举报
int 中断指令

使用方式:

int n.  n 为中断类型码,它的功能是引发中断,n 为引发的中断号。

先写一个中断程序的例子吧,安装中断7ch 中断例程,计算一个字型数的平方。
assume cs:code

code segment

    start:
        mov ax,cs
        mov ds,ax
        
        mov si,offset sets
        mov di,200h
        mov ax,0
        mov es,ax
        mov cx,offset sets0 - offset sets
        cld
        rep movsb

        mov ax,0
        mov es,ax
        mov word ptr es:[7ch*4],200h
        mov word ptr es:[7ch*4 + 2],0

        mov ax,4c00h
        int 21h

    sets:
        mul ax
        iret

    sets0:nop

code ends

end start
再来一个转换字符串的中断。 功能:将一个全是子母,以0结尾的字符串转换为大写。
assume cs:code

code segment

    start:
        mov ah,2
        mov bh,0
        mov dh,5
        mov dl,12
        int 10h
        
        mov ah,9
        mov al,'a'
        mov bl,11001010b
        mov bh,0
        mov cx,3
        int 10h


        mov ax,4c00h
        int 21h

code ends
end start
使用int 模拟 loop
assume cs:code

code segment
    start:
        mov ax,cs
        mov ds,ax
        mov ax,0
        mov es,ax
        mov si,200h
        mov di,offset se

        mov cx,offset se0 - offset se

        rep movsb

        mov ax,0
        mov es,ax
        mov word ptr es:[7ch*4],0
        mov word ptr es:[7ch*4+2],200h

        mov ax,4c00h
        int 21h

    se:
        push bp
        mov bp,sp
        dec cx
        jcxz ll
        add [bp+2],bx
    ll:
        pop bp
        iret

    se0:
        nop

code ends
end start
编写7CH中断实现jmp near ptr s   功能:
assume cs:code

data segment

    db 'conversion',0

data ends

code segment

    start:
        mov ax,cs
        mov ds,ax
        mov si,offset se
        mov ax,0
        mov es,ax
        mov di,200h
        mov cx,offset se0 - offset se 

        rep movsb

        mov ax,0
        mov es,ax
        mov word ptr es:[7ch*4],200h
        mov word ptr es:[7ch*4+2],0
        
        mov ax,data
        mov ds,ax
        mov si,0
        mov ax,0b800h
        mov es,ax
        mov di,12*160
      s:
        cmp byte ptr [si],0
        je ok
        mov al,[si]
        mov es:[di],al
        inc si
        add di,2
        mov bx,offset s - offset ok
        int 7ch
     ok:
        mov ax,4c00h
        int 21h


    se:
        push bp
        mov  bp,sp
        add  [bp+2],bx
        pop bp
        iret

    se0:nop

code ends
end start
编写并安装7ch中断,直到0结束的字符串
assume cs:code

data segment

    db 'weclome to linux world!',0

data ends

code segment

    start:
        mov ax,cs                ;添加中断代码
        mov ds,ax
        
        mov si,offset se 
        mov di,200h

        mov ax,0
        mov es,ax
        mov cx,offset se0 - offset se 
        
        cld 
        rep movsb

        mov ax,0                 ;设置中断号
        mov es,ax
        mov word ptr es:[7ch * 4],200h
        mov word ptr es:[7ch * 4 + 2],0
    
        mov dh,10                ;测试代码
        mov dl,10
        mov cl,2
        mov ax,data
        mov ds,ax
        mov si,0
        int 7ch



        mov ax,4c00h
        int 21h

    se:
        mov al,160           ;设置es:0b800h         
        mul dh
        add dl,dl
        mov dh,0
        add ax,dx
        mov di,ax
        mov ax,0b800h
        mov es,ax
      s:
        mov al,ds:[si]       ;打印字符
        mov ah,0
        cmp ax,0
        je f
        mov ah,cl 
        mov es:[di],ax
        inc si
        inc di
        inc di
        jmp s
      f:
        iret

    se0:nop


code ends
end start
编写7C 中断,打印80个!
assume cs:code

code segment

    start:
        mov ax,cs                       ;安装中断
        mov ds,ax
        mov si,offset lp

        mov ax,0
        mov es,ax
        mov di,200h

        mov cx,offset lpend - offset lp
        cld
        rep movsb

        mov word ptr es:[7ch*4],200h
        mov word ptr es:[7ch*4 + 2],0

        mov ax,0b800h                   ;设置es
        mov es,ax
        mov di,160*12
        mov bx,offset s -offset se 
        mov cx,80
        s:
            mov byte ptr es:[di],'!'
            add di,2
            int 7ch
        se:
            nop

        mov ax,4c00h
        int 21h

        lp:
            push bp                     ;循环 
            dec cx
            jcxz f
            mov bp,sp
            add [bp+2],bx
        f:
            pop bp
            iret
        lpend:nop

code ends
end start
 

查看原文:http://zmrlinux.com/2016/05/31/%e6%b1%87%e7%bc%96%e5%ad%a6%e4%b9%a0%ef%bc%88%e5%85%ab%ef%bc%898086%e6%b1%87%e7%bc%96%e6%8b%be%e9%81%97-7/
0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:73488次
    • 积分:3103
    • 等级:
    • 排名:第11531名
    • 原创:244篇
    • 转载:6篇
    • 译文:0篇
    • 评论:13条
    最新评论