Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2017-12

AVR calling convention for shortstring result type

3 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Christo

I'm trying to write an assembler function to read a string from program memory using LPM and return a shortstring result.  Consider the following prototype function:

function readProgmemStr(constref s: shortstring): shortstring;

It appears from the generated code as if the function result location is assigned before the function is called, with the reference to the function result passed as first parameter (in R24:R25) and the reference to s passed as the second parameter (in R22:R23). Is this indeed the current parameter handling for shortstring function result type?

If so it probably warrants a mention on the AVR wiki page.  Are there any other data types that deviates from the GCC AVR calling convention in this way?

Reply by email

Florian Klämpfl
to Christo
Christo wrote 9 lines
I'm trying to write an assembler function to read a string from program memory using LPM and return a shortstring result.  Consider the following prototype function: function readProgmemStr(constref s: shortstring): shortstring; It appears from the generated code as if the function result location is assigned before the function is called, with the reference to the function result passed as first parameter (in R24:R25) and the reference to s passed as the second parameter (in R22:R23). Is this indeed the current parameter handling for shortstring function result type?

Yes.

If so it probably warrants a mention on the AVR wiki page.  Are there any other data types that deviates from the GCC AVR calling convention in this way?

Where do the GCC AVR calling say something about how to pass shortstrings? FPC always use a first "hidden" parameter to pass e.g. pointers to storage space for data types not being returned in registers.

Reply by email

Christo Crause
to Florian Klämpfl
"Florian Klämpfl" wrote
Am 11.12.2017 um 21:58 schrieb Christo: > It appears from the generated code as if the function result location

is assigned before the

> function is called, with the reference to the function result passed as

first parameter (in

> R24:R25) and the reference to s passed as the second parameter (in

R22:R23). Is this indeed the

Show quoted text 6 lines
> current parameter handling for shortstring function result type? Yes. > > If so it probably warrants a mention on the AVR wiki page. Are there

any other data types that

> deviates from the GCC AVR calling convention in this way? Where do the GCC AVR calling say something about how to pass

shortstrings? FPC always use a first

"hidden" parameter to pass e.g. pointers to storage space for data types

not being returned in

registers.

Thanks Florian. First time I'm working with more complex data in assembly, so it's a concept that is new to me.

Reply by email