gpt4 book ai didi

assembly - 气体 : jmp to label results in wrong jump?

转载 作者:行者123 更新时间:2023-12-01 08:48:45 26 4
gpt4 key购买 nike

我正在尝试组装以下程序:

    .text
.globl _search2
_search2:
pushq %rbp
movq %rsp, %rbp
movq %rax, -8(%rbp)
go_again:
cmpl $0x90909090, (%rax)
je go_out
addq $0x8, %rax
jmp go_again
go_out:
leave
ret

通过这样做:“gcc -o test test.s main.c”,我得到了这个:

otool -v -t 测试

_search2:
0000000100000d0c pushq %rbp
0000000100000d0d movq %rsp,%rbp
0000000100000d10 movq %rax,0xf8(%rbp)
go_again:
0000000100000d14 cmpl $0x90909090,(%rax)
0000000100000d1a je 0x100000d29
0000000100000d20 addq $0x08,%rax
0000000100000d24 jmp 0x200000d14
go_out:
0000000100000d29 leave
0000000100000d2a ret

jmp 试图跳转到地址 0x200000d14,这是完全错误的,而不是标有 go_out 标签的 0x100000d29。

请帮忙。

最佳答案

试试 objdump -D test > test.list

00000000004004c4 <_search2>:
4004c4: 55 push %rbp
4004c5: 48 89 e5 mov %rsp,%rbp
4004c8: 48 89 45 f8 mov %rax,-0x8(%rbp)

00000000004004cc <go_again>:
4004cc: 81 38 90 90 90 90 cmpl $0x90909090,(%rax)
4004d2: 74 06 je 4004da <go_out>
4004d4: 48 83 c0 08 add $0x8,%rax
4004d8: eb f2 jmp 4004cc <go_again>

00000000004004da <go_out>:
4004da: c9 leaveq
4004db: c3 retq

查看您使用的工具是否可以显示指令,如果指令(有些)相同则相对地址是正确的,您可以忽略工具显示的地址,或者干脆不使用该工具。

如果分支是直接的并且与目标不匹配,则存在 gcc/gnu 工具问题。

关于assembly - 气体 : jmp to label results in wrong jump?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6890393/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com