about summary refs log tree commit diff stats
path: root/html/subx/apps/factorial.subx.html
diff options
context:
space:
mode:
authorKartik Agaram <vc@akkartik.com>2018-09-07 22:42:23 -0700
committerKartik Agaram <vc@akkartik.com>2018-09-07 22:42:23 -0700
commitc762564bd754884e847922c99172076fde4d646e (patch)
tree52b51d72a8e0bf29c94f5c01c13f098399830082 /html/subx/apps/factorial.subx.html
parent1a62e61df42bfdf001010700c1e1042c67d62ec2 (diff)
downloadmu-c762564bd754884e847922c99172076fde4d646e.tar.gz
4539
Diffstat (limited to 'html/subx/apps/factorial.subx.html')
-rw-r--r--html/subx/apps/factorial.subx.html60
1 files changed, 29 insertions, 31 deletions
diff --git a/html/subx/apps/factorial.subx.html b/html/subx/apps/factorial.subx.html
index c695cb3c..1fa6a4e3 100644
--- a/html/subx/apps/factorial.subx.html
+++ b/html/subx/apps/factorial.subx.html
@@ -63,7 +63,7 @@ if ('onhashchange' in window) {
 <span id="L7" class="LineNr"> 7 </span><span class="Comment">#   $ echo $?</span>
 <span id="L8" class="LineNr"> 8 </span><span class="Comment">#   120</span>
 <span id="L9" class="LineNr"> 9 </span>
-<span id="L10" class="LineNr">10 </span>== <a href='031check_operands.cc.html#L14'>code</a>
+<span id="L10" class="LineNr">10 </span>== code
 <span id="L11" class="LineNr">11 </span><span class="Comment"># instruction                     effective address                                                   operand     displacement    immediate</span>
 <span id="L12" class="LineNr">12 </span><span class="Comment"># op          subop               mod             rm32          base        index         scale       r32</span>
 <span id="L13" class="LineNr">13 </span><span class="Comment"># 1-3 bytes   3 bits              2 bits          3 bits        3 bits      3 bits        2 bits      2 bits      0/1/2/4 bytes   0/1/2/4 bytes</span>
@@ -88,36 +88,34 @@ if ('onhashchange' in window) {
 <span id="L32" class="LineNr">32 </span>
 <span id="L33" class="LineNr">33 </span><span class="Comment"># factorial(n)</span>
 <span id="L34" class="LineNr">34 </span>factorial:
-<span id="L35" class="LineNr">35 </span>  <span class="Comment"># initialize n</span>
-<span id="L36" class="LineNr">36 </span>  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              2/r32/EDX   4/disp8        <span class="Delimiter"> . </span>                <span class="Comment"># copy *(ESP+4) to EDX</span>
-<span id="L37" class="LineNr">37 </span>  <span class="Comment"># initialize EAX to 1 (base case)</span>
-<span id="L38" class="LineNr">38 </span>  b8/copy                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>              1/imm32           <span class="Comment"># copy 1 to EAX</span>
-<span id="L39" class="LineNr">39 </span>  <span class="Comment"># if (n &lt;= 1) jump exit</span>
-<span id="L40" class="LineNr">40 </span>  81          7/subop/compare     3/mod/direct    2/rm32/EDX   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>              1/imm32           <span class="Comment"># compare EDX with 1</span>
-<span id="L41" class="LineNr">41 </span>  7e/jump-if-&lt;=                  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>          $factorial:exit/disp8             <span class="Comment"># jump if &lt;= to $factorial:exit</span>
-<span id="L42" class="LineNr">42 </span>  <span class="Comment"># EBX: n-1</span>
-<span id="L43" class="LineNr">43 </span>  89/copy                         3/mod/direct    3/rm32/EBX   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>          2/r32/EDX  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># copy EDX to EBX</span>
-<span id="L44" class="LineNr">44 </span>  81          5/subop/subtract    3/mod/direct    3/rm32/EBX   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>              1/imm32           <span class="Comment"># subtract 1 from EBX</span>
-<span id="L45" class="LineNr">45 </span>  <span class="Comment"># prepare call</span>
-<span id="L46" class="LineNr">46 </span>  55/push                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># push EBP</span>
-<span id="L47" class="LineNr">47 </span>  89/copy                         3/mod/direct    5/rm32/EBP   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>          4/r32/ESP  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># copy ESP to EBP</span>
-<span id="L48" class="LineNr">48 </span>  <span class="Comment"># EAX: factorial(n-1)</span>
-<span id="L49" class="LineNr">49 </span>  53/push                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># push EBX</span>
-<span id="L50" class="LineNr">50 </span>  e8/call                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>          factorial/disp32
-<span id="L51" class="LineNr">51 </span>  <span class="Comment"># discard arg</span>
-<span id="L52" class="LineNr">52 </span>  5e/pop                         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># pop into ESI</span>
-<span id="L53" class="LineNr">53 </span>  <span class="Comment"># clean up after call</span>
-<span id="L54" class="LineNr">54 </span>  89/copy                         3/mod/direct    4/rm32/ESP   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>          5/r32/EBP  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># copy EBP to ESP</span>
-<span id="L55" class="LineNr">55 </span>  5d/pop                         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># pop to EBP</span>
-<span id="L56" class="LineNr">56 </span>  <span class="Comment"># refresh n</span>
-<span id="L57" class="LineNr">57 </span>  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              2/r32/EDX   4/disp8        <span class="Delimiter"> . </span>                <span class="Comment"># copy *(ESP+4) to EDX</span>
-<span id="L58" class="LineNr">58 </span>  <span class="Comment"># return n * factorial(n-1)</span>
-<span id="L59" class="LineNr">59 </span>  0f af/multiply                  3/mod/direct    2/rm32/EDX   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>          0/r32/EAX  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># multiply EDX (n) into EAX (factorial(n-1))</span>
-<span id="L60" class="LineNr">60 </span>  <span class="Comment"># TODO: check for overflow</span>
-<span id="L61" class="LineNr">61 </span>$factorial:exit:
-<span id="L62" class="LineNr">62 </span>  c3/return
-<span id="L63" class="LineNr">63 </span>
-<span id="L64" class="LineNr">64 </span><span class="Comment"># vim&#0058;ft=subx:nowrap:so=0</span>
+<span id="L35" class="LineNr">35 </span>  <span class="Comment"># initialize EAX to 1 (base case)</span>
+<span id="L36" class="LineNr">36 </span>  b8/copy                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>              1/imm32           <span class="Comment"># copy 1 to EAX</span>
+<span id="L37" class="LineNr">37 </span>  <span class="Comment"># if (n &lt;= 1) jump exit</span>
+<span id="L38" class="LineNr">38 </span>  81          7/subop/compare     1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>          4/disp8         1/imm32           <span class="Comment"># compare *(ESP+4) with 1</span>
+<span id="L39" class="LineNr">39 </span>  7e/jump-if-&lt;=                  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>          $factorial:exit/disp8             <span class="Comment"># jump if &lt;= to $factorial:exit</span>
+<span id="L40" class="LineNr">40 </span>  <span class="Comment"># EBX: n-1</span>
+<span id="L41" class="LineNr">41 </span>  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              3/r32/EBX   4/disp8        <span class="Delimiter"> . </span>                <span class="Comment"># copy *(ESP+4) to EBX</span>
+<span id="L42" class="LineNr">42 </span>  81          5/subop/subtract    3/mod/direct    3/rm32/EBX   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>              1/imm32           <span class="Comment"># subtract 1 from EBX</span>
+<span id="L43" class="LineNr">43 </span>  <span class="Comment"># prepare call</span>
+<span id="L44" class="LineNr">44 </span>  55/push                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># push EBP</span>
+<span id="L45" class="LineNr">45 </span>  89/copy                         3/mod/direct    5/rm32/EBP   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>          4/r32/ESP  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># copy ESP to EBP</span>
+<span id="L46" class="LineNr">46 </span>  <span class="Comment"># EAX: factorial(n-1)</span>
+<span id="L47" class="LineNr">47 </span>  53/push                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># push EBX</span>
+<span id="L48" class="LineNr">48 </span>  e8/call                        <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>          factorial/disp32
+<span id="L49" class="LineNr">49 </span>  <span class="Comment"># discard arg</span>
+<span id="L50" class="LineNr">50 </span>  5e/pop                         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># pop into ESI</span>
+<span id="L51" class="LineNr">51 </span>  <span class="Comment"># clean up after call</span>
+<span id="L52" class="LineNr">52 </span>  89/copy                         3/mod/direct    4/rm32/ESP   <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>          5/r32/EBP  <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># copy EBP to ESP</span>
+<span id="L53" class="LineNr">53 </span>  5d/pop                         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>           <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>         <span class="Delimiter"> . </span>             <span class="Delimiter"> . </span>                <span class="Comment"># pop to EBP</span>
+<span id="L54" class="LineNr">54 </span>  <span class="Comment"># refresh n</span>
+<span id="L55" class="LineNr">55 </span>  8b/copy                         1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none              2/r32/EDX   4/disp8        <span class="Delimiter"> . </span>                <span class="Comment"># copy *(ESP+4) to EDX</span>
+<span id="L56" class="LineNr">56 </span>  <span class="Comment"># return n * factorial(n-1)</span>
+<span id="L57" class="LineNr">57 </span>  f7          4/subop/multiply    1/mod/*+disp8   4/rm32/sib    4/base/ESP  4/index/none                          4/disp8        <span class="Delimiter"> . </span>                <span class="Comment"># multiply *(ESP+4) (n) into EAX (factorial(n-1))</span>
+<span id="L58" class="LineNr">58 </span>  <span class="Comment"># TODO: check for overflow</span>
+<span id="L59" class="LineNr">59 </span>$factorial:exit:
+<span id="L60" class="LineNr">60 </span>  c3/return
+<span id="L61" class="LineNr">61 </span>
+<span id="L62" class="LineNr">62 </span><span class="Comment"># vim&#0058;ft=subx:nowrap:so=0</span>
 </pre>
 </body>
 </html>