1

I'm using inline x64 assembly with Intel Compiler and I'm trying to add a huge value to the RBP register.
The compiler gives me an error saying that the operand is incorrect for that huge number. Is there a way to solve this?

My code:

__asm add rbp, 0x7ffffffffffffff0
__asm and rbp, 0x7fffffff

The compiler outputs this:

ld-link: : error : ld-temp.o <inline asm>:2:2: invalid operand for instruction
           add rbp, 3264300659
           ^
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
hotline1337
  • 47
  • 1
  • 6
  • Similar to [Can I add 64bit constants to 64bit registers?](https://stackoverflow.com/q/20020589/555045) with a different assembler, but `add r64, imm64` is still not encodeable. – harold Dec 25 '22 at 20:53
  • 5
    Would you mind *not* adding a huge value to `rbp`? It is possible to do it, but the `and` instruction right after it makes that unnecessary *in this specific case* (the result can equivalently be computed with just `ebp` and 32-bit constants, which are encodeable). – harold Dec 25 '22 at 20:58
  • 1
    It's kind of misleading to write `0x7fffffff` lined up with the most-significant digit of `0x7ffffffffffffff0`. You should indent it more to its low digit lines up with the value you're adding, making harold's point more obvious, that you're zeroing all bits above bit#30, so that might as well be `and ebp, 0x7fffffff` – Peter Cordes Dec 26 '22 at 02:35

1 Answers1

4

No, there is no opcode that can do it in that way!
However there is a single opcode that can do the following:

BigConstant = 0x7ffffffffffffff0
...
...
add   rbp, qword ptr BigConst  //48 03 2D xx xx xx xx

You could also use an extra register to solve the problem, like:

mov   rax, 0x7ffffffffffffff0
add   rbp, rax
Sep Roland
  • 33,889
  • 7
  • 43
  • 76
GJ.
  • 10,810
  • 2
  • 45
  • 62