I'm trying to learn assembly, and it makes sense to an extent but I have a problem. I have this source file hello.sfml:
; nasm -felf64 hello.asml && ld hello.o
global _start
section .text
_start:
; write(1, message, 13)
mov rax, 1 ; syscall 1 is write
mov rdi, 1 ; file handle 1 is stdout
mov rsi, message ; address of string to output
mov rdx, 13 ; number of bytes in the string
syscall ; invoke OS to write the string
; exit(0)
mov rax, 60 ; syscall 60 is exit
xor rdi, rdi
syscall ; invoke OS to exit
message:
db "Hello, World", 10 ; the 10 is a newline character at the end
Which works perfectly. I just don't understand why particular integer registers need to be used in different cases.
So for example, by trial and error I've discovered that when saying which syscall I want, e.g.
mov rax, 1
...
syscall
I put the value 1 into the integer register rax, but I can also use the integer registers eax, ax, al, or ah.
I haven't been learning assembly for very long, so it may very well be an obvious question.
If my question isn't obvious: I want to know how to decide which integer register to move values to e.g. if there's some generic system for this, or if each different intention uses a different integer register.
I'm using NASM on 64-bit Ubuntu.
Edit: My question is not a duplicate of this one, because where that one's asking about where you would use smaller integer registers, I'm asking for a method of deciding which integer register to use.