搜索
bottom↓
回复: 6

bootload程序的求教

[复制链接]

出0入0汤圆

发表于 2012-4-16 15:57:00 | 显示全部楼层 |阅读模式
刚刚接触BOOT LOAD这一块, 照例看了马潮老师的教程, 但以前没接触汇编, 有几句看不懂,
附上原文的一部分
void boot_page_ew(long p_address,char code)
{
      asm("mov r30,r16\n"
               "mov r31,r17\n"
               "out 0x3b,r18\n"); //将页地址放入Z寄存器和RAMPZ的Bit0中
      SPMCSR = code; //寄存器SPMCSR中为操作码
      asm("spm\n"); //对指定Flash页进行操作
}
//填充Flash缓冲页中的一个字
void boot_page_fill(unsigned int address,int data)
{
      asm("mov r30,r16\n"
                "mov r31,r17\n" //Z寄存器中为填冲页内地址
                "mov r0,r18\n"
                "mov r1,r19\n"); //R0R1中为一个指令字
      SPMCSR = 0x01;
      asm("spm\n");
}
估计很多人使用过这代码, 请问一下朋友们, mov r30,r16\n",  mov r31,r17\n",out 0x3b,r18\n" 这三句,是说将实参值传递到R30,R31,0x3b。 是怎么确定实参值在r16,r17,r18寄存器中,
还有就是    out 0x3b,r18\n"); //将页地址放入Z寄存器和RAMPZ的Bit0中   这句,不懂什么意思, 我看过ATmega32的数据手册,没找到RAMPZ是什么。 希望高手们解答, 非常感谢

出0入0汤圆

发表于 2012-4-16 19:46:29 | 显示全部楼层
1.M32是没有RAMPZ的。这段代码是应用于M128的。
2.实参值传递到R30,R31,0x3b,这个与你使用的编译器有关。这段是针对使用icc编译器的,使用其它的C,可能就需要变化。要知道为什么,需要认真仔细的学习ICC的HELP文件。当然,你必须具备看的懂的基础。

加油吧,小兄弟。先打好基础。

出0入0汤圆

 楼主| 发表于 2012-4-17 11:41:50 | 显示全部楼层
没想到能得到马老师的亲自回复, 用ICCAVR也有一段时间了。 还从没看过帮助文件, 主要是E文不行, 现在工作太忙了,好多东西都不能仔细的研究了。经马老师指点,不胜感激。

出0入0汤圆

发表于 2012-4-17 19:51:21 | 显示全部楼层
如果你想吃技术这口饭,E文不行, 工作太忙就都是借口。下面是从ICCAVR的HELP中摘录的说明,英文好的,有时间的,也不一定都能明白什么意思。所以我说“必须具备看的懂的基础”。这个基础不是肤浅的指E文好,肯花时间,而是更深一个层次的基础。

Assembly Interface and Calling Conventions

Argument and Return Registers

The first argument is passed in registers R16/R17 if it is an integer and R16/R17/R18/R19 if it is a long or floating point. The second argument is passed in R18/R19 if available. All other remaining arguments are passed on the software stack.

Integer arguments smaller than ints (i.e. char) are not extended to in IF the function prototype is available. If registers are used to pass byte arguments, it will use both registers but the higher register is undefined. For example, if the first argument is a byte, both R16/R17 will be used with R17 being undefined. Byte arguments passed on the software stack take up only a single byte. In the future release, byte arguments passed in registers will be packed tightly.

If R16/R17 is used to pass the first argument and the second argument is a long or float, the lower half of the second argument is passed in R18/R19 and the upper half is passed on the software stack.

Integer values are returned in R16/R17 and longs and floats are returned in R16/R17/R18/R19. Byte values are returned in R16 with R17 undefined.

出0入0汤圆

发表于 2012-7-16 17:24:50 | 显示全部楼层
同样受教了!

出0入0汤圆

发表于 2014-4-27 21:08:41 | 显示全部楼层
路过路过了  顺便看看

出0入0汤圆

发表于 2016-4-18 16:56:25 | 显示全部楼层
E文不好,说多了都是累啊
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-4-19 07:21

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表