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.