0

Question is in AVR GCC context.

I have .s file with C function prototype as follows:

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) 
... 

Above function works fine in Atmel Studio (I guess have to say "compiling with avr-gcc").

GNU asm syntax 
Syntax: .set symbol, expression 

AVR asm 
.SET label = expression 

It means GNU syntax is used. Now what I am trying to understand is - what are those constants 24, 22, 20 means in terms of C function prototyping? Comments are suggesting that I'm loading function arguments, but I don't understand how with .set and those constants it happens. I used to think that params are passed through stack and registers.

Secondary question - I know AVR asm is derived from GNU but can I really mix GNU asm syntax with AVR asm as above?

Pablo
  • 28,133
  • 34
  • 125
  • 215

1 Answers1

0

AVR uses registers for passing the first few arguments. See the description of the calling convention here.

The registers are memory-mapped at address zero. As such, the numbers you see in the pasted code are addresses that equal register numbers and can be used to reference the arguments through the memory mapping.

Jester
  • 56,577
  • 4
  • 81
  • 125