Questions tagged [relative-addressing]
49 questions
1
vote
1 answer
absolute and relative addressing in gcc inline assembly
I am not able to understand the concept of absolute addressing and relative addressing in assembly particularly in gcc inline assembly. I saw the following code in a tutorial :
asm volatile(" \
cli; \
mov %0,…

vjain27
- 3,514
- 9
- 41
- 60
0
votes
0 answers
Variable Memory addressing
Using NASM
I have:
VAR DW 0000
memptr: times 1024 DB 0H
I want to use VAR as a pointer into the block of memory memptr
How do I load VAR with the address of memptr + 1023 ?
MOV [VAR] , EAX ; Correct me here, this moves the content of EAX into the…

FJRusso
- 1
- 1
0
votes
0 answers
Finding all relative addresses in assembly
After I compile my own program, I want to filter out all relative addresses in the output file. I have already disassembled the output file into readable assembly code, but I'm rather new to assembly and have considered two ways of obtaining the…
0
votes
0 answers
Why does lea instruction load address that is different from the source address to destination?
In the below example I expect that the value of rax should be equal to 0x555555555ffd. But after I execute the instruction the rax shows the address of 0x555555556004. How lea instruction calculates the loaded address?
(gdb) disassemble…

lambdavary
- 1
- 1
0
votes
1 answer
Deciphering RIP-relative LEA instructions as part of a switch statement
What is the compiler doing in the beginning of the switch statement (snippet section below) to come up with the address in %rax so it can notrack jmpq *%rax to the correct offset ?
Are the constants 0xe07 and 0xdfb padding ?
lea 0xe07(%rip),%rax…

Lydon Ch
- 8,637
- 20
- 79
- 132
0
votes
0 answers
RIP-relative addressing on x86
I'm not really experienced with x86 assembler and try to debug a problem related to a bug in mach_inject.
The original code looks like this (function mach_inject in mach_inject.c):
#if defined(__x86_64__)
imageOffset = 0; // RIP-relative…

Albert
- 65,406
- 61
- 242
- 386
0
votes
0 answers
How to do relative addressing in GAS syntax
So I'm trying to write a function to zero out an input buffer in static memory in my assembly program. It looks like this:
zero_input_buffer:
mov $0, %ebx
mov $29, %eax
# not sure how to implement this line
mov %ebx, input(%rip,…

Dyskord
- 365
- 5
- 14
0
votes
0 answers
Question about relocation entries in assembly code
I write 2 C programs : main.c and sum.c.
Here is main.c :
int array[2] = {1, 2};
int main() {
int val = sum(array, 2);
return val;
}
Here is sum.c :
int sum(int* a, int n) {
int i, s = 0;
for (i = 0; i < n; i++) {
s +=…

dubugger
- 89
- 6
0
votes
3 answers
Understanding Cortex-M assembly LDR with pc offset
I'm looking at the disassembly code for this piece of C code:
#define GPIO_PORTF_DATA_R (*((volatile unsigned long *)0x400253FC))
int main(void){
// Initialization code
while(1) {
SW1 = GPIO_PORTF_DATA_R&0x10; // Read PF4…

Nicholas Humphrey
- 1,220
- 1
- 16
- 33
0
votes
1 answer
Forcing RIP-relative addressing?
Is there any way to force a compiler or an assembler to only generate RIP-relative addressing code?
I am trying to find a way to provide a mapping from conventional programming models to a Turing complete abstract model of computation.

polcott
- 143
- 1
- 13
0
votes
0 answers
When and How is %rip-relative addressing resolved?
Take the following assembly program:
_start:
mov myvar, %rax
mov myvar(%rip), %rax
mov myvar(%rip), %rax
mov myvar(%rip), %rax
mov myvar(%rip), %rax
The produces the following when run in gdb:
!0x00000000004000b0 ? mov …

carl.hiass
- 1,526
- 1
- 6
- 26
0
votes
1 answer
Using variables to define variable names
I am sure that there is a very simple answer and I am perhaps just being forgetful, but I cannot remember how to use a variable to define the name of another variable. I cannot even think of a name of this process to search for existing answers.
I…

Phil Busby
- 33
- 5
0
votes
1 answer
Addressing this in static classes instances on x86 32-bit
If I define static instance of a class, is there optimization in compilers (particularly g++/clang) to omit base register (for thiscalls) when data members accessed directly or indirectly (I mean [base + index * scale + displacement] formula) and…

Tomilov Anatoliy
- 15,657
- 10
- 64
- 169
0
votes
2 answers
C++, does absolute address of an object always remain constant until released?
Object1 * test= new Object1();
does "test" have absolute address on RAM or an absolute address in a virtual memory which has a relative starting point to RAM's zero adress?
An example could be, in a very fragmented memory I started many…

huseyin tugrul buyukisik
- 11,469
- 4
- 45
- 97
0
votes
1 answer
PC-relative addressing on an assembly-like language compiler
I'm currently writing a compiler for a custom asm-like programming language
and I'm really confused on how to do proper PC-relative addressing for data labels.
main LDA RA hello
IPT #32
HLT
hello .STR "Hello, world!"
The…

William Fernandes
- 239
- 2
- 14