Fix : The fix is to use "-fomit-frame-pointer" directive when compiling using arm-linux-gnueabihf-gcc (probably for other flavors as well).
$arm-linux-gnueabihf-gcc {YOUR FILE NAME}.c -fomit-frame-pointer -o {YOUR OUTPUT FILE NAME}
Thank you guys for all the comments. So, for the record, the above code logic in the question, works. As far as I understand it, the issue was that the compiler for some reason uses r7 as frame pointer. You can keep adding arguments as input and create a more general purpose syscall implementation using inline assembly. Consider what people have said in the comments for better implementations.
Pseudocode
returntype my_syscall(int syscallnumber,type arg1,type arg2,..)
{
int output_variable = 0;
__asm__ volatile
(
"mov r7,[sysnum]\n\t"
"mov r0,[var1]\n\t"
"mov r1,[var2]\n\t"
//continue similarly for more input arguments etc
"svc 0\n\t"
"mov %0,r0\n\t" //Return value of syscall will be available in r0 for ARM EABI
:"=r"(output_variable)
:[sysnum]"r"(syscallnumber),[var1]"r"(arg1),[var2]"r"(arg2) //and so on for other arguments
:"memory" //clobber others based on usage
);
return output_variable;
}
Backstory (For anyone interested) : The same code(the one which is present in the question) with slight variations worked when I implemented a simple "Hello World" string write (changes included different syscall number and arguments). But it wouldn't work when I called my custom syscall which returned a needed value (Alternatively, you can design the syscall to return values using arguments instead of return instruction to avoid this whole issue. I didn't do it because then I would have to recompile the whole kernel but I digress). I tested my syscall with inbuilt syscall() function and it worked perfectly. But MY implementation of the syscall() function was unable to call MY custom syscall.
I tried register variables , I tried different instructions and clobbered r0, memory etc.(before I asked the question here) but nothing seemed to work. Then I tried clobbering r7 and the compiler said you can't do that. So that is when I found out the r7 register was being used for something else as well. When I googled the error I found the above fix.
Ironically, after the fix it worked without clobbering r7 or anything else. lol.