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

发布于 2024-11-08 17:25:36 字数 952 浏览 1 评论 0原文

我是汇编新手,我正在尝试在汇编中进行一些任意精度的算术。但我一整天都陷入错误中。

    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 中的值或将其删除。因为屏幕上没有打印任何内容。有什么想法吗?

I am new in assembly and I am trying to do some arbitrary precision arithmethic in assembly. But I am stuck in an error for a whole day.

    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

My problem is that nothing is printed to the screen. But when I comment this line mov eax, [edx+ebx]the ebx value is printed correctly "8" So it seems that this line mov eax, [edx+ebx] changes the value in ebx or deletes it. Because nothing is printed to the screen. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

温馨耳语 2024-11-15 17:25:36

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

您说,如果您注释掉该行,一切都会按预期工作,并且输出为“8”,这是 ebx 的值。您检查过 edx 的值吗?

Most likely the problem is that the instruction mov eax, [edx+ebx] is trying to access a memory address that your program doesn't have permission to access. That causes the program to crash. Thus, no output. It's certain that accessing [edx+ebx] does not modify either of those two registers.

You say that if you comment out that line, things work as expected and the output is "8", which is the value of ebx. Have you checked the value of edx?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文