Assembly language step by-step programming with linux | Search for a title, author or keyword | ||||||||
Assembly language step by-step programming with linux by Jeff Duntemann. If you’re going to build your own operating system ( and you are going to, right? ), you’ll need be familiar with assembly programming. And before we can get started, you’re going to need an x86_64 Linux machine with the program NASM installed. Like most programming language tutorials, we will start by crafting the most basic of programs: “Hello, World!”. I will start by showing you the code, which I recommend you type in manually – no copy and paste! – to better commit it to memory. Remember: Linux has a completely different system call ABI ( Application Binary Interface ) under 64bit mode. We have SYSCALL, which tells the computer that we want to execute a system call using the values that we loaded into the CPU’s registers. The first number that we loaded, the one in register RAX, tells the computer what syscall that we want to use. A table of syscalls and their respective numbers is available in your "unistd_64.h" file. As you can see from the table, the 1 that we loaded into register RAX means that we will be calling write(int fd, const void* buf, size_t bytes). The first number we loaded after loading register RAX, mov rdx, 13, is the same number that will be used for the final parameter of the write() function. The final parameter of write(), size_t bytes, specifies the size of our intended message and, indeed, the value in RDX, 13, is the length of our message, “Hello, World!”. So, if we put it all together, by the time we get to syscall, we are telling the computer to execute write(1, message, 13), where: 1 ( RDI register ) is the same as stdout, so essentially we are telling the computer to write 13 bytes from message ( RSI register ) to stdout, which is exactly what our program does.
|
|||||||||
Assembly language step by-step programming with linux | Disclaimer: this link points to content provided by other sites. |