Questions tagged [relative-addressing]
49 questions
51
votes
2 answers
Why does the ARM PC register point to the instruction after the next one to be executed?
According to the ARM IC.
In ARM state, the value of the PC is the address of the current instruction plus 8 bytes.
In Thumb state:
For B, BL, CBNZ, and CBZ instructions, the value of the PC is the address of the current instruction plus 4…

newbie
- 1,230
- 1
- 12
- 21
35
votes
1 answer
How to use RIP Relative Addressing in a 64-bit assembly program?
How do I use RIP Relative Addressing in a Linux assembly program for the AMD64 archtitecture?
I am looking for a simple example (a Hello world program) that uses the AMD64 RIP relative adressing mode.
For example the following 64-bit assembly…

Erik
- 4,268
- 5
- 33
- 49
28
votes
1 answer
Understanding %rip register in intel assembly
Concerning the following small code, which was illustrated in another post about the size of structure and all the possibilities to align data correctly :
struct
{
char Data1;
short Data2;
int Data3;
char Data4;
} x;
unsigned fun ( void )
{
…
user1773603
17
votes
1 answer
How do RIP-relative variable references like "[RIP + _a]" in x86-64 GAS Intel-syntax work?
Consider the following variable reference in x64 Intel assembly, where the variable a is declared in the .data section:
mov eax, dword ptr [rip + _a]
I have trouble understanding how this variable reference works. Since a is a symbol corresponding…

Shuzheng
- 11,288
- 20
- 88
- 186
12
votes
2 answers
Why are global variables in x86-64 accessed relative to the instruction pointer?
I have tried to compile c code to assembly code using gcc -S -fasm foo.c.
The c code declare global variable and variable in the main function as shown below:
int y=6;
int main()
{
int x=4;
x=x+y;
return 0;
}
now I looked in…

roy cabouly
- 487
- 4
- 12
11
votes
2 answers
what does "mov offset(%rip), %rax" do?
Does rax get offset plus the address of this instruction, or the next? From a microcode point of view it might be easier if the answer was the next instruction.

Bing Bang
- 524
- 7
- 16
9
votes
1 answer
Why does this MOVSS instruction use RIP-relative addressing?
I found the following assembly code in disassembler (floating point logic c++).
842: movss 0x21a(%rip),%xmm0
I understand that when process rip will allways be 842 and this 0x21a(%rip) will be const. It seems a little odd to use this…

Vladimir Yanakiev
- 1,240
- 1
- 16
- 25
9
votes
1 answer
Why is the address of static variables relative to the Instruction Pointer?
I am following this tutorial about assembly.
According to the tutorial (which I also tried locally, and got similar results), the following source code:
int natural_generator()
{
int a = 1;
static int b = -1;
b += 1; …

Attilio
- 1,624
- 1
- 17
- 27
8
votes
1 answer
Generating %pc relative address of constant data
Is there a way to have gcc generate %pc relative addresses of constants? Even when the string appears in the text segment, arm-elf-gcc will generate a constant pointer to the data, load the address of the pointer via a %pc relative address and then…

Hudson
- 2,001
- 1
- 15
- 17
5
votes
2 answers
Understanding the ADR instruction in ARM, and adding an offset to that
I was looking at the assembler output of my code and need help with below instructions.
0x00000fe8: e28fc000 .... ADR r12,{pc}+8 ; 0xff0
0x00000fec: e28cca08 .... ADD r12,r12,#8, 20 ; #0x8000
From my…

MS.
- 881
- 2
- 9
- 23
4
votes
1 answer
Unable to move variables in .data to registers with Mac x86 Assembly
I have written a small piece of assembly with AT&T syntax and have currently declared three variables in the .data section. However, when I attempt to move any of those variables to a register, such as %eax, an error from gcc is raised. The code and…

Ajax1234
- 69,937
- 8
- 61
- 102
3
votes
3 answers
NASM x86_64 assembly in 32-bit mode: Why does this instruction produce RIP-Relative Addressing code?
[bits 32]
global _start
section .data
str_hello db "HelloWorld", 0xa
str_hello_length db $-str_hello
section .text
_start:
mov ebx, 1 ; stdout file descriptor
mov ecx, str_hello…

Mathmagician
- 179
- 1
- 8
3
votes
1 answer
Why do call and jump instruction use a displacement relative to the next instruction, not current?
In the table below extracted from Intel's docs we have for the opcodes E8 cw and E8 cd that the displacement is relative to the next instruction.
Why the next instruction? Why isn't the displacement relative to the call instruction itself?

Alexander
- 2,581
- 11
- 17
3
votes
1 answer
Can I choose RIP-relative or absolute addressing for different variables with gcc in x86-64
I write my own link script to put different variables in two different data sections (A & B).
A is linked to zero address;
B is linked near to code, and in high address space (higher than 4G, which is not available for normal absolute addressing in…

xingchong
- 31
- 3
2
votes
1 answer
How to assemble and link with ml64 in true 64-bit mode (with LARGEADDRESSAWARE)?
I am working on reworking an old masm program to true 64-bit x64 mode using Microsoft's ml64 and link on Windows 10. The linker gives an error in code that has a REX.W prefix.
The linker's /LARGEADDRESSAWARE option sounds like the right thing for…

Vikors
- 21
- 1