Machine code: Difference between revisions

m
→‎{{header|Phix}}: added personal tag and a more natural way to do it.
(Added Wren)
m (→‎{{header|Phix}}: added personal tag and a more natural way to do it.)
Line 746:
 
=={{header|Phix}}==
Phix has a builtin assembler, which makes the specifics of this task "the hard way to do it".
<!--<lang Phix>-->
<!--<lang Phix>(notonline)-->
<span style="color: #004080;">atom</span> <span style="color: #000000;">mem</span> <span style="color: #0000FF;">=</span> <span style="color: #000000;">allocate</span><span style="color: #0000FF;">(</span><span style="color: #000000;">9</span><span style="color: #0000FF;">)</span>
<span style="color: #000000;">poke</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mem</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">#8B</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#44</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#24</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#04</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#03</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#44</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#24</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#08</span><span style="color: #0000FF;">,</span><span style="color: #000000;">#C3</span><span style="color: #0000FF;">})</span>
Line 768 ⟶ 769:
<span style="color: #000000;">free</span><span style="color: #0000FF;">(</span><span style="color: #000000;">mem</span><span style="color: #0000FF;">)</span>
<!--</lang>-->
Better yet, albeit perhaps deviating somewhat from the task, but adhering in spirit, (and thisunlike runsthe above runnable on both 32 and 64 bit):<br><small>(Were you to produce a list.asm from this, using p -d, it would show the x86 bytes above or the x64 equivalent, using a mix of octal and hex representations)</small>
<!--<lang Phix>-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">res</span>
Line 795 ⟶ 796:
<span style="color: #0000FF;">?</span><span style="color: #000000;">res</span>
<!--</lang>-->
In practice I would omit the jmp/labels/call/ret and probably just use registers instead of the stack:
All three cases output 19
<!--<lang Phix>-->
<span style="color: #004080;">integer</span> <span style="color: #000000;">res</span>
#ilASM{
[32]
mov eax,12
mov edx,7
add eax,edx
mov [res],eax
[64]
mov rax,12
mov rdx,7
add rax,rdx
mov [res],rax
[]
}
<span style="color: #0000FF;">?</span><span style="color: #000000;">res</span>
<!--</lang>-->
All threefour cases output 19
 
=={{header|PicoLisp}}==
7,818

edits