Author Topic: Invalid effective address  (Read 1601 times)

Offline paml27

  • Jr. Member
  • *
  • Posts: 36
Invalid effective address
« on: October 28, 2022, 03:01:46 PM »
Hello,

vmovsd xmm0,[rdi+0+r9*24] – why is this an invalid effective address

vmovsd xmm1,[rdi+0+r9*8] – and this is a valid effective address?

Thanks,

Pam

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Invalid effective address
« Reply #1 on: October 28, 2022, 03:22:31 PM »
Hi pam127,

I am not sure. It looks to me like the "* 24" might be the problem. 2, 4, 8... 16? and 32? maybe? I'm not sure what to do about it if 24 is what you want.

Best,
Frank


Offline paml27

  • Jr. Member
  • *
  • Posts: 36
Re: Invalid effective address
« Reply #2 on: October 28, 2022, 03:43:23 PM »
Hi, Frank,

Thanks for your reply.  I guess it's successive powers of two. 

When I come back from my meeting I am going to try vmovsd xmm0,[rdi+0+r9*16*3+8*3] and I'll let you know what happens. 

Pam

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: Invalid effective address
« Reply #3 on: October 28, 2022, 04:29:59 PM »
If the instruction has a SIB field (scale, index, base), then there is only 2 bits for the scale. So, it is 1, 2, 4 or 8, no more.

The easiest way to do [rdi+r9*48+24] is:
Code: [Select]
mov    rax,r9
mov    rdx,r9  ; if you want to preserve r9.
shl    rax,5   ; rax = r9 * 32
shl    rdx,4   ; rdx = r9 * 16
add    rax,rdx ; rax = (32 + 16)*r9
movsd  xmm0,[rdi+rax+24]
« Last Edit: October 28, 2022, 04:45:54 PM by fredericopissarra »

Offline paml27

  • Jr. Member
  • *
  • Posts: 36
Re: Invalid effective address
« Reply #4 on: October 28, 2022, 06:08:53 PM »
I've tried various combinations, but Frederico's method is the only way to do it for what I need. 

Thanks to both of you. 


Offline fredericopissarra

  • Full Member
  • **
  • Posts: 368
  • Country: br
Re: Invalid effective address
« Reply #5 on: October 28, 2022, 06:32:28 PM »
Here's the probable confusion: NASM let you use 3, 5 or 9 "scale", as in:
Code: [Select]
  mov eax,[rbx*3]
  mov eax,[rbx*5]
  mov eax,[rbx*9]
As shortcuts to:
Code: [Select]
  mov eax,[rbx+rbx*2]
  mov eax,[rbx+rbx*4]
  mov eax,[rbx+rbx*8]
Notice that "scales" don't allow the full SIB, as in
Code: [Select]
mov eax,[rbx+rdx*3] ; invalid!"Scales" as 6, 7 or greater than 9 aren't possible because the calculation is base+index*scale. Subtracting (base-index*scale) isn't possible, due to cannonincal addresing.
« Last Edit: October 28, 2022, 06:34:01 PM by fredericopissarra »