Sorry for my English, I know it well enough to understand it, but I struggle when writing.
However, when the assembly code is translated into binary, the computer distinguishes between code and data thanks to the organization of memory and the information contained in the executable files.
Memory segmentation Programs are divided into different sections:
Text segment (.text): contains the executable instructions. Data segment (.data): contains static data such as initialized variables. BSS segment (.bss): contains uninitialized data. Stack and Heap: areas for dynamic memory management. Executable file format When the assembly is assembled and linked, the resulting file (for example, in ELF format on Linux systems) includes a table that specifies which sections contain code and which data. The operating system, when loading the program into memory, respects this division.
Memory protection Modern CPUs use memory protection to separate code and data. For example, the text segment is usually read-only and executable, while the data segment is writable but not executable. This helps prevent errors and attacks such as buffer overflows.
Pointers and Addressing The CPU's execution unit follows the instruction counter (PC - Program Counter) to know which instructions to execute. The executable code is loaded into specific addresses and the data into others, avoiding confusion between the two.
In summary, although the .data and .text directives are removed after assembly, the executable file retains the division, and the operating system and CPU use this organization to distinguish between code and data.
Hopefully, I've given you an idea of how it works!