【问题标题】:C function prototyping and .set directiveC 函数原型和 .set 指令
【发布时间】:2012-12-02 13:53:42
【问题描述】:

问题在 AVR GCC 上下文中。

我有一个带有 C 函数原型的 .s 文件,如下所示:

Mod_BigNum_by_u8: .global Mod_BigNum_by_u8 
; c-prototype ==> uint8_t Mod_BigNum_by_u8(uint8_t * pBigNum, uint8_t ByteCount, uint8_t Divisor); 

; Parameters 
    .set pBigNum, 24        ; (u16) pointer to the BigNum Dividend.  Highbyte first 
    .set ByteCount, 22      ; (u8) number of bytes in the BigNum 
    .set Divisor, 20        ; (u8) Divisor 

; Local Variables 
    .set BitCount, 23       ; (u8) Number of bits left in the current byte 
    .set CurrentByte, 21    ; (u8) Most recently used byte of BigNum 

; Return value 
    .set Dividend, 24       ; (u16) result (we only need 8bits, but WinAVR requires 16) 
... 

上述函数在 Atmel Studio 中运行良好(我猜不得不说“使用 avr-gcc 编译”)。

GNU asm syntax 
Syntax: .set symbol, expression 

AVR asm 
.SET label = expression 

这意味着使用了 GNU 语法。现在我想了解的是 - 这些常数 24、22、20 在 C 函数原型方面意味着什么?评论表明我正在加载函数参数,但我不明白 .set 和那些常量是如何发生的。我曾经认为参数是通过堆栈和寄存器传递的。

第二个问题 - 我知道 AVR asm 是从 GNU 派生的,但我真的可以像上面那样将 GNU asm 语法与 AVR asm 混合吗?

【问题讨论】:

    标签: assembly avr avr-gcc


    【解决方案1】:

    AVR 使用寄存器来传递前几个参数。请参阅description of the calling convention here

    寄存器在地址零处进行内存映射。因此,您在粘贴代码中看到的数字是等于寄存器编号的地址,可用于通过内存映射引用参数。

    【讨论】:

      猜你喜欢
      • 2011-06-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-06
      • 2014-10-01
      • 2012-07-15
      • 2016-02-08
      • 1970-01-01
      相关资源
      最近更新 更多