Unexpected MIPS assembly output

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Apologies if I am missing something obvious, but I cannot understand why I am getting the following assembler output from gcc.

Taking the following C function

int myadd(int a, int b)
{
    return a + b;
}

I compile with

mips-linux-gnu-gcc -S test.c

and the resulting assembly code is

        .file   1 "test.c"
        .section .mdebug.abi32
        .previous
        .nan    legacy
        .module fp=32
        .module oddspreg
        .abicalls
        .option pic0
        .text
        .align  2
        .globl  myadd
        .set    nomips16
        .set    nomicromips
        .ent    myadd
        .type   myadd, @function
myadd:
.frame $fp,8,$31 # vars= 0, regs= 1/0, args= 0, gp= 0
        .mask   0x40000000,-4
        .fmask  0x00000000,0
        .set    noreorder
        .set    nomacro
        addiu   $sp,$sp,-8
        sw      $fp,4($sp)
        move    $fp,$sp
        sw      $4,8($fp)
        sw      $5,12($fp)
        lw      $3,8($fp)
        lw      $2,12($fp)
        addu    $2,$3,$2
        move    $sp,$fp
        lw      $fp,4($sp)
        addiu   $sp,$sp,8
        j       $31
        nop

        .set    macro
        .set    reorder
        .end    myadd
        .size   myadd, .-myadd
        .ident  "GCC: (Sourcery CodeBench Lite 2015.11-32) 5.2.0"


What I do not understand is the use of the stack. The stack pointer is being moved by 8, so I would expect the code to use 0($sp) and 4($sp), but it uses 4, 8 and 12, which would appear to be in the callers stack frame?

Grateful for any guidance,
Nathan



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux