本文为《汇编语言程序设计》1301小节例程。点击链接…进课程主页。
示例1:中断7ch的中断例程的编写和安装
任务:编写程序,写7ch的中断例程,完成特定任务
功能:求一个word型数据的平方
参数: (ax)=要计算的数据
返回值:dx, ax中存放结果的高、低16位
程序实现
assume cs:code
code segment
start:mov ax,cs
mov ds,ax
mov si,offset sqr
mov ax,0
mov es,ax
mov di,200h
mov cx,offset sqrend - offset sqr
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
sqr: mul ax
iret
sqrend:nop
code ends
end start
测试说明:用下面的程序,通过调用中断求2*3456^2
assume cs:code
code segment
start: mov ax,3456
int 7ch ; 计算(ax)^2
add ax,ax
adc dx, dx
mov ax,4c00h
int 21h
code ends
end start
示例2 :中断7ch的中断例程,7ch的中断例程的任务是——
功能:将以 0结尾的字符串转化为大写。
参数: ds:si指向字符串的首地址
程序:
assume cs:code
code segment
start:mov ax,cs
mov ds,ax
mov si,offset capital
mov ax,0
mov es,ax
mov di,200h
mov cx,offset capitalend - offset capital
cld
rep movsb
mov ax,0
mov es,ax
mov word ptr es:[7ch*4],200h
mov word ptr es:[7ch*4+2],0
capital:
push cx
push si
change: mov cl,[si]
mov ch,0
jcxz ok
and byte ptr [si],11011111b
inc si
jmp short change
ok: pop si
pop cx
iret
capitalend:nop
mov ax,4c00h
int 21h
code ends
end start
测试说明:用下面的程序调用中断7ch
assume cs:code
data segment
db 'conversation',0
data ends
code segment
start: mov ax,data
mov ds,ax
mov si,0
int 7ch
mov ax,4c00h
int 21h
code ends
end start