<div dir="ltr">Hi Karol and thanks you very much! I got confused with the function names, I feel very sorry.<div>As I said in my previous email, I fixed by rewriting the assembler function. However, I don't why it worked. </div><div>So I understand you correctly, if I use assembler in my procedures there could be a risk that I trash a variable that the compiler is using. Is the compiler warning me about this? </div><div><br></div><div>Matias  </div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-01-10 17:14 GMT+01:00 Karoly Balogh (Charlie/SGR) <span dir="ltr"><<a href="mailto:charlie@scenergy.dfmk.hu" target="_blank">charlie@scenergy.dfmk.hu</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<span class=""><br>
On Wed, 10 Jan 2018, Matias Vara wrote:<br>
<br>
> I am getting an exception when I enable the -O2 optimization. More<br>
> precisaily, the line that stars with write_portd.... is corrupting the<br>
> data section. This is the pascal code: <br>
><br>
> function PciReadDword(const bus, device, func, regnum: UInt32): UInt32;<br>
> var<br>
>   Send: DWORD;<br>
> begin<br>
>   Send := $80000000 or (bus shl 16) or (device shl 11) or (func shl 8) or (regnum shl 2);<br>
>   write_portd(@Send, PCI_CONF_PORT_INDEX);<br>
>   read_portd(@Send, PCI_CONF_PORT_DATA);<br>
>   Result := Send;<br>
> end;  <br>
><br>
> which generates (without -02):<br>
><br>
> .section .text.n_arch_$$_pcireaddword$<wbr>longword$longword$longword$<wbr>longword$$longword,"x"<br>
> .balign 16,0x90<br>
> .globl ARCH_$$_PCIREADDWORD$LONGWORD$<wbr>LONGWORD$LONGWORD$LONGWORD$$<wbr>LONGWORD<br>
> ARCH_$$_PCIREADDWORD$LONGWORD$<wbr>LONGWORD$LONGWORD$LONGWORD$$<wbr>LONGWORD:<br>
><br>
</span>> (***shipp***)<br>
<span class="">><br>
> and with -O2:<br>
><br>
> .section .text.n_arch_$$_pciwriteword$<wbr>word$word$word$word$word,"x"<br>
> .balign 16,0x90<br>
> .globl ARCH_$$_PCIWRITEWORD$WORD$<wbr>WORD$WORD$WORD$WORD<br>
> ARCH_$$_PCIWRITEWORD$WORD$<wbr>WORD$WORD$WORD$WORD:<br>
><br>
</span><span class="">> The first thing that I realize was the the optimized version is not<br>
> generating the correct source when is exiting since it should return<br>
> "Send", but am I right? The assembler code of write_portd remains the<br>
> same, Am I missing something? <br>
<br>
</span>The -O2 version of the function you sent is from a different one, it's<br>
from a Write function, not a Read... So no wonder it doesn't return<br>
anything... :)<br>
<br>
BTW, -O2 uses register variables, while -O- doesn't. If your assembler<br>
trashes one of them without preserving one, it can lead to crashes...<br>
But there could be many other reasons.<br>
<br>
Without seeing the actual assembler functions it's hard to tell.<br>
<span class="HOEnZb"><font color="#888888"><br>
Charlie</font></span><br>______________________________<wbr>_________________<br>
fpc-pascal maillist  -  <a href="mailto:fpc-pascal@lists.freepascal.org">fpc-pascal@lists.freepascal.<wbr>org</a><br>
<a href="http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal" rel="noreferrer" target="_blank">http://lists.freepascal.org/<wbr>cgi-bin/mailman/listinfo/fpc-<wbr>pascal</a><br></blockquote></div><br></div>