So I am trying to learn assembly(NASM). The issue is that the resources for assembly are very basic-theoretical and rare, and I cannot understand very basic things. I know that assembly registers are used as "variables" on the processor's "memory". But the issue is that for example in this "hello world" type program:
section .text
global _start ;must be declared for linker (gcc)
_start: ;tell linker entry point
mov edx,len ;message length
mov ecx,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 from assembly!',0xa ;a message
len equ $ - msg ;length of message
I cannot understand WHY we save for example the message length on edx and the message to write on ecx, when for example here in tutorialspoint it says:
So here I assume that since ECX should have the loop counter, in a C-like program:
for(int i = 0; i < 5; i++)
{
printf("Hey!\n");
}
the ECX register should contain the i. But on the program above, we save the message on ECX.
Similarly, I am confused about where we save the arguments when we want to call C functions from assembly, but I assume that since this is more advanced, if I understand what I save in which registers, gradually I would understand what happens in case i want to call C functions.
Thank you!
