Most x86 instruction sets are common to all processors - itโs a fairly safe bet that your processors have the same instruction set, except perhaps for SIMD instructions, which probably wonโt be very useful for you when implementing a simple compiler (These instructions are usually used to make multimedia applications, etc. faster). The instruction set is provided in the Intel - 2A and 2B manuals , in particular, they contain a complete list of instructions and their behavior, although other volumes are worth a look at.
When generating user space code, choosing an operating system matters when it comes to system calls. For example, if you want a program to output something to a terminal on 64-bit Linux, you need to make a system call:
- Load the value 1 into the
rax register to indicate that this is a write system call. - load the value 1 into the
rdi register to indicate that stdout should be used (1 - file descriptor for stdout) - Loading the start address of what you want to print into the
rsi register - loading the length of what you want to print into the
rdx register - executing the
syscall after setting registers (and memory).
The return value from write stored in rax .
Another operating system may have a different system call number for write , there may be a different way of passing arguments (x86-64 Linux system calls always use rdi , rsi , rdx , r10 , r8 and r9 in this order for parameters, with the system call number in rax ) and generally can have different system calls.
The convention for regular function calls on Linux is similar - the order of the rdi , rsi , rdx , rcx , r8 and r9 (so anyway, except for using rcx instead of r10 ), with additional arguments on the stack and a return value in rax . According to this page , the registers rbp , rbx and r12 to r15 must be stored in all function calls. Of course, you can make your own agreement (if you donโt make a system call), but this makes it difficult to call from code created or written by others.
Michael williamson
source share