RE: Unexpected MIPS assembly output

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

 



Nathan Cole <nath@xxxxxxxxxxxxxxxxxxxxxx> writes:
> 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?

Hi Nathan,

This is part of the o32 MIPS ABI. There is a minimum 16-byte argument
area on the stack for any call even if all arguments are passed in registers.
This stack space is used to spill arguments instead of creating new stack
slots in the caller's frame.

Take a look at the mipsabi.pdf found here for more details although it is
a tough read:

https://dmz-portal.mips.com/wiki/MIPS_ABI_Project#Where_are_the_current_and_historical_MIPS_ABI_related_documents

Hope that helps,
Matthew




[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