go to previous page   go to home page   go to next page hear noise highlighting

Answer:

As with all subroutines, mysub() starts with a prolog.


Prolog for mysub()

frame for main

Of course, mysub starts with a prolog. There are two variables so space is assigned to them on the stack.

The subroutine could be written without using $s1. But here is used to show how linkage works.


#  int mysub( int arg )
#  {
#    int b,c;                     // b: 0($fp)
#                                 // c: 4($fp)
#    b = arg*2;
#    c = b + 7;
#    
#    return c;  
#  }
         .text
         .globl   
 :
                                  # prolog        
         sub     $sp,$sp,4        #   1. Push return address
         sw      $ra,($sp)
         sub     $sp,$sp,4        #   2. Push caller's frame pointer
         sw      $fp,($sp)

              , ,       #   3. Push register $s1
         
              , 

         sub    $fp,$sp,    #   4. $fp = $sp - space_for_variables

         move   $sp,$fp           #   5. $sp = $fp
         
         . . . .     
                                  # epilog
         jr      $ra              # return to caller 

QUESTION 13:

Play compiler:

Fill in those blanks.


go to previous page   go to home page   go to next page