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 5934617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:08:20+00:00 2026-05-22T15:08:20+00:00

I read in MIPS tutorial, that only reginsters $s0-$s7 are preserved across procedure calls.

  • 0

I read in MIPS tutorial, that only reginsters $s0-$s7 are preserved across procedure calls.
But I think (maby I am wrong?) that it is not elegant to create procedures that have side effects – I think procedures should change only $v0, $v1 reginsters and stack if it is needed (am I right?).
So in my opinion inside my procedure I can use only $t0-$t9 reginsters.
But when I call some prodedures in my procedure it can change $t0-$t9 reginsters. So I have to store temporary reginsters and restore it after procedure call in my procedure. But when my procedure looks like following:

call procedure1
compute something on temporary reginsters

call procedure2
compute something on temporary reginsters

call procedure3
compute something on temporary reginsters

...

my procedure needs a lot of memory accesses.
So my idea is to use:

Store at the begining of my procedure reginsters $s0-$s7.
Use reginsters $s0-$s7 in my procedure.
Restore old values of reginsters $s0-$s7.

Is it elegant and has it any bad consequences?

  • 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-05-22T15:08:21+00:00Added an answer on May 22, 2026 at 3:08 pm

    I read in MIPS tutorial, that only reginsters $s0-$s7 are preserved across procedure calls.

    Nothing magical happens to $s0–$s7 across a call (e.g. jal some_routine just sticks the return address in $ra and jumps to some_routine; nothing else happens).

    The preservation of these registers across a call is just a convention: it’s part of the standard “Application Binary Interface” (ABI), which is a set of conventions covering register usage, stack usage, data formats etc. — different bits of code (applications, libraries, etc.) which conform to the same ABI will interoperate with each other.

    If you want your code to be callable from elsewhere, your code needs to conform to the ABI expected by the caller. e.g. if you’re writing some assembly routine that needs to be called from C code, you’ll need to conform to the ABI used by the code that the C compiler generates.

    For the usual MIPS ABI, this means that the code which calls your routine will assume that whatever values it has put in $s0 – $s7 before the call will still be there after the call returns, but it will not assume that the contents of $t0 – $t9 are still the same. (Similarly, if your code calls out to library routines (for example), it can make the same assumptions: after the call returns, anything that was in $s0 – $s7 has been preserved, but $t0 – $t9 may contain anything.)

    That means your code must save any of $s0 – $s7 before changing them, and restore them before returning. What it does between saving and restoring them doesn’t matter — all that matters is that the caller does not see any change.

    So, yes, your idea is correct (and indeed the sensible thing to do here).

    (Note that your sub-procedures (procedure1, prodcedure2 etc.) do not necessarily have to conform to this standard ABI, if they are only ever called from your main procedure, and don’t call out to external routines — because, in that case, they only need to interoperate with your main procedure, not with any other code. But it is a good idea to follow the ABI anyway, unless there is a very good reason not to; it makes it easier to read the code, easier to make one of the internal procedures more public later on if necessary, easier to add calls to other code, etc.)

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

Sidebar

Related Questions

Read some other things on here re: this similar problem but am not sure
I am writing a program in MIPS that will read in signed integers from
Read Carefully The question here is not that does PHP parser processes comments or
Read on before you say this is a duplicate, it's not. (as far as
I read from some books that Phusion Passenger is the answer to easy Ruby
I read a guide . It says that run the following line and forget
I read the tutorial which advises me to run at util-linux package ./configure I
I read up someplace, that there are characters other than A-Z that have a
I read http://android-developers.blogspot.com/2012/01/say-goodbye-to-menu-button.html but have some issues. For pre-honeycomb I want a custom title,
I have this issue using assembly MIPS. From the keyboard I read an integer

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.