title: How do i write Simple inline asm instruction from C on Linux 64 bit?
body: <p>i am writing a simple c program and my requirement is to print RIP(Instruction Pointer) from some function of the program. i dont want to use ptrace.</p>
  
  <p>the one thing i tried with inline asm is:
  <strong>asm("movl %%rip, %0;" : "=r"(val) )</strong>
  this should copy my rip register value to variable val, but i am getting compilation error.</p>
  
  <p>if i use ebp/esp which are base pointer and stack pointers for 32 bit machine, i dont get any compilation error and my val has some hexadecimal number assigned.</p>
  
  <p>i have few questions here:</p>
  
  <p>1) as my machine is 63 bit, how was above instruction able to read 32 bit registers?</p>
  
  <p>2) why i am not able to read any register for 64 bit, is there any issue b'caz of <strong>'r'</strong>?</p>
  
  <p>3) when i use eip which is for 32 bit i get compilation error, does it mean IP registers are restricted for reading?</p>