StringCopyEx 函数

StringCopyEx 函数将以零结尾的字符串内容复制到预备缓冲区中。指针通过栈传递。函数会自动将栈对齐 4 个字节。

参数(栈): 1. 源字符串的指针。2. 目标缓冲区的指针。

返回值: 函数不返回值。

标志状态: 函数不改变标志状态。

程序源代码

Intel 8086 汇编程序示例,演示使用 StringCopyEx 函数将字符串复制到缓冲区。地址通过栈传递。

title Author: Dovgopolov Evgeny Sergeevich

.286C
.model small
.stack 100h

data segment public
    string db "Hello, World 8086 Assembler!\0"
    buffer db ($-string) - 1 dup(0)
    fmtout db "Copied string: %s\0"
data ends

code segment public
    assume  ds:data, cs:code
    include Handyfar.inc           ; 包含函数文件
    include Handymac.inc           ; 包含宏文件

    main proc
        call    SetDataSegment     ; 调用过程 SetDataSegment

        pushs   es:[buffer]        ; 第2步:将变量 buffer 的地址压入栈顶
        pushs   ds:[string]        ; 第1步:将变量 string 的地址压入栈顶
        call    StringCopyEx       ; 调用过程 StringCopyEx(string, buffer)

        pushs   ds:[buffer]        ; 第2步:将变量 buffer 的地址压入栈顶
        leaax   ds:[fmtout]        ; 第1步:将格式字符串 fmtout 的地址装入寄存器 ds:ax
        call    PrintFormatString  ; 调用过程 PrintFormatString(ax:fmtout, buffer)
        add     sp, 2              ; 对齐栈

        push    0                  ; 将字节值(返回代码)压入栈顶
        call    ExitProcessEx      ; 调用过程 ExitProcessEx(0)
    main endp

code ends
end main

Copied string: Hello, World 8086 Assembler!

示例取自教材 "HANDYFAR - MASM (Dovgopolov Evgeny Sergeevich)".