Learning x86 with NASM — Working with Data and Stack Memory

Scott Cosentino
4 min readJun 1, 2022

In this article, we will create a program that stores simple numeric data using the .data section. We will first look at the different methods of declaring data. Once we have our data declared, we will look at how it can be loaded into a register for use.

The code for this article can be found at: https://github.com/scprogramming/Learning-x86-with-NASM/tree/main/Storing%20Numeric%20Data

Declaring Data in NASM x86

To declare data, we need to provide three pieces of information in the .data section of the program:

1. The variable name used to reference the data

2. The format of the data

3. The initial value of the data

For example, the code below shows how data can be declared in a program.

In this code, we have declared a variable named num. The type of this variable is DW, which stands for declare word. A word is an allocation of 16 bits of memory. The initial value of the variable is 0. To summarize, this code declares 16 bits of space in memory, initializes it to 0, and associates it with the name num.

--

--