实验10.1
1. X
- 题目:编写子程序-显示字符串
子程序描述 名称:show_str 功能:在指定的位置, 用指定的颜色, 显示一个用 0 结束的字符串。 参数:(dh)=行号(取值范围 0 ~ 24), (dl)=列号(取值范围 0 ~ 79), (cl)=颜色, ds:si 指向字符串的首地址 返回:无 应用举例:在屏幕的 8 行 3 列, 用绿色显示 data 段中的字符串。 'Welcome to masm!',0
assume cs:code,ds:data,ss:stack
data segment
db 'Welcome to masm!',0
data ends
stack segment stack
db 128 dup(0)
stack ends
code segment
start:
mov ax, stack
mov ss,ax
mov sp,128
mov dh,8 ; 行
mov dl,3 ; 列
mov cl,2 ; 颜色
call init_reg
mov si,0
call show_str
mov ax,4c00h
int 21h
;=================================
init_reg:
mov ax, data
mov ds,ax
mov bx,0B800H
mov es,bx
ret
;=================================
get_col:
mov al,2
mov bl,dl
mul bl
add di,ax
ret
;=================================
get_row:
mov al,160
mov bl, dh
mul bl
mov di, ax ; es:[di]
ret
;=================================
show_str:
call get_row
call get_col
mov dh,cl ; dx dl = 字符, dh = 颜色
call show_string
ret
;=================================
show_string:
push cx
push dx
push ds
push es
push si
push di
mov cx,0
showString:
mov cl, ds:[si]
jcxz showStringRet
mov dl, cl
mov es:[di],dx
add di,2
inc si
jmp showString
showStringRet:
pop di
pop si
pop es
pop ds
pop dx
pop cx
ret
code ends
end start