1

I write a simple code for test.

#include <stdio.h>

int funadd(int a, int b){
  int x = 0;

  x = a + b;

  return x;
}

int fun(int a, int b){
  int y = 17;
  int returnvalue = 0;

  returnvalue = funadd(a, b);
  returnvalue = returnvalue - y;

  return returnvalue;
}

int main(){

  int a = 32;
  int b = 24;

  int c = 0;

  c = fun(a, b);

  printf("%d\n", c);

  return c;

}

And then assemble it.

After assembly, I realize that there is some section at the beginning of each function.

funadd:
    .frame  $fp,24,$31      # vars= 8, regs= 1/0, args= 0, gp= 8
    .mask   0x40000000,-4
    .fmask  0x00000000,0
    .set    noreorder
    .set    nomacro
...
fun:
    .frame  $fp,40,$31      # vars= 8, regs= 2/0, args= 16, gp= 8
    .mask   0xc0000000,-4
    .fmask  0x00000000,0
    .set    noreorder
    .cpload $25
    .set    nomacro
...
main:
    .frame  $fp,48,$31      # vars= 16, regs= 2/0, args= 16, gp= 8
    .mask   0xc0000000,-4
    .fmask  0x00000000,0
    .set    noreorder
    .cpload $25
    .set    nomacro

I want to know what each section means, how to use these sections and why they are here.And why are they different in different functions such as main and the funadd.

And what I care about most is if I append some functions by myself with assembly form in the .s file which gcc makes, can I ignore these sections and directly write the instructions for example start directly with addiu $sp,$sp,-48.

Can anyone explain these detailedly or just give me a link with detail explanation.

I am not familiar with MIPS. Thank you.

50u1w4y
  • 91
  • 1
  • 7
  • 3
    Related issue: https://stackoverflow.com/questions/730587/documentation-of-gnu-assembler-directives – Michael Apr 01 '20 at 06:00
  • 2
    Regarding `.set noreorder` and `.set nomacro`: They tell the assembler not to reorder instructions to fill branch delay slots, and to warn if pseudo-instructions are expanded into multiple real instructions. – Michael Apr 01 '20 at 06:01

0 Answers0