You are not doing simple arithmetic, at least you used system call explicitly.
If these lines are all your codes, then the problem causing the segfault is not in itself, it's the empty code after those lines.
See here the system call list for linux 32bit. When %eax
is 4, the call is write
. So written in C, you are calling
// write(unsigned int fd, const char * buf, size_t count);
write(0xffff, 0, 0);
since before int 0x80
, your registers are %ebx=0xffff
, %ecx=0
, %edx=0
. This call will return an error, but won't cause segfault, since 0xffff
is not a valid file descriptor.
Then system call returns and your program resumes the execution. There is no planed code after this point, but CPU will still execute what is after this memory point, normally just many zeros, those garbage execution causes segfault.
If you want your assembly program terminate normally, you need to call another system call sys_exit
explicitly. For better understanding your simple assembly program, use gdb to look at its effect step by step.