Question

I'm in an assembly language course focusing on x86 Pentium processors, and am working on a Linux system. I understand that programs get loaded into memory and that you can perform operations directly within the registers but I'm not sure you can avoid creating a data segment altogether.

A yes or no, followed by a brief explanation as to why would be great.

Was it helpful?

Solution

It is not required. A data segment is simply a block of memory allocated for data and thus can be written to and read from. Code segments are read only. If you try to write to a code segment the hardware will generate an interrupt. However, assembly codes can be fed any address in memory, and if protected mode is disabled, then the hardware won't generate an interrupt.

As an example, the boot sector loads into a very restricted space on launch, and it is quite common (because space is so restricted) to place variables among the code bytes. Once I even wrote a boot sector that adjusted its own byte-code to accommodate differences in booting from different disks. So this is a case of code using code addresses as variables.

However, while you definitely can avoid creating a data segment, 99.99% of the time you do separate out a data segment.

You may also want to read up on protected mode to understand this better.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top