eip in 32-bit mode,, and rip in 64-bit mode


GNU

(gdb) info registers
rax            0xfffffffffffffdfc	-516
rbx            0x5dc	1500
rcx            0xffffffffffffffff	-1
rdx            0x5dc	1500
rsi            0x1	1
rdi            0x7fff09cf5780	140733357971328
rbp            0x2051160	0x2051160
rsp            0x7fff09cf5730	0x7fff09cf5730
r8             0x0	0
r9             0xffffffff	4294967295
r10            0x8	8
r11            0x246	582
r12            0x7fff09cf5780	140733357971328
r13            0x7fff09cf5790	140733357971344
r14            0x0	0
r15            0x1	1
rip            0x7f2e947000c8	0x7f2e947000c8
eflags         0x246	[ PF ZF IF ]
cs             0x33	51
ss             0x2b	43
ds             0x0	0
es             0x0	0
fs             0x0	0
gs             0x0	0
(gdb)

rip 0x7f2e947000c8 0x7f2e947000c8

The RIP register is the instruction pointer register. In 64-bit mode, the
 RIP register is extended to 64 bits to support 64-bit offsets. In 32-bit
 x86 architecture, the instruction pointer register is the EIP register.

source:
http://developers.sun.com/solaris/articles/x64_dbx.html

Related Discussion

Hi...I'm teaching myself some AMD 64 bit assembler programing and I'm
curious about RIP relative addressing. The docs that I've read state
 "You are recommended to use RIP relative addressing whenever possible
 to reduce code size" now my question is, is this the code size reduction
 they are talking about


Code:
example code 1 RIP-relative addressing

.section .data
	mydata: .long 0

.section .bss

.section .text
	.global _start
_start:
			movq	$64, mydata(%rdi)
Code:
example code 2
.section .data
	mydata: .long 0

.section .bss

.section .text
	.global _start
_start:
			movq	$64, mydata
and the results

Code:
example 1 RIP-relative addressing
code1:     file format elf64-x86-64


Disassembly of section .text:

00000000004000b0 :
  4000b0:	48 c7 87 bc 00 60 00 	movq   $0x40,0x6000bc(%rdi)
  4000b7:	40 00 00 00
Code:
example 2
code2:     file format elf64-x86-64


Disassembly of section .text:

00000000004000b0 :
  4000b0:	48 c7 04 25 bc 00 60 	movq   $0x40,0x6000bc
  4000b7:	00 40 00 00 00
are we talking about a one byte reduction in code size every time I use RIP relative addressing?

source :
http://www.linuxforums.org/forum/linux-programming-scripting/131795-amd-64-bit-rip-relative-addressing.html

Variation

How RIP/EIP relative addressing works in 32-bit mode

In 32-bit programs you can't do this :

mov al, [eip]

But you will have to do something like this instead :
call $ + 5
pop ebx
add ebx, 1 + 1 + 1 + 1 ; POP + ADD + ModRM + imm8
mov al, [ebx] ; EBX is now pointing to this instruction!



How RIP/EIP relative addressing works in 64-bit mode

In 64-bit programs you are allowed to write this :
mov al, [rip]

source :
http://www.codegurus.be/codegurus/Programming/riprelativeaddressing_en.htm