Sleep program in Linux Gas asm
This little program uses nanosleep syscall to sleep a specified amount of seconds. It accepts 2 arguments; 1st argument is how many seconds, and 2nd arg is how many nanoseconds.
Sleep - by Jakash3 For Linux; Usage: sleep sec nanosec
It also uses atoi from C library to convert string arguments into integers.
.text .globl _start _start: pushl %ebp movl %esp,%ebp #New stack frame movl 4(%ebp),%ecx #Get argc cmpl $3,%ecx jne help #Show help if argc!=3 movl 16(%ebp),%eax #Get argv pushl %eax call atoi #Convert to int movl %eax,(%esp) #Save it to stack movl 12(%ebp),%eax #Get argv pushl %eax call atoi #Convert to int movl %eax,(%esp) #Save it to stack on top of converted argv #Now we have our timespec struct on the #stack. leal (%esp),%ebx #Address of timespec struct in ebx movl $162,%eax #nanosleep syscall function movl $0,%ecx #Useless argument set to null int $0x80 #EXECUTE CALL leave #Pop off stack frame jmp endstart help: movl $4,%eax #Write syscall function movl $1,%ebx #Write to stdout movl $helpmsg,%ecx #Address of data movl $55,%edx #Number of bytes to write int $0x80 #EXECUTE CALL endstart: movl $1,%eax #Exit syscall function movl $0,%ebx #Return status 0 int $0x80 #EXECUTE CALL .data helpmsg: .ascii "Sleep - by Jakash3\nFor Linux; Usage: sleep sec nanosec\n"
To assemble run these:
as -o sleep.o sleep.asm ld -I /lib/ld-linux.so.2 -o sleep -lc sleep.o
./sleep 3 0