Sign in Join

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

Mailing lists / fpc-pascal / 2012-06

asm statement

5 messages · 4 people ·

Reply by email Subscribe to this list Your subscription

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

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' ... ];

Rainer Stratmann
to leledumbo
leledumbo wrote 8 lines
> 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)

Alexander Shishkin
to Rainer Stratmann

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

Show quoted text 18 lines
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 - http://lists.freepascal.org/mailman/listinfo/fpc-pascal

This is described in PFC documentation: Programmer`s guide, ch 3.4 "Signaling changed registers".

Jonas Maebe
to Rainer Stratmann: Is it still necessary to fill in the registers at the end of a asm statement? What…
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