Address of a variable: Difference between revisions

Content added Content deleted
m (→‎{{header|J}}: Regularize non-standard header markup)
m (→‎{{header|Phix}}: added syntax colouring the hard way)
Line 1,229: Line 1,229:
compiler only omits the appropriate binary for the currently selected target architecture.
compiler only omits the appropriate binary for the currently selected target architecture.
You can also use allocate/free with peek/poke to obtain similar effects.
You can also use allocate/free with peek/poke to obtain similar effects.
<lang Phix>procedure address()
<!--<lang Phix>-->
<span style="color: #008080;">procedure</span> <span style="color: #000000;">address</span><span style="color: #0000FF;">()</span>
object V
<span style="color: #004080;">object</span> <span style="color: #000000;">V</span>
integer addr4 -- stored /4 (assuming dword aligned, which it will be)
<span style="color: #004080;">integer</span> <span style="color: #000000;">addr4</span> <span style="color: #000080;font-style:italic;">-- stored /4 (assuming dword aligned, which it will be)</span>
#ilASM{
#ilASM{
[32]
lea eax,[V]
[32]
shr eax,2
lea eax,[V]
mov [addr4],eax
shr eax,2
[64]
mov [addr4],eax
lea rax,[V]
[64]
shr rax,2
lea rax,[V]
mov [addr4],rax
shr rax,2
[]
mov [addr4],rax
}
[]
if machine_bits()=32 then
}
<span style="color: #008080;">if</span> <span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()=</span><span style="color: #000000;">32</span> <span style="color: #008080;">then</span>
poke4(addr4*4,123)
<span style="color: #000000;">poke4</span><span style="color: #0000FF;">(</span><span style="color: #000000;">addr4</span><span style="color: #0000FF;">*</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">123</span><span style="color: #0000FF;">)</span>
elsif machine_bits()=64 then
<span style="color: #008080;">elsif</span> <span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()=</span><span style="color: #000000;">64</span> <span style="color: #008080;">then</span>
poke8(addr4*4,123)
<span style="color: #000000;">poke8</span><span style="color: #0000FF;">(</span><span style="color: #000000;">addr4</span><span style="color: #0000FF;">*</span><span style="color: #000000;">4</span><span style="color: #0000FF;">,</span><span style="color: #000000;">123</span><span style="color: #0000FF;">)</span>
end if
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
?V
<span style="color: #0000FF;">?</span><span style="color: #000000;">V</span>
if getc(0) then end if
<span style="color: #008080;">if</span> <span style="color: #7060A8;">getc</span><span style="color: #0000FF;">(</span><span style="color: #000000;">0</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">then</span> <span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end procedure
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>

address()</lang>
<span style="color: #000000;">address</span><span style="color: #0000FF;">()</span>
<!--</lang>-->
{{out}}
{{out}}
<pre>
<pre>