在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串 'welcome to masm!'用ret 方法编写
时间: 2024-02-26 19:59:35 浏览: 24
好的,以下是使用ret方法编写的代码:
```assembly
.model small
.stack 100h
.data
msg1 db 'welcome to masm!',0ah,0dh,'$'
msg2 db 'welcome to masm!',0ah,0dh,'$'
msg3 db 'welcome to masm!',0ah,0dh,'$'
.code
main proc
mov ah, 9
lea dx, msg1
int 21h ; 显示绿色字符串
ret ; 返回到调用程序
mov ah, 9
lea dx, msg2
int 21h ; 显示绿底红色字符串
ret ; 返回到调用程序
mov ah, 9
lea dx, msg3
int 21h ; 显示白底蓝色字符串
ret ; 返回到调用程序
main endp
end main
```
请注意,上述代码只会显示第一个字符串 "welcome to masm!",因为在每个字符串的后面都有一个 ret 指令,它会导致程序直接返回到调用它的程序,从而跳过后面的字符串。如果要显示所有三个字符串,可以将 ret 指令删除。
相关问题
在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串 'welcome to masm!'... 用子程序方法编写
以下是使用MASM汇编语言编写的程序,使用子程序的方法,在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串 'welcome to masm!':
```
.model small
.stack 100h
.data
msg1 db 'welcome to masm!', 0
msg2 db 'welcome to masm!', 0
msg3 db 'welcome to masm!', 0
.code
main proc
mov ax, @data
mov ds, ax
; 显示绿色字符串
call set_green
mov ah, 09h
lea dx, msg1
int 21h
; 显示绿底红色字符串
call set_green_background
mov ah, 09h
lea dx, msg2
int 21h
; 显示白底蓝色字符串
call set_white_background
mov ah, 09h
lea dx, msg3
int 21h
mov ah, 4ch
int 21h
main endp
; 设置绿色
set_green proc
push ax
push bx
push cx
push dx
mov ah, 06h
mov al, 0
mov bh, 0
mov bl, 0x02
mov cx, 80
mov dx, 12
int 10h
pop dx
pop cx
pop bx
pop ax
ret
set_green endp
; 设置绿底红色
set_green_background proc
push ax
push bx
push cx
push dx
mov ah, 06h
mov al, 0
mov bh, 0
mov bl, 0x42
mov cx, 80
mov dx, 13
int 10h
pop dx
pop cx
pop bx
pop ax
ret
set_green_background endp
; 设置白底蓝色
set_white_background proc
push ax
push bx
push cx
push dx
mov ah, 06h
mov al, 0
mov bh, 0
mov bl, 0x17
mov cx, 80
mov dx, 14
int 10h
pop dx
pop cx
pop bx
pop ax
ret
set_white_background endp
end main
```
该程序使用了子程序的方法来设置屏幕属性,分别定义了三个子程序set_green、set_green_background和set_white_background,用来设置绿色、绿底红色、白底蓝色。然后在主程序中,依次调用这三个子程序,并使用INT 21h中断来显示字符串。在屏幕的第12行显示绿色字符串,在第13行显示绿底红色字符串,在第14行显示白底蓝色字符串。
用简单的子程序编写在屏幕中间分别显示绿色、绿底红色、白底蓝色的字符串 'welcome to masm!'
好的,以下是使用简单的子程序编写的代码:
```assembly
.model small
.stack 100h
.data
msg1 db 'welcome to masm!',0ah,0dh,'$'
msg2 db 'welcome to masm!',0ah,0dh,'$'
msg3 db 'welcome to masm!',0ah,0dh,'$'
.code
main proc
call green_msg ; 显示绿色字符串
call green_red_msg ; 显示绿底红色字符串
call white_blue_msg ; 显示白底蓝色字符串
mov ah, 4ch
int 21h ; 退出程序
main endp
green_msg proc
mov ah, 2
mov dl, 2 ; 绿色
lea dx, msg1
int 21h ; 显示字符串
ret ; 返回到调用程序
green_msg endp
green_red_msg proc
mov ah, 2
mov dl, 2 ; 绿色
mov ah, 1
mov cl, 4 ; 绿底红色
lea dx, msg2
int 21h ; 显示字符串
ret ; 返回到调用程序
green_red_msg endp
white_blue_msg proc
mov ah, 2
mov dl, 1 ; 蓝色
mov ah, 9
mov cl, 7 ; 白色底纹
lea dx, msg3
int 21h ; 显示字符串
ret ; 返回到调用程序
white_blue_msg endp
end main
```
上述代码定义了三个子程序 `green_msg`、`green_red_msg` 和 `white_blue_msg`,分别用于显示绿色、绿底红色和白底蓝色的字符串。在 `main` 程序中,我们通过调用这三个子程序来显示所有三个字符串。