0

Result of

VarHeaderLen equ 2
VarHeaderSize equ VarHeaderLen * 8

is that VarHeaderSize is substituted by "2 * 8". How to make it to evaluate to 16 in assembly time?

Edit: I receive following error message from fasm:

_gen_code.asm [225]:
mov rsi, qword [r13 + rcx * VarHeaderSize + VarValOffset]
processed: mov rsi,qword[r13+rcx*2*8+1*8]
error: invalid address.

DSblizzard
  • 4,007
  • 7
  • 48
  • 76
  • That does get evaluated to 16 at assembly time. What makes you think otherwise? – Jester Nov 11 '19 at 19:34
  • Error message (see Edit) – DSblizzard Nov 11 '19 at 19:37
  • @Jester: FASM `equ` is just a text substitution, which can be a problem for `len equ $ - msg`. So you use `foo = bar * 8` for on-the-spot eval. But yes, it does eventually become a compile-time constant of `2 * 8`. Which of course doesn't work as a 2-bit scale factor in an addressing mode. – Peter Cordes Nov 11 '19 at 19:40
  • As Peter is telling you, we cannot multiply by an arbitrary constant for the scaling factor in the scaled-indexed addressing mode. Only x1, x2, x4 and x8 are allowed: you're asking for x16. See http://www.c-jump.com/CIS77/CPU/x86/X77_0110_scaled_indexed.htm . For that factor, you'll have to scale separately in its own instruction instead of using the addressing mode. – Erik Eidt Nov 11 '19 at 19:45
  • @PeterCordes: This question does not have answer on linked page. Answer is: VarHeaderSize = VarHeaderLen * 8, "=" instead of "equ". Scale factor of 16 is another problem. – DSblizzard Nov 11 '19 at 19:49
  • `rcx * 2 * 4` is valid FASM syntax isn't it? (with the `2*4` happening at assemble time, just not on-the-spot). Yes, just tested with `mov eax, [rdi + rcx * 2 * 4]` and it assembles as expected. So `equ` wasn't the real problem, and your title based on your guess of what the problem was unfortunately misleading. `foo = bar * 8` wouldn't have answered the real question. – Peter Cordes Nov 11 '19 at 19:54
  • But if it makes you happy, there's a Q&A about FASM EQU vs. `=` – Peter Cordes Nov 11 '19 at 20:07

0 Answers0