夜郎 发表于 2012-4-16 15:57:00

bootload程序的求教

刚刚接触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是什么。 希望高手们解答, 非常感谢

machao 发表于 2012-4-16 19:46:29

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

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

夜郎 发表于 2012-4-17 11:41:50

没想到能得到马老师的亲自回复, 用ICCAVR也有一段时间了。 还从没看过帮助文件, 主要是E文不行, 现在工作太忙了,好多东西都不能仔细的研究了。经马老师指点,不胜感激。

machao 发表于 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.

longwu537 发表于 2012-7-16 17:24:50

同样受教了!

xuanfong1 发表于 2014-4-27 21:08:41

路过路过了顺便看看

robotway 发表于 2016-4-18 16:56:25

E文不好,说多了都是累啊
页: [1]
查看完整版本: bootload程序的求教