请帮我用子程序完成这个代码的作用
时间: 2024-02-29 08:52:44 浏览: 33
好的,下面是使用子程序实现的代码:
```
assume cs:code, ds:data, ss:stack
data segment
message db 'welcome to masm!'
colors db 00000010B,00100100B,01110001B
data ends
stack segment
db 128 dup(0)
stack ends
code segment
start:
mov ax, data
mov ds, ax
mov ax, stack
mov ss, ax
mov sp, 128
mov ah, 0
mov al, colors[0]
mov cx, 16
mov si, offset message
call print_string
mov ah, 1
mov al, colors[1]
mov cx, 3
mov si, offset colors
call print_string
mov ah, 0
mov al, colors[2]
mov cx, 16
mov si, offset message
call print_string
mov ah, 0
mov al, 0
mov bx, 0
int 16h
mov ax, 4c00h
int 21h
print_string proc
push ax
push bx
push cx
push dx
push si
push di
mov bx, 160*10+30*2
mov di, bx
mov dx, 0B800h
mov es, dx
mov dh, al
mov al, ' '
mov cx, 80
rep stosw
mov bx, 160*10+30*2
mov di, bx
mov dx, 0B800h
mov es, dx
mov dh, ah
mov cx, bx
add di, cx
mov cx, 16
rep movsb
pop di
pop si
pop dx
pop cx
pop bx
pop ax
ret
print_string endp
code ends
end start
```
这个代码使用了一个名为`print_string`的子程序,它的作用是打印一个字符串,并且可以指定颜色。在主程序中,我们先使用`call`指令调用这个子程序,然后传递不同的参数来打印不同的字符串和颜色。具体实现过程可以看代码注释。
相关推荐
![ppt](https://img-home.csdnimg.cn/images/20210720083527.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)