【子程序】显示字符串

image

assume cs:code

data segment

	db 'welcome to masm',0

data ends

code segment

start:	mov dh,8            ; row number
		mov dl,3			; col number
		mov cl,2            ; color
		mov ax,data
		mov ds,ax
		mov si,0            ; ds:si head of str
		call show_str

		mov ax,4c00h
		int 21h

show_str:
		; protect the scene
		push ax
		push dx
		push es
		push cx
		push si
		push di
		
		; ptr of str: 0b800h:dh * 160 + dl * 2
		mov ah,0
		mov al,160
		mul dh
		mov dh,0
		add ax,dx
		add ax,dx
		mov di,ax
		mov ax,0b800h
		mov es,ax

		; tmp of cl
		mov dl,cl

		mov ch,0
s:		
		mov cl,ds:[si]
		jcxz ok
		mov al,ds:[si]
		mov es:[di],al
		mov es:[di+1],dl
		inc si
		add di,2
		jmp short s

ok:		
		; restore the secen
		pop di
		pop si
		pop cx
		pop es
		pop dx
		pop ax
		ret

code ends

end start
posted @ 2022-05-31 13:51  moon_orange  阅读(22)  评论(0编辑  收藏  举报