Passage of AVR GCC Function Parameters

passage

For the curious, below is the method and order that parameters are passed to and from functions in the 8-bit AVR GCC world. A description of the method is given here.


uint8_t func1(uint8_t a, uint8_t b, uint8_t c, uint8_t d) {
//do something here. . .
return 0x42;
}

uint32_t func2(uint32_t a, uint16_t b, uint8_t c) {
//do something here. . .
return 0x42;
}

int main(void) {
func1(1, 2, 3, 4);
func2(1, 2, 3);
return 0;
}

//
//Disassembly:
//

//funct1(1, 2, 3, 4);
ldi r18,0x04 ;d
ldi r20,0x03 ;c
ldi r22,0x02 ;b
ldi r24,0x01 ;a
jmp . . .
. . .
//return 0x42;
ldi r24,0x42
ret

//funct2(1, 2, 3);
ldi r18,0x03 ;c (uint8_t)
ldi r20,0x02 ;b (uint16_t)
ldi r21,0x00
ldi r22,0x01 ;a (uint32_t)
ldi r23,0x00
ldi r24,0x00
ldi r25,0x00
jmp . . .
. . .
ldi r22,0x42
ldi r23,0x00
ldi r24,0x00
ldi r25,0x00
ret

Advertisements

About Jim Eli

µC experimenter
This entry was posted in Uncategorized and tagged , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s