0

How come mov rax, [rbp + 8*r8] is valid addresing, but mov rax, [rbp - 8*r8] isn't ? mov rax, [rbp - 8] is also fine. I couldn't find anything on a negative scale*index value being an issue. To me it seems it follows the SBI template. (I didn't wanna dump my code here since this is the only line of code I get an error for).

monolith937
  • 429
  • 1
  • 4
  • 13
  • 3
    because the only scaling factors allowed are 1,2,4,8 not -1,-2,-4,-8 – Michael Petch Aug 10 '18 at 14:55
  • What about if `r8` contained a negative value ? – monolith937 Aug 10 '18 at 14:56
  • 4
    The contents of the register can be anything the scaling factor is limited. – Michael Petch Aug 10 '18 at 14:57
  • 1
    @monolith937 Then you can still do `rbp + 8*r8`. What `r8` contains doesn't matter. – fuz Aug 10 '18 at 15:08
  • 3
    It is documented in the basic architecture manual, section _3.7.5 Specifying an Offset_, in particular _Figure 3-11. Offset (or Effective Address) Computation_ and _"Each of these components can have either a positive or negative (2s complement) value, with the exception of the scaling factor."_. – Jester Aug 10 '18 at 15:10
  • 1
    See https://wiki.osdev.org/X86-64_Instruction_Encoding#SIB to understand why you can't have a negative scale: it's only a 2-bit field which can encode a left-shift of 0..3. It would take 1 more bit to allow subtraction instead of addition. – Peter Cordes Aug 11 '18 at 01:10

0 Answers0