NASM - The Netwide Assembler

NASM Forum => Programming with NASM => Topic started by: sh0tz on August 25, 2022, 02:17:19 PM

Title: What does the "word" keyword mean?
Post by: sh0tz on August 25, 2022, 02:17:19 PM
I'm following a tutorial and I saw the 'word' keyword being used. What does it do? The code went something like:
Code: [Select]
div word [some_pointer]
Title: Re: What does the "word" keyword mean?
Post by: fredericopissarra on August 25, 2022, 03:39:38 PM
16 bits or 2 bytes.
Title: Re: What does the "word" keyword mean?
Post by: Frank Kotler on August 25, 2022, 04:06:22 PM
 Hi sh0tz,

Welcome to the forum.

"word" is just a size - 16 bits or two bytes.

Other sizes would be:
nybble - 4 bits
byte - 8 bits
dword - 32 bits, 4 bytes
qword - 64 bits, 8 bytes

In some cases, Nasm can tell the size - typically by the size of the register that is used. In other cases, typically the contents of a pointer, as in your example, Nasm needs to be told the size.

Some other assemblers remember the size, Nasm does not.

Code: [Select]
myvar dw 42 ; "dw" = data word, not dword! "dd" is data dword.
mov [myvar] word 11  ; needs the size and will complain if it doesn't get it
mov word [myvar], 11 ; size can go before or after
mov [myvar], ax ; Nasm knows the size
mov [myvar], eax ; oh oh -  this is an error, but Nasm doesn't know it! Be careful!
mov [myvar], al ; also an error but MAY not do any  harm.

That's just the way it is. Unlikely to change at this point...

(Thanks, Fred)

Best,
Frank