User Tools

Site Tools


programming:assembly:assembly_programming

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
programming:assembly:assembly_programming [2021/03/21 07:53]
nanodano [Call Assembly functions from C]
programming:assembly:assembly_programming [2021/03/22 02:22] (current)
nanodano ↷ Page name changed from programming:assembly:home to programming:assembly:assembly_programming
Line 3: Line 3:
 ====== Assembly Programming ====== ====== Assembly Programming ======
  
 +Assembly is about as close as you can get to machine code. 
 There are many Assembly compilers out there. ''nasm'' is one compiler that is available across platforms and can be used to program x86 processors. There are many Assembly compilers out there. ''nasm'' is one compiler that is available across platforms and can be used to program x86 processors.
  
Line 8: Line 9:
  
 Use interrupt ''0x80'' to make Linux system calls like reading and writing to file descriptors and sockets. Use interrupt ''0x80'' to make Linux system calls like reading and writing to file descriptors and sockets.
-For a list of system calls in Linux, refer to [[https://man7.org/linux/man-pages/man2/syscalls.2.html]]+For a list of system calls in Linux, run ''man syscalls'' or refer to an online man page like [[https://man7.org/linux/man-pages/man2/syscalls.2.html]]. To get the actual number, try to find the ''unistd.h'' file. For example, in Debian, ''/usr/include/asm-generic/unistd.h'' has all of the statements that define the syscall numbers (''NR''). Or, refer to the source code of Linux (pick the right branch) [[https://github.com/torvalds/linux/blob/v4.17/arch/x86/entry/syscalls/syscall_64.tbl]] and [[https://github.com/torvalds/linux/blob/v4.17/arch/x86/entry/syscalls/syscall_32.tbl]].
  
 Here is an example of compiling with ''nasm'': Here is an example of compiling with ''nasm'':
Line 47: Line 48:
  int 80h              ; call the kernel  int 80h              ; call the kernel
  
 +</code>
 +
 +Compile and run with:
 +
 +<code bash>
 +# Compile
 +nasm -f elf64 hello.asm -o hello.o
 +
 +# Link
 +ld hello.o -o hello
 +
 +# Run
 +./hello
 </code> </code>
 ===== x86 on DOS ===== ===== x86 on DOS =====
programming/assembly/assembly_programming.1616313190.txt.gz · Last modified: 2021/03/21 07:53 by nanodano