NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: paml27 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
-
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
-
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
-
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:
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]
-
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.
-
Here's the probable confusion: NASM let you use 3, 5 or 9 "scale", as in:
mov eax,[rbx*3]
mov eax,[rbx*5]
mov eax,[rbx*9]
As shortcuts to:
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
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.