gpt4 book ai didi

assembly - x86 32 位汇编问题

转载 作者:行者123 更新时间:2023-12-02 22:09:01 26 4
gpt4 key购买 nike

我目前正在学习汇编,并且正在研究 if 语句。我当前的代码如下。

write:
mov eax, 0x4
sub esp, 4
int 0x80

main:
; The message has already been pushed to the stack
mov eax, 4
inc eax
cmp eax, 5
je write

如果我将 ret 放在 write: 末尾,则会收到总线错误 10,如果不这样做,则会出现无限循环,从而导致段错误。我应该怎么做才能使这项工作成功?

最佳答案

使用call指令而不是je进入writeret 期望返回地址位于堆栈上,但如果您使用跳转到达那里,则不会将其推送!您还必须将 esp 恢复为输入该函数时的状态。以下是基于您的代码的最佳猜测示例:

write:
mov eax, 0x4
sub esp, 4
int 0x80
add esp, 4
ret

main: ; The message has already been pushed to the stack
mov eax, 4
inc eax
cmp eax, 5
jne dontwrite ; skip calling 'write' if eax != 5
call write
dontwrite:
; the rest of the program goes here

关于assembly - x86 32 位汇编问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7210804/

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