Why Aren't Other Registers Used in This Programming Code?

  • Thread starter pairofstrings
  • Start date
In summary: However, in 64 bit mode, there are no more segment registers, so you would need to use the TSS (Thread-Specific Storage) area, which is reserved for the OS and is not available for your program.
  • #1
pairofstrings
411
7
section .text
global _start:
_start:
mov eax, 4
mov ebx, 1
mov ecx, string
mov edx, length
int 80h

mov eax, 1
mov ebx, 0
int 80h

section .data
string: db "hello world", OxOA
length: equ 13

My question is simple. Why is the programmer not using other registers such as segment registers, index registers or pointer registers? I googled everywhere but couldn't find any explanation. If you have any material please share. thank you.
 
Technology news on Phys.org
  • #2
pairofstrings said:
section .text
global _start:
_start:
mov eax, 4
mov ebx, 1
mov ecx, string
mov edx, length
int 80h

mov eax, 1
mov ebx, 0
int 80h

section .data
string: db "hello world", OxOA
length: equ 13

My question is simple. Why is the programmer not using other registers such as segment registers, index registers or pointer registers? I googled everywhere but couldn't find any explanation. If you have any material please share. thank you.
This appears to be assembly programming in Linux. I'm very familiar with assembly programming in DOS, but not at all in Linux.

Do you understand what this program does? The first block of code causes the string "hello world" to be displayed on the computer screen. The second block of code causes the program to exit.

To answer your questions, I'm not sure about the one you asked about segment registers. It appears to me that segment registers are not needed. The code portion of this program is in the .text section (the code segment) and the .data section (data segment) contains the string and a variable for its length. If you had more code or more data than would fit in the code and data segments, I imagine that you would need some extra segments, and then you would need to use segment registers to identify the segment you are using.

BTW, your code has a typo. The hex number after the string is the linefeed character, ASCII 10. You have OXOA - it should be 0X0A. In other words, with the digit 0 before and after X, not the capital O that you have.

As far as index registers (such as ESI and EDI), this code doesn't need them, since it is not using any instructions such as LOOP that require them.

As far as pointer registers, I'm not sure what you mean. The code stores the address of the string in ECX, so this register is being used as a pointer.

In a little more detail, what is going on here is this.
EAX <--- 4 -- output a string
EBX <--- 1 -- send output to stdout (the computer screen)
ECX <--- string -- store the address of the string
EDX <--- length -- store 13
int 80h -- system call into the kernel. The value in EAX specifies which system call. The values in the other registers are parameters.

For the other system call,
EAX <--- 1 -- exit
EBX <--- 0 -- return code (I think)
int 80h --- system call into the kernel.
 
  • #3
Unless you code a kernel, you won't need to worry about segment registers. They're totally ignored because they're a pain to work with in C (and because there are other protection methods that work better).

When you say "pointer registers," do you mean EBP and ESP? Those are meant for stack management. They're too important for other things to be used for passing parameters.
 
  • #4
pointer registers
In 32 bit mode, the normal registers can be used as pointers (EAX, ECX, EDX) as well as the traditional pointer registers (EBX, ESI, EDI, EBP, ESP), and segment registers and virtual memory are usually preset by the OS to provide a flat virtual address space for your program.
 
  • #5


There are a few possible reasons why the programmer may have chosen to use these specific registers in this code:

1. Efficiency: The registers chosen may be the most efficient for this particular task. Different registers have different purposes and some may be better suited for specific operations.

2. Compatibility: The programmer may have chosen these specific registers to ensure compatibility with other systems or programs. Using different registers may cause compatibility issues and make the code less portable.

3. Simplicity: The code may have been written with simplicity in mind. Using too many different registers can make the code more complex and harder to understand.

4. Convention: In some cases, certain registers may be conventionally used for specific tasks. This could be due to historical reasons or common practices within the programming community.

Overall, the choice of registers used in this code may have been based on a combination of efficiency, compatibility, simplicity, and convention. It is also important to note that different registers may be used in different contexts and for different purposes, so there is no one-size-fits-all answer to why certain registers are used in a particular code.
 

1. Why aren't other registers used in scientific research?

Other registers may not be used in scientific research due to several factors such as compatibility, reliability, and availability. Some registers may not be compatible with the equipment or methods used in the research, making their use ineffective. Additionally, the reliability and accuracy of other registers may not be well-established, making them less desirable for use in scientific studies. Lastly, certain registers may not be readily available or accessible to researchers, limiting their use in scientific research.

2. Are there any advantages to using other registers in scientific research?

Yes, there are potential advantages to using other registers in scientific research. These registers may provide different or more specialized data that can enhance the understanding of a phenomenon or support a specific hypothesis. Additionally, using multiple registers can help validate findings and provide a more comprehensive understanding of a topic.

3. What are the drawbacks of using other registers in scientific research?

One of the main drawbacks of using other registers in scientific research is the potential for inconsistency or inaccuracy in the data collected. This can be due to differences in methodology, equipment, or reliability of the register itself. Additionally, using multiple registers may also increase the complexity of data analysis and interpretation, making it more challenging to draw clear conclusions.

4. How do researchers determine which registers to use in their studies?

The decision of which registers to use in a scientific study is typically based on the research question, objectives, and available resources. Researchers will select registers that are compatible with their methods and equipment, have a proven track record of reliability and accuracy, and are accessible for use. They may also consider the potential advantages and drawbacks of using certain registers in their study.

5. Can different registers be used together in a single study?

Yes, different registers can be used together in a single study. In fact, using multiple registers is often encouraged in scientific research as it can provide a more comprehensive understanding of a topic and help validate findings. However, it is essential to carefully consider the compatibility and potential drawbacks of using different registers and ensure that proper data analysis and interpretation methods are used.

Similar threads

  • Programming and Computer Science
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
7K
  • Programming and Computer Science
Replies
4
Views
6K
  • Sticky
  • Programming and Computer Science
Replies
13
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
Replies
6
Views
3K
Back
Top