linux asm 101
it makes some sense to me now.
section .data
hello: db 'Hello world!',10
hellolen: equ $-hello
section .text
global _start ; obj entry
; ld(1) looks for this by default
_start:
mov eax, 4 ; write() system call
mov ebx, 1 ; standard output
mov ecx, hello ; my dear string
mov edx, hellolen ; length of my dear string
int 0x80 ; call kernel
mov eax, 1 ; exit() system call
mov ebx, 0 ; because things worked
int 0x80 ; exit gracefully
at first though (which is to say, sometime in the past), even with a set of comments, i still couldn’t understand anything even remotely close as to why that silly arrangement of numbers and instructions worked.
these are invaluable
/usr/include/asm/unistd.h man 2 [sys_call] e.g. man 2 write
i’m still learning but let me just share what i’ve learned so far. in linux assembly:
1) you put the system call number in the eax register.
2) you set the arguments to _that_ system call (respectively) in ebx, ecx, edx, esi, edi and ebp
3) if (arguments > 6), ebx will contain the memory location where the arguments are stored.
4) the relevant interrupt is 80h (0x80) (in dos, it is int 21h)
5) the result is usually returned in register eax
thanks to :
linux assembly dot org
google dot com
more on this topic as i progress.
