Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7875111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:55:42+00:00 2026-06-03T02:55:42+00:00

I’ve wrote a MIPS subroutine that implements the merge sort algorithm (the code is

  • 0

I’ve wrote a MIPS subroutine that implements the merge sort algorithm (the code is in the end of the post). It receives the pointer to the array, and its size. Sort it, and don’t return anything.

I’ve been debugging it, fixed some errors, and since the subroutine seems to work well until it reaches the base case (array of size 1), now I’m using gdb and this C code to debug it for that specific situation:

#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

extern void merge_sort(char*, int);

int main(int argc,char **argv){

    char* vector;
    vector = (char*)malloc(sizeof(char));
    if(vector == NULL) printf("error");

    size_t vector_size = 1;
    memcpy(vector,"5",vector_size);

    merge_sort(vector, vector_size);

    int i;
    for(i = 0; i < vector_size; i++){
            printf("%c ", vector[i]);
    }

    printf("\n");
    return 0;
}

My problem is that when I’m stepping through the subroutine lines, when I get to the penultimate line (jr ra), it crashes and exit with code 060, and gdb show this message:

Warning: GDB can't find the start of the function at 0x400730.
    GDB is unable to find the start of the function at 0x400730
    and thus can't determine the size of that function's stack 
    frame. This means that GDB may be unable to access that stack
    frame, or the frames below it.

    This problem is most likely caused by an invalid program 
    counter or stack pointer.  However, if you think GDB should
    simply search farther back from 0x400730 for code which looks
    like the beginning of a function, you can increase the range 
    of the search using the `set heuristic-fence-post' command. 
0x004008a0 in _start

I can’t figure out why that happens. I think it could be either a problem with the address stored in ra, a bad stack allocation, or wrong linkage between the C and MIPS code, but I have no idea about what I’m doing wrong.

Here is the MIPS code of merge_sort:
For the base case, the code runs up to the line beq t1, zero, SALIDA, then jumps to SALIDA, and finishes. So I just paste that parts of code (SALIDA means exit in spanish :P).

#include <mips/regdef.h>
#include <sys/syscall.h>

#define     SSIZE   (56)
#define     O_RA    (48)
#define     O_FP    (44)
#define     O_GP    (40)
#define     O_S3    (36)
#define     O_S2    (32)
#define     O_S1    (28)
#define     O_S0    (24)
#define     O_ARG0  (SSIZE)
#define     O_ARG1  ((SSIZE) + 4)

.text
.align  2
.globl  merge_sort
.ent    merge_sort

merge_sort:
.frame $fp, SSIZE, ra
.set noreorder
.cpload t9
.set reorder     

subu    sp,sp,SSIZE

sw  s0, O_S0(sp)
sw  s1, O_S1(sp)
sw  s2, O_S2(sp)
sw  s3, O_S3(sp)

sw  gp, O_GP(sp)
sw  $fp, O_FP(sp)
sw  ra, O_RA(sp) 
move    $fp, sp

sw  a0, O_ARG0($fp)
sw  a1, O_ARG1($fp)

lw  t0, O_ARG1($fp)
addi    t1, t0, -1

beq     t1, zero, SALIDA

SALIDA:     
lw  s0, O_S0($fp)
lw  s1, O_S1($fp)
lw  s2, O_S2($fp)
lw  s3, O_S3($fp)

move    sp, $fp
lw  gp, O_GP($fp)
lw  $fp, O_FP($fp)
lw  ra, O_RA($fp) 

addiu   sp, sp, SSIZE

jr  ra

.end    merge_sort
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T02:55:44+00:00Added an answer on June 3, 2026 at 2:55 am

    I think your problem is the following near the end of the subroutine:

    lw  $fp, O_FP($fp)    // restores $fp
    lw  ra, O_RA($fp)     // restore ra, but $fp isn't pointing to our frame anymore
    

    I think it might work better if you reverse those instructions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I have this code to decode numeric html entities to the UTF8 equivalent character.
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.