How is $example different from example(%rip)?

纵然是瞬间 提交于 2019-12-20 06:49:09

问题


I've spent 2 hours googling, but to no avail --- there are not many beginner-level guides for assembly, and the course I am taking right now dos not do a very good job at explaining some stuff.

Anyway; I've been trying to work with SSE and tried comparing two doubles using comisd instruction. I've spent a lot of time to understand how to hard-code a non-integer constant (let's call it example, it is declared as

example:
    .long   3794832442
    .long   1044740494

); but after I've done that, I couldn't get it to work --- "operand type mismatch". I've turned to C-to-assembly translator and found out that instead of my comisd $example, %xmm0 it used comisd example(%rip), %xmm0, and it turned out to work. Now I don't understand, how does it work and how are these different?


回答1:


$example is simply the absolute address of that variable - it doesn't mean a memory access.

You get the "operand type mismatch" because comisd does not support an immediate operand. comisd example, %xmm0 (without the $) would have worked, as that is a memory reference.

example(%rip) is using the PC-relative addressing mode introduced in x86-64, which makes the code position-independent because instead of using an absolute address, it uses an offset from the current instruction pointer.


Based on an answer of Jonathon Reinhart.



来源:https://stackoverflow.com/questions/42137189/how-is-example-different-from-examplerip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!