Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[翻译] x86 汇编的基础介绍 - Luyu Huang's Tech Blog #60

Open
luyuhuang opened this issue Jan 18, 2022 · 3 comments
Open

[翻译] x86 汇编的基础介绍 - Luyu Huang's Tech Blog #60

luyuhuang opened this issue Jan 18, 2022 · 3 comments

Comments

@luyuhuang
Copy link
Owner

https://luyuhuang.tech/2022/01/18/x86-assembly.html

原文 A fundamental introduction to x86 assembly programming0. 介绍x86 指令集架构是近 20 年来我们家庭电脑和服务器所使用的 CPU 的核心. 能够阅读和编写低级汇编语言是一项很强大的技能, 这能够让你写出更高效的代码, 使用 C 语言中无法使用的机器...

@jiang131072
Copy link

基本算数指令错的离谱。目标应该是第一参数。
参见:https://learn.microsoft.com/en-us/windows-hardware/drivers/debugger/x86-instructions#arithmetic

@luyuhuang
Copy link
Owner Author

@AmazonXYZ
基本算数指令错的离谱。目标应该是第一参数。

语法不一样吧. 这里介绍的是 AT&T 的语法, 目标确实是第二参数. 如果是 Intel 的语法, 目标就是第一参数.

int a;
void foo() {
    a += 42;
}

gcc -S -masm=att -O2 t.c 编译成

foo():
        addl    $42, a(%rip)
        ret

gcc -S -masm=intel -O2 t.c 则编译成

foo():
        add     DWORD PTR a[rip], 42
        ret

@jiang131072
Copy link

🙏抱歉没有看到,确实是syntax的问题

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants