last day (15 days later) » 

10:33 PM
0
A: Segfault on movq instruction?

Bradmovq 0x...., %rcx is trying to move a value from rcx into a memory location. If that memory isn't mapped into your process space, or isn't writeable, then you will get a segfault. So the question is - how did you come up with the magic number for the location? You need to get the location fr...

 
I was attempting to move an immediate into the rcx register. Based on disassembly of code generated by the C compiler, that was the instruction.
 
flip it the other way. movq's destination is on the left.
 
As to why the loop is empty, I am trying to measure the overhead of the loop itself, and gcc removes empty loops which is why I wrote asm.
 
@merlin2011 - that makes sense. You just have the movq operands backwards.
 
Reversing the arguments also results in a segfault on that line. I just tried it.
Also, since I am compiling with gcc, I was pretty sure the argument order is src, dest since it uses AT&T syntax.
 
10:33 PM
keep in mind too that your OS might interrupt the loop - so your timing could be subject to jitter and overhead from that. Depending on quantum time for the OS thread scheduler and processor speed.
 
Hi Brad, I found the answer when double-checking the syntax, so your comment was definitely useful.
 
Great. I had to do some searching but had not found the answer for a 64-bit operand yet.
 
And you're right, I did consider the OS interrupt, but I expect that the delta between the loop with the op that I am timing and without should both be subject to OS interrupt.
 
What did you come up with?
 
I needed a $ before the immediate.
without the $, I'm not sure how the immediate is interpretted.
Perhaps it is interpreted as a memory location.
as you said in your answer.
Which might explain why it segfaulted.
 
10:36 PM
Yes I think it's a memory location. Check that the register is being set right. I found some articles that suggest it might get truncated to 32-bit with an immediate.
Can't test it right now I'm afraid.
Glad I could help.
 
Thanks for the assist!
 

last day (15 days later) »