Results 1 to 2 of 2
I have a simple question about relative addressing and it is, how does relative addressing work with pointers?
I understand how it works with values, how it calculates the distance ...
- 09-12-2009 #1
Intel/AMD 64 bit Relative Addressing %rip question
I have a simple question about relative addressing and it is, how does relative addressing work with pointers?
I understand how it works with values, how it calculates the distance from the next %rip value and uses this as an offset to get the value – see code below:
This example (above) will use the instruction pointer and a offset to calculate the address of the variable – and from this get the variable value and add it to the value of %rax...simpleCode:.section .text myint1: .quad 12 myint2: .quad 45 .global myfunc myfunc: pushq %rbp movq %rsp, %rbp xorq %rax, %rax addq myint1(%rip), %rax addq myint2(%rip), %rax movq %rbp, %rsp popq %rbp ret
Now if I write a program that has to retrieve the pointer of a value I have to do certain tricks to get the address – see code below
Is this the proper method of retrieving the address of a value when you have relative addressing at your disposal?(The above code just displays the message “this is the message to display!\n”)..Code:.section .text mydata: .ascii "this is the message to display!\n" .equ mylen, . - mydata .global myfunc myfunc: call tohere tohere: popq %rsi .equ myoff, . - mydata addq $-myoff + 0x1, %rsi pushq %rbp movq %rsp, %rbp movq $1, %rax movq $1, %rdi movq $mylen, %rdx syscall movq %rbp, %rsp popq %rbp ret
Any responses will be appreciated...Yes its the proper way...No its not...Gerard4143Make mine Arch Linux
- 09-12-2009 #2
Found my own answer..use leaq with relative addressing to retrieve a pointer value....G4143
Code:.section .text mydata: .ascii "this is the message to display!\n" .equ mylen, . - mydata .global myfunc myfunc: pushq %rbp movq %rsp, %rbp movq $1, %rax movq $1, %rdi leaq mydata(%rip), %rsi /*retrieve the pointer for mydata*/ movq $mylen, %rdx syscall movq %rbp, %rsp popq %rbp ret
Make mine Arch Linux


Reply With Quote