flat assembler
Message board for the users of flat assembler.
Index
> Main > Error: operand sizes do not match |
Author |
|
jkhjklhgl 15 Mar 2016, 17:49
I get 'operand sizes do not match'.
Code: mov [timer_start],eax mov [timer_start+4],edx section '.data' data readable writeable timer_start rq 1 |
|||
15 Mar 2016, 17:49 |
|
cod3b453 15 Mar 2016, 18:51
The natural size of timer_start is qword so you'll want to use the dword override:
Code: mov dword [timer_start],eax mov dword [timer_start+4],edx |
|||
15 Mar 2016, 18:51 |
|
jkhjklhgl 27 Mar 2016, 13:39
But eax has 32 bits and I'm generating 32 bit code. The operation can only be 32 bits, so why demand the use of 'dword'?
|
|||
27 Mar 2016, 13:39 |
|
jkhjklhgl 27 Mar 2016, 15:06
JohnFound wrote: Because the compiler is not sure you really want to write 32bit register to 64bit variable. You could misspell the names of similar named variables, for example. JohnFound wrote: Or you redefined the variable from 32 to 64 bit and then forgot to change the mov instruction from eax to rax. |
|||
27 Mar 2016, 15:06 |
|
system error 27 Mar 2016, 15:55
timer_start is a 64-bit operand. EAX is a 32-bit operand. So "operand size doesn't match" pretty much sums it up. Rule of mov - two operands must be of equal size.
You can make it as an 32-bit operand by using a 32-bit pointer as operand, so this can save you the dword directive. Code: mov ebx,timer_start mov [ebx],eax |
|||
27 Mar 2016, 15:55 |
|
jkhjklhgl 27 Mar 2016, 16:33
Maybe it's better to write:
Code: timer_start rd 2 |
|||
27 Mar 2016, 16:33 |
|
l_inc 27 Mar 2016, 16:42
jkhjklhgl
That would be exactly my answer. The point is not what kind of code (16-, 32- or 64-bit) you write. The point is how you declare your variables. Declarations indicate what kind of variable you have and if that kind does not match the operation you try to apply to it, then the compiler complains. That the compiler "is not sure" is not correct in this case. It's quite sure that you're using a wrong operation unless you forcefully make it shut up with a size override operator. For that reason the change in the declaration is a much better idea as it needs no enforcement and allows the compiler to perform the size check. _________________ Faith is a superposition of knowledge and fallacy |
|||
27 Mar 2016, 16:42 |
|
cod3b453 27 Mar 2016, 17:58
While it could infer the 32bit dword encoding there are many possible ambiguities that would otherwise be missed:
use32 vs use64/mov vs mov{s|z}x/Exx vs Rxx mov (gpr) vs movq (mmx) natual size (qword) vs explicit qualifier (dword) semantically incoherent halves (non-atomic modification) A further option is to make use of a union that has both the full 64bit value and its 32bit sub-components so that natural encodings can be selected. |
|||
27 Mar 2016, 17:58 |
|
revolution 28 Mar 2016, 08:31
jkhjklhgl wrote: Maybe it's better to write: |
|||
28 Mar 2016, 08:31 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.