Author Topic: Make NASM print warning when operands aren't of same size.  (Read 6920 times)

Offline niccolo

  • Jr. Member
  • *
  • Posts: 2
Make NASM print warning when operands aren't of same size.
« on: August 16, 2021, 05:47:11 PM »
Look at the following code:

Code: [Select]
  segment .text

     mov eax, x
     mov ebx, y

     ...

  segment .data

     x DW 10
     y DW 1

It has a bug: 'x' and 'y' are defined with 'dw' (16 bits) instead of 'dd' (32 bits). And they're assigned to 32 bits registers.

How can I make NASM print a warning in this case? If it's not possible, is there some way to guard against such bugs?

I've run nasm with the '-w+all' command line option, but it prints no warning.

(I'm new to Assembly.)

Offline niccolo

  • Jr. Member
  • *
  • Posts: 2
Re: Make NASM print warning when operands aren't of same size.
« Reply #1 on: August 16, 2021, 08:46:12 PM »
Oh my, I've found the following in the manual:

Quote
  2.2.3 NASM Doesn't Store Variable Types

  NASM, by design, chooses not to remember the types of variables you declare.

So I guess that's it.

(Anyway, if anybody has tips on how not to trip on this, I'm all ears.)