I'm stepping into the world of Assembly Language Programming. I'm trying to understand everything found on: https://www.tutorialspoint.com/assembly_programming
I came across the code below:
section .text
global _start ;must be declared for using gcc
_start: ;tell linker entry point
;This part works fine.
;mov edx, len ;message length
;mov ecx, msg ;message to write
;This does not work because I interchanged edx and ecx.
mov ecx, len ;message length
mov edx, msg ;message to write
mov ebx, 1 ;file descriptor (stdout)
mov eax, 4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax, 1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, Kaunda!',0xa ;our dear string
len equ $ - msg ;length of our dear string
Can I choose to put the variable 'len' or 'msg' in any of the data registers (EAX, EBX, ECX and EDX).
On order words:
WHY is the content of variable len
transferfed into EDX register and not ECX or any other register? Is there a clear guideline to know which variable goes into which register?
I've read about about the functions of each of the registers EAX, EBX, ECX and EDX but I'm still not clear. Their functions looks similar to me.
Update: I've running the code from https://www.tutorialspoint.com/compile_assembly_online.php
I think that is Linux environment
See Question&Answers more detail:os