Calling Convention

The Caller

The Caller pushes the Arguments on the Stack in Order.

The Callee

The Callee then must pop them into registers in reverse Order. That happens before anything else in the Callee.

Example - IR

TAC_CONST_VALUE t1 = 19
TAC_PARAM t1
TAC_CONST_VALUE t2 = 24
TAC_PARAM t2
TAC_CALL myfunction
TAC_RETURN t2
----------------
TAC_CONST_VALUE t0 = 0
TAC_RETURN t0

Example - AVR Assembler

main:
ldi r16, 19
push r16
ldi r16, 24
push r16
call myfunction
mov r0, r16
ret

myfunction:
pop r17
pop r18
ret