<div dir="ltr">Similar to bif0...bif3 gc_bifN uses import index from the import table. Import table contains triples {Mod, Fun, Arity} for external functions used in the current module:<div><br><div><a href="http://beam-wisdoms.clau.se/en/latest/indepth-beam-instructions.html#bif1-11-bif2-152-bif3">http://beam-wisdoms.clau.se/en/latest/indepth-beam-instructions.html#bif1-11-bif2-152-bif3</a><br></div></div><div><br></div><div>So Bif=00 is the 0th index in the import table.</div><div><br></div><div><a href="http://beam-wisdoms.clau.se/en/latest/indepth-beam-file.html#impt-imports-table">http://beam-wisdoms.clau.se/en/latest/indepth-beam-file.html#impt-imports-table</a><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-09-14 23:16 GMT+02:00 Gabriel Rivas <span dir="ltr"><<a href="mailto:gabriel.alberto.rivas@gmail.com" target="_blank">gabriel.alberto.rivas@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><span style="font-size:12.8px">Hello all,</span><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">I am trying to understand BEAM files most specifically the Code section.</div><div style="font-size:12.8px">For that objective I wrote a simple program consisting of just a subtraction function </div><div style="font-size:12.8px">taking 2 parameters:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div style="font-size:12.8px">-module(ex3).</div><div style="font-size:12.8px">-export([sub/2]).</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">sub(X,Y) -></div><div style="font-size:12.8px"> X-Y.</div></div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">From that file I created the .S version, and I can see that the assembly</div><div style="font-size:12.8px">version for the subtraction is:</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px"><div style="font-size:12.8px">{gc_bif,'-',{f,0},2,[{x,0},{x,<wbr>1}],{x,0}}. </div><div style="font-size:12.8px"> return.</div><div style="font-size:12.8px"><br></div><div style="font-size:12.8px">In the BEAM file I can see that the bytecode part that correlated with this</div><div style="font-size:12.8px">function is (in hex numbers):</div><div style="font-size:12.8px"><br></div><div><span style="font-size:12.8px">7D 05 20 00 03 13 03 13</span><br></div></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">After some reading of the BEAM book and some analysis, I could translate</span></div><div style="font-size:12.8px"><span style="font-size:12.8px">these hex numbers to:</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><div><span style="font-size:12.8px">7D 05 20 = {gc_bif2,</span></div><div><span style="font-size:12.8px"> Lbl = 05,</span></div><div><span style="font-size:12.8px"> Live X registers = 2,</span></div><div><span style="font-size:12.8px"> Bif = 00,</span></div><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">03 13 03 13 = args: X0,X1</span></div><div><span style="font-size:12.8px"> return: X0</span></div><div><span style="font-size:12.8px"> 13 -> k_return</span></div></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">But I still don't see how the subtraction happens. Can anybody shed some light</span></div><div style="font-size:12.8px"><span style="font-size:12.8px">on the internals of calling a BIF in the erlang module?</span></div><div style="font-size:12.8px"><span style="font-size:12.8px"><br></span></div><div style="font-size:12.8px"><span style="font-size:12.8px">Regards,</span></div><div style="font-size:12.8px"><span style="font-size:12.8px">Gabriel</span></div></div>
<br>______________________________<wbr>_________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/<wbr>listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div>