【问题标题】:Concatenate String in MASMMASM 中的连接字符串
【发布时间】:2014-02-06 22:02:08
【问题描述】:

我一直在尝试在 MASM 中连接一个字符串,但遇到了一些困难。首先,此时我的输出是一个带有树状字符的 0,但我认为我的 WriteString(来自 Irvine 库)可能没有被正确使用。 WriteString 是从 edx 还是 eax 写的? 我还知道,在使用字符串时,我需要使用指向第一个字符地址的指针,而不是整个字符串;这就是我试图用缓冲区和 OFFSET 指针做的事情,但我不确定这是否完全正确。我也不确定 push 和 pop 是否必要,如果是,它到底做了什么。 请帮忙!提前非常感谢。

这是我写的代码:

TITLE Str_Concat        (WA5.asm)

; Program Description: This program concatenates a source string to a target string.
; Author: 
; Date Created: 2/6/2013


INCLUDE C:\IrvineExamplesVS2010a\Irvine32.inc

.data
    source BYTE "Rocks",0
    target BYTE "Zachary",0
    buffer BYTE 24 DUP (0)

.code
main PROC
    push ds    
    pop es

    mov esi, OFFSET source
    mov edi, OFFSET target
    cld                         ;direction = forward
    mov cx, LENGTHOF source
    rep movsb

    call WriteString
    call crlf


        exit        ; exit to operating system
main ENDP

END main

【问题讨论】:

    标签: assembly masm irvine32


    【解决方案1】:

    Irvine 在他的书中解释了他的大部分程序。他的图书馆的源代码也可以从他的网站下载。在源代码中,他留下了一些关于 procs 将什么作为参数、在什么寄存器中以及他的每个 procs 返回什么的信息。这是来自WriteString的描述:

    WriteString PROC
    ;
    ; Writes a null-terminated string to standard
    ; output. Input parameter: EDX points to the
    ; string.
    ; Last update: 9/7/01
    ;--------------------------------------------------------
    

    那么,读完之后,您会将target 的地址放在哪个寄存器中?您不能“按原样”使用edi,因为edi 中的原始地址已增加rep movsb

    附带说明,您不是连接字符串,而是用source 中的字符串覆盖target 中的字符串。您定义了buffer,但从不使用它。 buffer 是把两个字符串连在一起吗?如果是这样,您需要将target 复制到buffer,然后将source 复制到buffer。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-03-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-31
      • 2017-04-24
      相关资源
      最近更新 更多