SYS_TIMERFD_CREATE equ 0x142 SYS_TIMERFD_GETTIME equ 0x146 SYS_TIMERFD_SETTIME equ 0x145 SYS_READ equ 0x3 ;timerfd_setttime() ;argument struct itimerspec contains 2 struct timespec ;struct timespec contains seconds as time_t (integer unixtimestamp?) and nanoseconds as long section .bss ;timer filedescriptor tfd RESB 4 ;target memory for sys_timerfd_gettime ot RESB 16 ;timer struct interval itimer RESQ 2 ;timer struct init val vtimer RESQ 1 ;variable for timer read tval RESB 8 section .data tick equ 2000 msg db 'tick',0xa msgl equ 5 section .text global _start _start: ;prepeare sys_timerfd_create mov eax, SYS_TIMERFD_CREATE mov ebx, 1 mov ecx, 0 int 0x80 ;get timer fd mov [tfd], eax ;init timer ;interval used for timer triggers mov [itimer], dword 0x05 ;sec mov [itimer + 4], dword 0x00 ;nanosecs ;value - initial value must bes set to arm timer mov [itimer + 8], dword 0x05 ;secs mov [itimer + 12], dword 0x0 ;nanosecs ;settime sys_timerfd_settime mov eax, SYS_TIMERFD_SETTIME mov ebx, [tfd] mov ecx, 0 mov edx, itimer mov esi, 0 int 0x80 poll: ;get time from fd ;not used just for debugging with strace mov eax, SYS_TIMERFD_GETTIME mov ebx, [tfd] mov ecx, ot int 0x80 ;sysread on fd from timer blocks til timer triggerd mov eax, SYS_READ mov ebx, [tfd] mov ecx, tval mov edx, 0x20 int 0x80 ;print "tick" mov eax, 4 mov ebx, 1 mov ecx, msg mov edx, msgl int 0x80 jmp poll exit: mov eax, 1 mov ebx, 0 int 0x80