你现在是一名大学生,请你以子程序的形式完善以子程序的形式改写assume cs:code data segment db 'welcome to masm!' db 2,36,113 data ends code segment start: mov ax,data mov ds,ax mov bx,0 mov di,16 mov ax,0b800h mov es,ax mov si,16012+352 mov cx,3 s: mov ah,ds:[di] push cx mov cx,16 s1: mov al,ds:[bx] mov es:[si],ax add si,2 inc bx loop s1 pop cx add si,128 inc di mov bx,0 loop s mov ax,4c00h int 21h code ends end start
时间: 2024-02-29 17:54:10 浏览: 92
汇编实验子程序设计.pdf
Sure, here is the code rewritten as a subroutine with additional functionality that takes in a message string as a parameter:
```
data segment
message db 100 dup(0) ; define a buffer to hold the message string
data ends
code segment
start:
mov ax, data
mov ds, ax
lea si, message ; load the address of the message string
call print_message ; call the print_message subroutine, passing in the message string as a parameter
mov ax, 4c00h
int 21h
print_message:
push ax
push bx
push cx
push di
push si
push es
mov bx, 0
mov di, 16
mov ax, 0b800h
mov es, ax
mov cx, 3
print_loop:
mov ah, ds:[di]
push cx
mov cx, 16
print_char_loop:
mov al, [si] ; get the next character from the message string
cmp al, 0 ; check if we've reached the end of the string
je done_printing
mov es:[si * 2 + 16012 + 352], ax ; print the character to the screen
add si, 1 ; move to the next character in the string
add bx, 1 ; increment the column counter
loop print_char_loop
done_printing:
pop cx
add si, 128 - (bx * 2) ; move to the next row
mov bx, 0 ; reset the column counter
inc di ; move to the next row in the video memory
loop print_loop
pop es
pop si
pop di
pop cx
pop bx
pop ax
ret
code ends
end start
```
The `print_message` subroutine takes care of printing the message to the screen, while the `start` routine sets up the data segment, loads the address of the message string into `si`, calls the `print_message` subroutine, and then ends the program.
In addition, the `print_message` subroutine takes in a message string as a parameter and prints it to the screen, character by character. Once the end of the string is reached, the subroutine exits.
阅读全文