|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 远山 于 2016-4-27 15:44 编辑
assume cs:code,ds:data,ss:stack
data segment
db 'welcome to masm!',0
data ends
stack segment
db 16 dup (0)
stack ends
code segment
start:mov dh,8
mov dl,3
mov cl,2
mov ax,data
mov ds,ax
mov si,0
call show_str
mov ax,4c00h
int 21h
show_str:push ax
push bx
push cx
push dx
push si
push di ; 将子程序中用到的寄存器内容保存起来。
mov al,160
mul dh ;8*160寻址到第8行,因为每行160个字节,结果以乘积的形式默认放到ax中。
mov bx,ax ;将乘积转存至bx中。
mov al,2
mul dl ;2*3寻址到该行的第6个字节处,结果以乘积的形式默认放到ax中。
add bx,ax ;将最终定位的地址放到bx中,共后面指令使用。
mov ax,0b800h
mov es,ax ;初始化es寄存器,将段地址b800放入其中。
mov di,0
mov ah,cl ;将原本存储在cl中的字符的属性内容转存到ah中,因为cx在后面要用来与“jcxz”指令搭配使用。
s:mov ch,0
mov cl,ds:[si] ;将第一个字节存到cl中。
jcxz s0 ;判断cx是否为0,为0即表示字符串结束,跳转,否则继续向下执行。
mov es:[bx+di],cl ;将字符内容放入低地址中。
mov es:[bx+1+di],ah ;将字符属性放入高地址中。
inc si ;si+1,定位到下一个字符。
add di,2 ;di+2,定位到显示字符的下两个字节。
jump short s ;跳转。
s0:pop di ;取出寄存器内容,返回。
pop si
pop dx
pop cx
pop bx
pop ax
ret
code ends
end start
|
|