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
时间: 2024-02-14 10:07:00 浏览: 33
这段代码是用 MASM 语言编写的,主要功能是在屏幕上输出三行不同的字符串,并且每行字符串的颜色不同。其中,data segment 定义了一个字符串数组,里面存放了欢迎语和三个不同的颜色,code segment 定义了三个函数,分别用于输出三个不同颜色的字符串。程序的入口点是 start 标签,程序最后通过 int 21h 中断退出。
相关问题
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 改成子程序形式
下面是将代码改写成子程序形式的程序:
```
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彩色字符模式显示缓冲区的操作。
CODE SEGMENT ASSUME CS:CODE MAIN PROC FAR MOV AX,DATA MOV DS,AX
这段代码是一个汇编语言程序的开始部分,用于设置代码段和数据段的寻址方式。其中的指令含义如下:
- `CODE SEGMENT`:定义代码段,代码段中包含程序的指令。
- `ASSUME CS:CODE`:将代码段的起始地址赋值给代码段寄存器 CS,以便程序能够正确地访问代码段中的指令。
- `MAIN PROC FAR`:定义一个过程(Procedure),过程名为 MAIN,使用 FAR 关键字表示该过程是一个远调用过程,可以从其他程序中调用该过程。
- `MOV AX,DATA`:将数据段的起始地址(在汇编语言中通常被称为 DS)存储在 AX 寄存器中。
- `MOV DS,AX`:将 AX 寄存器中的数据段起始地址赋值给数据段寄存器 DS,以便程序能够正确地访问数据段中的数据。
这段代码的作用是设置程序的代码段和数据段,并将数据段的起始地址存储在 AX 寄存器中,然后将其赋值给数据段寄存器 DS。这样程序就能够正确地访问数据段中的数据。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![text/plain](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://img-home.csdnimg.cn/images/20210720083646.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)