assume ds:data, cs:code data segment db 'welcome to masm!' db 2H,24H,71H data ends code segment start: mov ax,data mov ds,ax mov ax,0B800H mov es,ax mov cx,10h mov bx,0 mov si,0 s0:mov ax,[bx] mov es:[0720h+si+bx],ax mov al,2h mov byte ptr es:[0721h+si+bx],al inc bx inc si loop s0 mov cx,10h mov bx,0 mov si,0 s1:mov ax,[bx] mov es:[07c0h+si+bx],ax mov al,24h mov byte ptr es:[07c1h+si+bx],al inc bx inc si loop s1 mov cx,10h mov bx,0 mov si,0 s2:mov ax,[bx] mov es:[0860h+si+bx],ax mov al,71h mov byte ptr es:[0861h+si+bx],al inc bx inc si loop s2 mov ax,4c00h int 21h code ends end start 改成子程序形式
时间: 2024-02-14 11:06:56 浏览: 72
下面是将代码改写成子程序形式的程序:
```
assume ds:data, cs:code
data segment
db 'welcome to masm!'
db 2H,24H,71H
data ends
code segment
start:
mov ax,data
mov ds,ax
mov ax,0B800H
mov es,ax
call print_string_attr_1
call print_string_attr_2
call print_string_attr_3
mov ax,4c00h
int 21h
print_string_attr_1:
mov cx,10h
mov bx,0
mov si,0
s0:
mov ax,[bx]
mov es:[0720h+si+bx],ax
mov al,2h
mov byte ptr es:[0721h+si+bx],al
inc bx
inc si
loop s0
ret
print_string_attr_2:
mov cx,10h
mov bx,0
mov si,0
s1:
mov ax,[bx]
mov es:[07c0h+si+bx],ax
mov al,24h
mov byte ptr es:[07c1h+si+bx],al
inc bx
inc si
loop s1
ret
print_string_attr_3:
mov cx,10h
mov bx,0
mov si,0
s2:
mov ax,[bx]
mov es:[0860h+si+bx],ax
mov al,71h
mov byte ptr es:[0861h+si+bx],al
inc bx
inc si
loop s2
ret
code ends
end start
```
以上程序将每个循环改写成了一个子程序,分别是print_string_attr_1、print_string_attr_2和print_string_attr_3。在主程序中调用这三个子程序即可完成字符串及属性值输出到80×25彩色字符模式显示缓冲区的操作。
阅读全文