Thread: BuYS:Compiler magic!
-
06-24-2012, 02:33 PM #1Garage Member
- Join Date
- Sep 2010
- Location
- Chennai
- Posts
- 83
- Blog Entries
- 1
- Thanks
- 16
- Thanked 55 Times in 18 Posts
BuYS:Compiler magic!
Hey guys,
Long time...Hope you are all doing well.. I made a small programming puzzle @ The compiler magic! « phr33dom
Try solving it. And FYI , kindly post the answers as comments in the blog coz i have asked the same puzzle elsewhere too and it might be useful to a larger audience which includes my college juniors as well . And yeah, it is not a trick to generate blog traffic
If you feel, PM me the solutions too , i leave it up to u to submit the solutions the way you prefer.
Got a lot of catching up to do in g4h..
Till then ,
Peace
Btw: I used visual c++ 2010 , didn't try out for other compilers..will update in a day about results in gcc
//Update 1: Made a small typo in code..re-check the link..Last edited by sebas_phoenix; 06-25-2012 at 10:18 AM. Reason: Compiler used!!
-
06-24-2012, 02:45 PM #2Super Commando Dhruv


- Join Date
- Sep 2010
- Location
- Lucknow/Pune,India
- Posts
- 470
- Blog Entries
- 2
- Thanks
- 170
- Thanked 144 Times in 83 Posts
-
06-25-2012, 11:07 AM #3Garage Member
- Join Date
- Sep 2010
- Location
- Chennai
- Posts
- 83
- Blog Entries
- 1
- Thanks
- 16
- Thanked 55 Times in 18 Posts
Haha, i know dude.. Just kidding...
-
07-03-2012, 11:52 AM #4Security Researcher


- Join Date
- Jul 2010
- Posts
- 253
- Blog Entries
- 2
- Thanks
- 181
- Thanked 141 Times in 73 Posts
Namaste
The compilers check for a return statement and it is present but it is present (otherwise logically compilation should generate a warning).
Now the answer is:
The function is typecasted to int, it should return an int and return values are prepared into eax register.
This is the case with return line; now with else statement:
res=num*fact(num-1);
the res variable is might also be going inside EAX register right before the natural ending of the function i.e. the epilogue.
And thats why due to in both cases the EAX register is getting the value, thats why this code is working correctly.
Note: haven't checked the compiled/dissembled code, but a blind guess depending on the most of compiler's behavior.
..."vinnu"
-
07-13-2012, 08:59 PM #5Garage Member
- Join Date
- Sep 2010
- Location
- Chennai
- Posts
- 83
- Blog Entries
- 1
- Thanks
- 16
- Thanked 55 Times in 18 Posts
Posted the answer @ The compiler magic! « phr33dom
@Vinnu bro: the 'res' variable will go into eax, if there was an 'explicit' return statement.



LinkBack URL
About LinkBacks



Reply With Quote

Poizon Web Exploiter 2.0
Yesterday, 10:34 PM in Tools & Scripts