执行“mov eax,[edx + ebx]”汇编(NASM)后,ebx寄存器的值发生变化

时间:2011-05-19 22:26:38

标签: assembly nasm

我是装配中的新手,我正在尝试在装配中做一些任意精度算术。但是我整天都陷入了错误。

    mov eax,[ebp+8] ; the first parameter of c function
    mov edx,[ebp+12] ; the second parameter of c function
    sub ecx,ecx
    sub ebx,ebx

    for_loop2:
    cmp ecx,[noktadanSonraFark] ; [noktadanSonraFark] is a variable that contains the difference of the lenghts of the two parameters 
    je end_for2

    mov ebx,[length2] ; the length of the second parameter "9"

    sub ebx,1 ; if length is 9 the last chacter will be on 8. index

    sub ebx,ecx

    mov eax, [edx+ebx] ; must show the character at the 8.index

        mov eax,ebx ; this 4 line returns thee value stored in eax to the 
        pop ebx  ; c function. and the result is printed
        pop ebp
        ret

    inc ecx
    jmp for_loop2

我的问题是屏幕上没有任何内容。但是,当我对此行mov eax, [edx+ebx]发表评论时,ebx值正确打印“8”因此,此行mov eax, [edx+ebx]似乎更改了ebx中的值或删除了它。因为屏幕上没有任何内容。有什么想法吗?

1 个答案:

答案 0 :(得分:4)

问题很可能是指令mov eax, [edx+ebx]正在尝试访问程序无权访问的内存地址。这导致程序崩溃。因此,没有输出。可以肯定的是,访问[edx+ebx]不会修改这两个寄存器中的任何一个。

你说如果你注释掉那一行,事情按预期工作,输出为“8”,这是ebx的值。你检查了edx的价值吗?