裸板开发_bootloader_开发之路(一)通过寄存器控制灯,寄存器变量

一、目的

1、本系列,基于ARM汇编语言系列,主要在汇编的基础上实现完整的bootloader程序。
2、只求将学习过程中的大致流程和遇到的问题发出来,大家一起探究一下。
3、本系列学习笔记,基于韦东山教程,有兴趣的可以看一下。
4、芯片为:s3c2440

二、前言

在单片机开发中,我们往往可以通过已经封装完整的函数来直接实现对GPIO的状态获取和高低电平设置,但是试想这些函数又是如何控制芯片发出正确的指令了?
答案就是,芯片通过对对应的寄存器的值进行设置来达到对应的目的。

三、资料解释

3.1 芯片手册的GPIO的控制寄存器:

在这里插入图片描述

3.2、寄存器变量

在c programing langage 中,寄存器变量定义如下:

4.7 Register Variables
A register declaration advises the compiler that the variable in question will be heavily used. The idea is that register variables are to be placed in machine registers, which may result in smaller and faster programs. But compilers are free to ignore the advice.
The register declaration looks like
register int x;
register char c;
and so on. The register declaration can only be applied to automatic variables and to the formal parameters of a function. In this later case, it looks like
f(register unsigned m, register long n)
{
register int i;
… }
In practice, there are restrictions on register variables, reflecting the realities of underlying hardware. Only a few variables in each function may be kept in registers, and only certain types are allowed. Excess register declarations are harmless, however, since the word register is ignored for excess or disallowed declarations. And it is not possible to take the address of a register variable (a topic covered in Chapter 5), regardless of whether the variable is actually placed in a register. The specific restrictions on number and types of register variables vary from machine to machine.

翻译过来,意思就是:寄存器变量用于定义那些需要被大量使用的变量。可以帮助实现那些更小和更快的项目,但是编译器可能会忽略这些定义。并且,低层机器的硬件情况也对寄存器变量有限制。只有少数变量可以保存在寄存器变量中, 而且,无论变量是否实际放置在寄存器中,都无法获取寄存器变量的地址(第5章中涉及的主题)。 寄存器变量的数量和类型的特定限制因计算机而异。

3.3、芯片寄存器头文件:

我一开始以为,__REG是寄存器变量的意思,后来一搜索发现,网上好像没有这个变量,我突然发现,这是自己的在头文件里面定义的取值宏定义

#define     __REG(x)					(*(volatile unsigned int *)(x)) 
#
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值