Author Topic: What does the "word" keyword mean?  (Read 6989 times)

Offline sh0tz

  • New Member
  • Posts: 1
What does the "word" keyword mean?
« 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]

Offline fredericopissarra

  • Full Member
  • **
  • Posts: 373
  • Country: br
Re: What does the "word" keyword mean?
« Reply #1 on: August 25, 2022, 03:39:38 PM »
16 bits or 2 bytes.

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: What does the "word" keyword mean?
« Reply #2 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