I should probably state explicitly that that code will actually return the address of the POP instruction rather than the CALL in case that is a problem. Alternatively, you can just:
Code: Select all
__asm__ volatile ("1: movl $1b, %0" : "=r" (reg_eip));
Note that neither this code example or your NASM example are actually reading EIP, they are simply storing the location provided by the linker, so:
Code: Select all
mov eax, $
;Will be assembled into machine code as
mov eax, 400034h
If the code is Position Independant and you want to find where you are then the CALL; POP will be better.