Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Assembly 我的循环没有像我期望的那样执行_Assembly_X86_Strcat - Fatal编程技术网

Assembly 我的循环没有像我期望的那样执行

Assembly 我的循环没有像我期望的那样执行,assembly,x86,strcat,Assembly,X86,Strcat,我正在运行一个调用外部汇编函数的C程序。出于学术目的,我正在尝试执行strcat。我将这两个字符串作为char*参数传递给我的汇编程序。我将ebp推送到堆栈,并将string1和string2分配给edx和ebx,如下所示: mov edx, [ebp+8] mov ebx, [ebp+4] 现在,其余内容如下: procStr1: cmp BYTE PTR [edx], 0 jne readStr1 procStr2: cmp BYTE PTR [ebx], 0

我正在运行一个调用外部汇编函数的C程序。出于学术目的,我正在尝试执行strcat。我将这两个字符串作为char*参数传递给我的汇编程序。我将ebp推送到堆栈,并将string1和string2分配给edx和ebx,如下所示:

mov edx, [ebp+8]
mov ebx, [ebp+4]
现在,其余内容如下:

procStr1:
     cmp BYTE PTR [edx], 0
     jne readStr1
procStr2:
     cmp BYTE PTR [ebx], 0
     jne readStr2
     jmp bottom
readStr1:
    inc edx
    jmp procStr1
readStr2:
    mov BYTE PTR [edx], 'a'
    inc edx
    inc ebx
    jmp procStr2

bottom:
    inc edx
    mov BYTE PTR [edx], 0
    pop ebx
    pop edx
    pop ebp
    ret
我只是通过在string1的末尾添加a来测试它是否有效。如果我输入'hi'和'bye',我希望通过C程序打印hiaaa(通过打印string1)。相反,无论string2有多大,我通常在string1之后得到13 a。如果您有任何意见,我将不胜感激。这真的让我难以置信。

您是否做了以下工作:

push ebp
mov ebp, esp
在顶端

如果是,您的参数现在位于:

mov edx, [ebp+8]
mov ebx, [ebp+Ch]  ; 0xC, not 4 -- C-language passes args right-to-left
而且


+1数据处理看起来很好(除了
inc edx
),所以我怀疑这只是从正确的位置获取指针的问题。我不太明白,在Visual Studio中编译时执行[ebp+C]时,我遇到了语法错误。从右到左,你的意思是第二个参数首先被推到堆栈上吗?我编辑了post-C是十六进制的,所以要么使用12(十六进制C的值),要么附加一个h。这个想法是正确的,只是语法错误。至于从右到左,是的,我的意思是第二个参数被推到第一个参数之前。这就是C调用约定,它允许可变数量的参数。耶!我很高兴。欢迎来到了解机器工作原理的奇妙世界。:)
bottom:
    inc edx       ; This inc should be removed -- edx already points one
                  ; byte beyond the ultimate copied byte.
    mov BYTE PTR [edx], 0