Member Avatar for Jeph_1

Hello, I wrote this c program that will rearrange the numbers in an array such that all the even numbers come first and that will also calculate the sum. However, when I tested it on mipsmark software ( for correcting assembly language programs) I have a test fails.

Here's what it say: Did 0 swaps
evens=-36 odds=0

  int arr[LENGTH] = {1,2,3,4,5,6,7,8,9};

void rearrange (int a[], int length)

{
   /* Initialize left (i) for outer loop iteration  and right index (j) for inner loop iteration */
    int i = 0, j = 0;
    /* repeat i loop n times */
    for (i = 0; i < length; i++)
     {
        /* start the j loop from the element next to i && set j = i + 1 */
        for (j = i + 1; j < length; j++)
          {
            /* check if 1st element is odd && 2nd is even. If so, call swap function */
            if (a[i] % 2 == 1 && a[j] % 2 == 0)
               {
                /* once elements are exchanged, compare the 1st element with the others */
                swap (&a[i], &a[j]);
                break;
                }
           }
    }
}

int firstodd (const int a[], int length)
{
  int i, j;
  for (i = 0; i < length; i++)
    { 
    /* repeat loop n times until if finds an odd number */
    if (a[i] % 2 == 1)
    break;
    }
   return i;
}

int sum (const int a[], int length)
{
  /* set s to 0 */
  int i, sum = 0;
  for (i = 0; i < length; i++)
  /* adding each element of array with current sum value */
    sum = sum + a[i];
    return sum;
}

Recommended Answers

All 8 Replies

I was left guessing here. That is, you didn't explain why we use MIPSMARK and more. Maybe this is some homework that I'd have to know which course and the book chapter or assignment to get a clear picture but as presented I don't see how I can pass this MIPSMARK test.

Member Avatar for Jeph_1

i wrote the code and i have to test it with mipsmark to be graded it has a bug, my program works correctly. I probably has a minor mistake somewhere

I've been programming since the 1970's and never heard of MIPSMARK so I leave it to you to tell the story. Also how I can see what book this assignment came from. I've written code for dozens of micros over the years so let me share that automatic code checkers are not infallible. Maybe MIPSMARK is some new AI grading app? You may want to discuss this one with the professor if the code works but the AI is complaining.

commented: I've never heard of it either, but apparently it has been around since 1998. Go figure. +15

From what I've read, MIPSMARK is intended for checking and grading MIPS assembly language programs. Are you compiling the C code to MIPS assembly, and if you are, with what compiler and compiler invocation?

Where is MIPSMARK available from? Do you know of a download site for it, or a documentation page? Also, could you tell us which book the assignment is from?

commented: OP supplied C style code and then as you note something about assembler check app but left out the story and more. +16
Member Avatar for Jeph_1

does my code take into account all the cases? If it has been failed its because I have made a mistake. If you look at introduction to risc assembly language programming.

What mistake is there? You haven't told us why you write in C and test the compiler's assembly output. No one I know has done this.

If there is a test that wasn't done, maybe it's the lone IF test on line 14? I'm really stretching here that there is no code to handle when there is no true result to line 14. That does not mean it's bad code!

The fact that the code given is incomplete, with no main() function, makes it hard for us to judge whether it works at all.

Member Avatar for Jeph_1

was able to debug myself. Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.