1. Data types

We will now see the types of data present in assembler. As you will see there is not much.

Type Size
Byte 8 bits
Word 16 bits
Double word 32 bits
Quad word 64 bits
Ten bytes 80 bits

2. Define initialized data

When reading the NASM documentation, you end up falling on a page containing the image below. This image makes it possible to understand the definition of variable in a program in assembler:

Each type of data can be read as below:

Type Description
db Define byte (1 byte)
dw Define word (2 bytes)
dd Define double word (4 bytes)
dq Define quad word (8 bytes)
dt Define ten bytes (10 bytes)

3. Define uninitialized data

To declare uninitialized data, here's how to do it:

As you can see, it's pretty simple to define data.

4. Endianness

Before finishing this part of the tutorial, we have to know one last element which is the endianness.
Endianness refers to the sequential order in which bytes are arranged into larger numerical values when stored in memory or when transmitted over digital links. Endianness is of interest in computer science because two conflicting and incompatible formats are in common use: words may be represented in big-endian or little-endian format, depending on whether bits or bytes or other components are ordered from the big end (most significant bit) or the little end (least significant bit).

5. Practice

You can put into practice what we have just seen. To do this, you can declare variables of different types and understand what is going on with a debugger.

Here is a small skeleton to help you:

section .text
global _start

    ; not important here but if you want to test assignation
    mov rax, var1
    mov rbx, var2
    ; ...

section .data
    var1: db 0x12, 0x34
    var2: dw 0x1234
    var3: TIMES 3 db 0x41
    ; etc

section .bss
    buf: resw 20
    ; etc

6. References

  1. Endianness definition
    Wikipedia endianness
  2. Endianness image viva64.com
  3. NASM Official documentation
    NASM official documentation