flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Main > Error: operand sizes do not match

Author
Thread Post new topic Reply to topic
jkhjklhgl



Joined: 04 Mar 2016
Posts: 9
Error: operand sizes do not match
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

Post 15 Mar 2016, 17:49
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 616
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

Post 15 Mar 2016, 18:51
View user's profile Send private message Reply with quote
jkhjklhgl



Joined: 04 Mar 2016
Posts: 9
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'?
Post 27 Mar 2016, 13:39
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3459
Location: Bulgaria

jkhjklhgl wrote:
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'?


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. Or you redefined the variable from 32 to 64 bit and then forgot to change the mov instruction from eax to rax.

_________________
Tox ID: 48C0321ADDB2FE5F644BB5E3D58B0D58C35E5BCBC81D7CD333633FEDF1047914A534256478D9
Post 27 Mar 2016, 14:17
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
jkhjklhgl



Joined: 04 Mar 2016
Posts: 9

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.

If 32 bit code is generated, 64 bit variables must be written with two 32 bit operations. There is no reason for the compiler to suspect that anything is wrong.


JohnFound wrote:
Or you redefined the variable from 32 to 64 bit and then forgot to change the mov instruction from eax to rax.

The compiler knows when it's making 32 bit code, so this isn't possible.
Post 27 Mar 2016, 15:06
View user's profile Send private message Reply with quote
system error



Joined: 01 Sep 2013
Posts: 673
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

Post 27 Mar 2016, 15:55
View user's profile Send private message Reply with quote
jkhjklhgl



Joined: 04 Mar 2016
Posts: 9
Maybe it's better to write:

Code:
         timer_start rd 2

Post 27 Mar 2016, 16:33
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
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
Post 27 Mar 2016, 16:42
View user's profile Send private message Reply with quote
cod3b453



Joined: 25 Aug 2004
Posts: 616
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.
Post 27 Mar 2016, 17:58
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 15303
Location: Bigweld Industries

jkhjklhgl wrote:
Maybe it's better to write:

Code:
         timer_start rd 2


That would "solve" your immediate problem, but it is not really describing the precise contents of the variable. A single 64-bit value is not the same thing as two 32-bit values.
Post 28 Mar 2016, 08:31
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >

Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.