# ;; sleep.s # try to illustrate how to work with the nanosleep system call # # # The man page for nanosleep gives the following specification for the arguments: # # #include # # int nanosleep(const struct timespec *req, struct timespec *rem); # # # # struct timespec { # time_t tv_sec; /* seconds */ # long tv_nsec; /* nanoseconds */ # }; # # # had to work a bit to find that both "time_t" and "long" are actually .quad, not .long ! # # #include .file "sleep.s" .data time: .quad 5 .quad 0 rem: .quad 0 .quad 0 .text .globl sleep # first argument goes into %rdi == pointer to time # second argument goes into %rsi == pointer to rem (short for remainder, if we are interrupted) sleep: lea time,%rdi # lea rem,%rsi # mov $__NR_nanosleep,%rax # syscall is nanosleep, so 35 goes in %rax... syscall mov $0, %rdi # and exit with a zero status mov $__NR_exit, %rax # syscall = 60 is exit syscall