4 ms·
ELI someone who knows mips?
by quantumtremor 11y ago
ELI someone who knows mips?
- pbsd 11y agoBasically equivalent to this C code (assuming BSR = procedure call): int x2(int x) { return x + x; } int x4(int x) { return x2(x) + x2(x); } int x8(int x) { return x4(x) + x4(x); } int x16(int x) { return x8(x) + x8(x); } int x32(int x) { return x16(x) + x16(x); }
- bbcbasic 11y agoHmm. How is this recursion? Maybe I don't understand what the word recursion means, but I thought that you'd have to call yourself directly or indirectly.
- ScottBurson 11y agoYou're right. This isn't recursion by any definition I know. Cute, though.
- bbcbasic 11y agoYes from the answers it seems it is recursion, as long as you stretch the definition of recursion to mean making subroutine calls, or code that can be refactored into a recursive solution. By these definitions, all but the most trivial code is recursive.
- LesZedCB 11y agoIt's not recursion in the sense that it calls itself. However, it does divide the problem into smaller (though explicitly defined) chunks, which is still recursion. You could state it that the multiple by a power of two is the sum of the multiples of one order of magnitude base 2 lower.
- sgustard 11y agoIt's equivalent to this recursive function, just change x2(n) to x(n, 2) and so on. // e is a power of two int mult(x, e) return e==1 ? x : mult(x, e/2) + mult(x, e/2) end