如何阅读、使用源码
问题一:求一字型数据的平方
参数: (ax) = 要计算的数据
返回值: 存放结果 DX高16位、AX低16位
应用: 求十进制运算 2*3456^2
完整源码
assume cs:code
code segment
start: mov ax,3456
int 7cH
add ax,ax
adc dx,dx
mov ax,4c00H
int 21H
code ends
end start
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
实际运行
问题二:将全是字母、以0结尾的字符串转为大写
参数: ds:si 指向字符串的首地址
应用: 将data段中的字符串转化为大写
完整源码
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
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
mov ax,4c00H
int 21H
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
code ends
end start
实际运行