博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
The C Runtime Environment
阅读量:7081 次
发布时间:2019-06-28

本文共 2282 字,大约阅读时间需要 7 分钟。

hot3.png

 

We Are Not Alone

When you write your application in C, your code isn't the only thing that gets programmed into the PIC®microcontroller. Before your application can perform its first action, the C Runtime Environment startup code must configure the device to run code produced by a C compiler.

Purpose of the C Runtime Environment

There are several things the C Runtime Environment startup code must do before your application's code can run.

  • Allocate space for a software stack and initialize the stack pointer
    On 8-bit devices that have a hardware based return address stack, the software stack is mostly used for parameter passing to and from functions. On 16- and 32-bit devices the software stack also stores the return address for each function call and interrupt.
  • Allocate space for a heap (if used)
    A heap is a block of RAM that has been set aside as a sort of scratchpad for your application. C has the ability to dynamically create variables at runtime. This is done in the heap.
  • Copy values from Flash into variables declared with initial values
    Variables declared with initial values (e.g. int x=10;) must have those initial values loaded into memory before the program can use them. The initial values are stored in flash program memory (so they will be available after the device is power cycled) and are copied into each RAM location allocated to an initialized variable for its storage.
  • Clear uninitialized RAM
    Any RAM (file register) not allocated to a specific purpose (variable storage, stack, heap, etc.) is cleared so that it will be in a known state.
  • Disable all interrupts
  • Call main(), where your application code starts

Working With the C Runtime Environment

The runtime environment setup code is automatically linked into your application. It usually comes from a file with a name like crt0.s (assembly source) or crt0.o (object code).

The runtime startup code can be modified if necessary. In fact, the source file provides hooks for "user initialization" where you can run code that must execute before the main application begins, such as initializing some external hardware immediately after power is applied. Details on runtime startup code modification will be covered in the compiler specific classes.

转载于:https://my.oschina.net/u/2308739/blog/737024

你可能感兴趣的文章
私有云桌面和公有云桌面的区别是什么
查看>>
ipmotool
查看>>
国家级期刊投稿要求
查看>>
mpls的基础原理
查看>>
大数据开发零基础需要学习什么内容?(1)Java、大数据基础
查看>>
SecureCRT教程——如何使用SecureCRT命令窗口将命令发送到多个会话
查看>>
php 字符串写入文件或追加入文件
查看>>
Reporting Server IIS Log
查看>>
linux和windows软件收集
查看>>
javascript-放大镜
查看>>
SQL-31 获取select * from employees对应的执行计划
查看>>
LAMP攻略: LAMP环境搭建,Linux下Apache,MySQL,PHP安装与配置
查看>>
怎么让XP屏保图片显示为全屏
查看>>
用border画图
查看>>
window活动目录——操作主机
查看>>
Java内存解析
查看>>
fckeditor jsp配置
查看>>
.每隔5秒查看hadoop用户是否登录,如果登录,显示其登录并退出;否则,显示当前时间,并说明hadoop尚未登录...
查看>>
LVS集群的基本原理、LVS/NAT模式的配置、LVS/DR模式的配置、编写自动脚本检查LVS上realserver健康性...
查看>>
A very hard Aoshu problem
查看>>