Author Topic: Size Specifier Position In The Mem Involved Instructions?  (Read 10930 times)

Offline dalfonso01

  • Jr. Member
  • *
  • Posts: 44
Size Specifier Position In The Mem Involved Instructions?
« on: July 24, 2014, 08:50:00 AM »
Hi,
As far as I can understand the  instructions:

mov dword [HexStr],  'G'

mov [HexStr], dword  'G'

mov dword [HexStr], dword  'G'

work and do the same.

Are this corrects ? And what could the better representing (the 3rd is just to overload more)

I checked and they will end up to the very same opcode:
   29 00000011 C705[00000000]4700-             mov dword [HexStr],  'G'
   30 00000019 0000

Thanks
« Last Edit: July 24, 2014, 09:06:50 AM by dalfonso01 »

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Size Specifier Position In The Mem Involved Instructions?
« Reply #1 on: July 24, 2014, 09:54:06 AM »
Yeah, they're all the same. I tend to default to:
Code: [Select]
mov dword [eax], 'G'
But I was discussing this question with someone around here, and we observed that in:
Code: [Select]
movzx eax, byte [ebx]
the size specifier has to come second, so perhaps it would be better to standardize on putting it second. I haven't changed my habits, but you can develop better ones if you want. :)

Why in the world you want to treat 'G' as a dword is a different question. :)

Best,
Frank


Offline dalfonso01

  • Jr. Member
  • *
  • Posts: 44
Re: Size Specifier Position In The Mem Involved Instructions?
« Reply #2 on: July 24, 2014, 10:17:22 AM »
Hi,
that was just playing with the fact that you are 'altering' more than you are actually putting, so that size specifier has a reason to be there.

Thanks
Fabio D'Alfonso

Offline dalfonso01

  • Jr. Member
  • *
  • Posts: 44
Re: Size Specifier Position In The Mem Involved Instructions?
« Reply #3 on: July 24, 2014, 10:46:15 AM »
Hi,
I was now wondering why the two are different, but in this case the point is that the

movzx byte eax, [ebx]

is not different but actually and error, because we are applying a size specifier to a register that has its own implicit size getting a warning, and being ignored, while the other which is a location  in memory has no one.

But there is something more I would need to think about this, because

mov byte eax, [ebx]

only fires the warning.

Any way, as of my minimal knowledge, if the destination is a register, you are using the register size to tell how much you are storing. That works for mov while is the opposite for movzx where there is a need to put the size specifier before the source operand, where in mov is an error.

« Last Edit: July 24, 2014, 11:36:53 AM by dalfonso01 »