1

In my compilers class assignment, we were asked to write some MIPS code. One of the problem involved implementing fact() function as a sub-problem. I wanted to implement the standard recursive version

int fact ( int n )
{
     if ( n == 0 || n == 1 )    return 1;
     return n * fact(n-1);
}

As I am new to MIPS, I looked up here on how to implement recursive routines. Unfortunately, the link explained recursion using fact() function itself. As I didn't want to "copy" code, I just understood the concept of recursion and wrote the fact myself.

But my fact code seems very similar to the one I looked up to learn recursion in MIPS. Is it for the fact that I glanced at the code already or the fact that factorial is really a very simple function with hardly 10 lines in it? Am I guilty of plagiarism here?

Here is my code

fact:   addi $sp, $sp, -8       # decrement SP to make room for pushing input var and ret addr
        sw $ra, 4($sp)          # save $ra
        sw $a0, 0($sp)          # save input on stack

        li   $v0, 1             # Set v0 to 1 initially.
        beq  $a0, 0, fact_ret   # if ( n == 0 )    return 1;
        beq  $a0, 1, fact_ret   # if (n == 1) return 1;

        addi $a0, $a0, -1
        jal fact                # Recursive call fact(n-1)
        lw  $a0, 0($sp)
        mult $v0, $a0           # n * fact(n-1)
        mflo $v0                # Save answer in v0
fact_ret: 
        lw $ra, 4($sp)          # restore $ra
        addi $sp, $sp, 8        # restore $sp
        jr $ra                  # return from function
2
  • There's only one standard way to write "Hello World" in any language (don't play tricky, please). For a function so simple, I'd be more concerned if your function looked nothing like a standardized example.
    – Compass
    Feb 10, 2015 at 19:17
  • The best defense again plagiarism is attribution. You can always add a note to your assignment (e.g. in a comment) to say that you consulted a source, wrote the code separately, and the results ended up being similar. Then the professor will make the decision. If the professor is approachable, you could also ask about this during office hours. Feb 11, 2015 at 11:27

3 Answers 3

3

I think this is very subjective question and will depend on who the judge is. I would suggest you communicate exactly what you wrote in the question to your professor and let him be the judge. If he thinks yes, he might assign you some other relevant exercise to evaluate your learning.

By actually being honest about your situation, you will likely be treated in a positive light.

3

The answers here are insane.

This is less than nothing!!! You are discussing implementation of extremely basic function as a small part of your homework where using the internet is probably not only allowed but also desired.

0

You are right to worry about it since it might be detected as plagiarism by scanning software. At my last university, there was what might best be called a plagiarism witch-hunt that was carried out upon students with very little common sense by some staff. As advised above, you might well want to insert a disclaimer in your submission. You also would be wise to cite all reference material used before and after writing the function.

As advised above, your algorithm should be similar for something like this. If you haven't copied the function, then your comments should be significantly different from the original ones. You might even be advised to deliberately alter any comments that seem too similar to the published material or to 'tweak' the algorithm as a prophylactic against accusations of plagiarism.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .