NASM - The Netwide Assembler

NASM Forum => Using NASM => Topic started by: niccolo on August 16, 2021, 05:47:11 PM

Title: Make NASM print warning when operands aren't of same size.
Post by: niccolo 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.)
Title: Re: Make NASM print warning when operands aren't of same size.
Post by: niccolo on August 16, 2021, 08:46:12 PM
Oh my, I've found the following in the manual (https://www.nasm.us/xdoc/2.15.05/html/nasmdoc2.html#section-2.2.3):

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.)