问题
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 double
s 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