0

I am wondering how to move an address forward a set amount of bytes in Intel x86-64

Say i have the string "string" and i want to move it forward 3 bytes, i want it to print "ing" using some pointer arithmetic to move it up

i have tried

mov rax, 1
mov rdi, 1
mov rsi, [string+3]
mov rdx, 3
syscall

to sys_write the string moved forward three places, and in this example change the length to 3 because that's how many will be left, however it is not working appropriately.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847

1 Answers1

3

You want the address of the 4th byte, not a qword load from that position.

lea rsi, [string+3] Or better, use a RIP-relative addressing mode. If this is NASM, use
lea rsi, [rel string+3], or GAS .intel_syntax noprefix lea rsi, [RIP + string+3]

Or in position-dependent code on Linux, (NASM) mov esi, string+3 or (GAS) mov esi, OFFSET string+3 to get the absolute address string+3 as a 32-bit immediate.

See How to load address of function or label into register (my answer there also has some NASM syntax).

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847