asm statement

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

asm statement

Rainer Stratmann
Is it still necessary to fill in the registers at the end of a asm statement?
What happens if there is only the end; statement without the used registers?

asm
 mov eax , ebx
end ['EAX' , 'EBX' ... ];
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: asm statement

leledumbo
Administrator
> What happens if there is only the end; statement without the used registers?

The compiler couldn't save the values in the registers prior to the asm block. If they contain intermediate result, they may be gone and unexpected result would come. CMIIW.
Reply | Threaded
Open this post in threaded view
|

Re: asm statement

Rainer Stratmann
Am Tuesday 12 June 2012 18:44:20 schrieb leledumbo:
> > What happens if there is only the end; statement without the used
>
> registers?
>
> The compiler couldn't save the values in the registers prior to the asm
> block. If they contain intermediate result, they may be gone and unexpected
> result would come. CMIIW.
>
Here there is no such mentioning of the used registers in the asm statement.
http://wiki.freepascal.org/Lazarus_Inline_Assembler
(last modified on 24 March 2012)

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: asm statement

Alexander Shishkin
12.06.2012 23:23, Rainer Stratmann пишет:

> Am Tuesday 12 June 2012 18:44:20 schrieb leledumbo:
>>> What happens if there is only the end; statement without the used
>>
>> registers?
>>
>> The compiler couldn't save the values in the registers prior to the asm
>> block. If they contain intermediate result, they may be gone and unexpected
>> result would come. CMIIW.
>>
> Here there is no such mentioning of the used registers in the asm statement.
> http://wiki.freepascal.org/Lazarus_Inline_Assembler
> (last modified on 24 March 2012)
>
> _______________________________________________
> fpc-pascal maillist  -  [hidden email]
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
>
This is described in PFC documentation: Programmer`s guide, ch 3.4
"Signaling changed registers".

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: asm statement

Jonas Maebe-2
In reply to this post by Rainer Stratmann

On 12 Jun 2012, at 18:41, Rainer Stratmann wrote:

> Is it still necessary to fill in the registers at the end of a asm statement?

Yes.

> What happens if there is only the end; statement without the used registers?

Then the compiler will assume that the assembler code can change all callee-saved registers for the current target platform, and that it will not modify any caller-saved registers. If you don't know what the callee/caller-saved registers of all of your current and future supported target platforms are (possibly even targets that do not yet exist), or if you simply don't want the compiler to needlessly save and restore all callee-saved registers even when you don't modify them (it would be rather strange to resort to assembler and then force the compiler to generate suboptimal code), then you should specify the registers that are overwritten by your assembler code.

And no, the compiler cannot automagically figure this out for you. It does not contain an abstract interpretation infrastructure for assembler that can determine what registers are changed and not saved/restored by the code, neatly sidestepping the halting problem in the process. Anything less would result in a lot of work with either only suboptimal or unsafe results.


Jonas_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/mailman/listinfo/fpc-pascal