sparc v8 stack frame

main.c

int enable=1;

int main()
{
    int a, b;
    int sum;

    a = 1;
    b = 3;

    sum = add(a, b);

    return 0;
}

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

int del()
{
    return 0;
}

汇编如下:

main.elf:     file format elf32-sparc

Disassembly of section .text:

70000000 <main>:
70000000:    9d e3 bf 88     save  %sp, -120, %sp
70000004:    90 10 20 01     mov  1, %o0
70000008:    d0 27 bf f4     st  %o0, [ %fp + -12 ]
7000000c:    90 10 20 03     mov  3, %o0
70000010:    d0 27 bf f0     st  %o0, [ %fp + -16 ]
70000014:    d0 07 bf f4     ld  [ %fp + -12 ], %o0
70000018:    d2 07 bf f0     ld  [ %fp + -16 ], %o1
7000001c:    40 00 00 08     call  7000003c <add>
70000020:    01 00 00 00     nop
70000024:    d0 27 bf ec     st  %o0, [ %fp + -20 ]
70000028:    90 10 20 00     clr  %o0
7000002c:    b0 10 00 08     mov  %o0, %i0
70000030:    01 00 00 00     nop
70000034:    81 c7 e0 08     ret
70000038:    81 e8 00 00     restore 

7000003c <add>:
7000003c:    9d e3 bf 98     save  %sp, -104, %sp
70000040:    f0 27 a0 44     st  %i0, [ %fp + 0x44 ]
70000044:    f2 27 a0 48     st  %i1, [ %fp + 0x48 ]
70000048:    f2 07 a0 44     ld  [ %fp + 0x44 ], %i1
7000004c:    f0 07 a0 48     ld  [ %fp + 0x48 ], %i0
70000050:    b0 06 40 18     add  %i1, %i0, %i0
70000054:    01 00 00 00     nop
70000058:    81 c7 e0 08     ret
7000005c:    81 e8 00 00     restore 

70000060 <del>:
70000060:    9d e3 bf 98     save  %sp, -104, %sp
70000064:    b0 10 20 00     clr  %i0
70000068:    01 00 00 00     nop
7000006c:    81 c7 e0 08     ret
70000070:    81 e8 00 00     restore
Disassembly of section .data:

70000074 <enable>:
70000074:    00 00 00 01     unimp  0x1

1、3个局部变量,共12字节,按照8字节对齐,需要16字节,即104+16=120

70000000: 9d e3 bf 88 save  %sp, -120, %sp

2、main.c将局部变量a,b分配在%fp + -12,%fp + -16

70000004:    90 10 20 01     mov  1, %o0
70000008:    d0 27 bf f4     st  %o0, [ %fp + -12 ]
7000000c:    90 10 20 03     mov  3, %o0
70000010:    d0 27 bf f0     st  %o0, [ %fp + -16 ]

3、将输入参数放在o0和o1中,然后调用add

70000014:    d0 07 bf f4     ld  [ %fp + -12 ], %o0
70000018:    d2 07 bf f0     ld  [ %fp + -16 ], %o1
7000001c:    40 00 00 08     call  7000003c <add>

4、将局部变量sum,放在%fp + -20,调用结束,从o0取得add的返回值。

70000024:    d0 27 bf ec     st  %o0, [ %fp + -20 ]

5、add将输入参数放在%fp + 0x44,%fp + 0x48,这是为什么?0x44=68, 0x48=72

70000040:    f0 27 a0 44     st  %i0, [ %fp + 0x44 ]
70000044:    f2 27 a0 48     st  %i1, [ %fp + 0x48 ]

add函数里的%fp + 0x44感觉又到了main的堆栈里了,这是怎么回事?

原文地址:https://www.cnblogs.com/yanhc/p/12312905.html

时间: 2024-08-14 23:45:34

sparc v8 stack frame的相关文章

How a stack frame works 栈帧

http://en.citizendium.org/wiki/Stack_frame To use a stack frame, a thread keeps two pointers, often called the Stack Pointer (SP), and the Frame (FP) or Base Pointer (BP). SP always points to the "top" of the stack, and FP always points to the &

PHP错误: Exception thrown without a stack frame in Unknown on line 0[转载]

来自:网易博客 就目前我的了解,在两种情况下,PHP会报 Exception thrown without a stack frame in Unknown on line 0这种错误: 1)异常捕捉用了set_exception_handler导向,Exception里面执行另一个Exception 如下面这段代码,就会出现这种问题: http://de.php.net/manual/de/function.set-exception-handler.php#88082 function er

Stack frame

http://en.citizendium.org/wiki/Stack_frame In computer science, a stack frame is a memory management strategy used to create and destroy temporary (automatic) variables in some programming languages. Among other things, use of a stack allows programm

stack frame in memory(一)

The content of this article is from Assembly Language For x86 Processors Sixth Edition By Kip R.Irvine,appended with some understanding of myself. 1.Stack Parameters 1.1    Contrast register parameters with stack parameters: 1.2    Two general types

ARM处理器的堆栈和函数调用,以及与Sparc的比较

主要内容来自以下网址.该网站是个学习ARM汇编的好地方.计划将该篇文章翻译过来,并和Sparc对比. https://azeria-labs.com/functions-and-the-stack-part-7/ ARM和Sparc比较 之前整理的Sparc的原理,Sparc V8 汇编指令.寄存器窗口.堆栈.函数调用,https://www.cnblogs.com/yanhc/p/12255886.html 关于函数调用的跳转执行 ARM跳转有BL指令,Branch Link(Saves (P

【转】iOS:堆(heap)和栈(stack)的理解--简介

Objective-C的对象在内存中是以堆的方式分配空间的,并且堆内存是由你释放的,即release 栈由编译器管理自动释放的,在方法中(函数体)定义的变量通常是在栈内,因此如果你的变量要跨函数的话就需要将其定义为成员变量. 1.栈区(stack):由编译器自动分配释放,存放函数的参数值,局部变量等值.其操作方式类似于数据结构中的栈. 2.堆区(heap):一般由程序员分配释放,若程序员不释放,则可能会引起内存泄漏.注堆和数据结构中的堆栈不一样,其类是与链表. 操作系统iOS 中应用程序使用的计

C# Heap(ing) Vs Stack(ing) in .NET [C# 堆和栈的使用以及垃圾回收原理]

最近在<C#Corner>上看到了一篇关于.NET内存管理以及垃圾回收的文章,虽说是英文的内容,但还是硬着头皮读了下来.发现并不是我原本想象中的那么枯燥,因为语言通俗而且还有很多图片示意,感觉让我又对"堆"和"栈"以及垃圾回收机制有了更加深刻的理解和认知,记录下来提醒自己尽量书写优质的代码,而不是只管实现功能,不管性能优劣去蛮干.  [文章出自: http://www.c-sharpcorner.com/article/c-sharp-heaping-v

iOS:堆(heap)和栈(stack)的理解

Object-c的对象在内存中是以堆的方式分配内存空间的,并且堆内存是由你释放的,即release 1.栈区(stack):由编译器自动分配释放,存放函数的参数值,局部变量等值.其操作方式类似于数据结构中的栈. 2.堆区(heap):一般由程序员分配释放,若程序员不释放,则可能会引起内存泄漏.注堆和数据结构中的堆栈不一样,其类是与链表. 操作系统iOS 中应用程序使用的计算机内存不是统一分配空间,运行代码使用的空间在三个不同的内存区域,分成三个段:"text segment ",&qu

JVM -Xss调整Stack Space的大小 【转】

Java程序中,每个线程都有自己的Stack Space.这个Stack Space不是来自Heap的分配.所以Stack Space的大小不会受到-Xmx和-Xms的影响,这2个JVM参数仅仅是影响Heap的大小. Stack Space用来做方法的递归调用时压入Stack Frame.所以当递归调用太深的时候,就有可能耗尽Stack Space,爆出StackOverflow的错误.Stack Space的大小随着OS,JVM以及环境变量的大小而发生变化.一般说来默认的大小是512K.在64