diff options
author | Kartik Agaram <vc@akkartik.com> | 2018-11-26 01:19:47 -0800 |
---|---|---|
committer | Kartik Agaram <vc@akkartik.com> | 2018-11-26 01:19:47 -0800 |
commit | d1c9392a5461e0d33e226375a8f7986a97d2d66b (patch) | |
tree | 494c19edbe1d1522344b56ced6aa7c040ad37406 | |
parent | 7e00968c99f97e13be8f5269feaf7fd1d33ecd33 (diff) | |
download | mu-d1c9392a5461e0d33e226375a8f7986a97d2d66b.tar.gz |
4782
52 files changed, 6662 insertions, 4034 deletions
diff --git a/html/subx/000organization.cc.html b/html/subx/000organization.cc.html index e3e2abb4..056519bd 100644 --- a/html/subx/000organization.cc.html +++ b/html/subx/000organization.cc.html @@ -22,7 +22,6 @@ a:hover { text-decoration: underline; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.cSpecial { color: #008000; } --> </style> @@ -212,7 +211,7 @@ if ('onhashchange' in window) { <span id="L153" class="LineNr">153 </span> <span class="Normal">const</span> <span class="Normal">int</span> x = <span class="Constant">1</span><span class="Delimiter">;</span> <span id="L154" class="LineNr">154 </span> <span class="Normal">const</span> <span class="Normal">char</span>* y = <span class="Normal">reinterpret_cast</span><<span class="Normal">const</span> <span class="Normal">char</span>*><span class="Delimiter">(</span>&x<span class="Delimiter">);</span> <span id="L155" class="LineNr">155 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*y != <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L156" class="LineNr">156 </span> cerr << <span class="Constant">"SubX requires a little-endian processor. Do you have Intel (or AMD or Atom) inside?</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L156" class="LineNr">156 </span> cerr << <span class="Constant">"SubX requires a little-endian processor. Do you have Intel (or AMD or Atom) inside?\n"</span><span class="Delimiter">;</span> <span id="L157" class="LineNr">157 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L158" class="LineNr">158 </span> <span class="Delimiter">}</span> <span id="L159" class="LineNr">159 </span><span class="Delimiter">}</span> diff --git a/html/subx/001help.cc.html b/html/subx/001help.cc.html index 5b9dbf8d..1a3fe7ed 100644 --- a/html/subx/001help.cc.html +++ b/html/subx/001help.cc.html @@ -19,6 +19,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -65,7 +66,7 @@ if ('onhashchange' in window) { <span id="L5" class="LineNr"> 5 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc <= <span class="Constant">1</span> || <a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"--help"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L6" class="LineNr"> 6 </span> <span class="Comment">//: this is the functionality later layers will provide</span> <span id="L7" class="LineNr"> 7 </span> <span class="Comment">// currently no automated tests for commandline arg parsing</span> -<span id="L8" class="LineNr"> 8 </span> cerr << get<span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"usage"</span><span class="Delimiter">);</span> +<span id="L8" class="LineNr"> 8 </span> cerr << get<span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"usage"</span><span class="Delimiter">);</span> <span id="L9" class="LineNr"> 9 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L10" class="LineNr"> 10 </span><span class="Delimiter">}</span> <span id="L11" class="LineNr"> 11 </span> @@ -84,33 +85,33 @@ if ('onhashchange' in window) { <span id="L24" class="LineNr"> 24 </span> <span id="L25" class="LineNr"> 25 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"help"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L26" class="LineNr"> 26 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>argc == <span class="Constant">2</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L27" class="LineNr"> 27 </span> cerr << <span class="Constant">"help on what?</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L27" class="LineNr"> 27 </span> cerr << <span class="Constant">"help on what?\n"</span><span class="Delimiter">;</span> <span id="L28" class="LineNr"> 28 </span> <a href='001help.cc.html#L46'>help_contents</a><span class="Delimiter">();</span> <span id="L29" class="LineNr"> 29 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L30" class="LineNr"> 30 </span> <span class="Delimiter">}</span> <span id="L31" class="LineNr"> 31 </span> string key<span class="Delimiter">(</span>argv[<span class="Constant">2</span>]<span class="Delimiter">);</span> <span id="L32" class="LineNr"> 32 </span> <span class="Comment">// End Help Special-cases(key)</span> -<span id="L33" class="LineNr"> 33 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> key<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L34" class="LineNr"> 34 </span> cerr << get<span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> key<span class="Delimiter">);</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> key<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L34" class="LineNr"> 34 </span> cerr << get<span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> key<span class="Delimiter">);</span> <span id="L35" class="LineNr"> 35 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L36" class="LineNr"> 36 </span> <span class="Delimiter">}</span> <span id="L37" class="LineNr"> 37 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L38" class="LineNr"> 38 </span> cerr << <span class="Constant">"No help found for '"</span> << key << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L38" class="LineNr"> 38 </span> cerr << <span class="Constant">"No help found for '"</span> << key << <span class="Constant">"'\n"</span><span class="Delimiter">;</span> <span id="L39" class="LineNr"> 39 </span> <a href='001help.cc.html#L46'>help_contents</a><span class="Delimiter">();</span> -<span id="L40" class="LineNr"> 40 </span> cerr << <span class="Constant">"Please check your command for typos.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L40" class="LineNr"> 40 </span> cerr << <span class="Constant">"Please check your command for typos.\n"</span><span class="Delimiter">;</span> <span id="L41" class="LineNr"> 41 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span id="L42" class="LineNr"> 42 </span> <span class="Delimiter">}</span> <span id="L43" class="LineNr"> 43 </span><span class="Delimiter">}</span> <span id="L44" class="LineNr"> 44 </span> <span id="L45" class="LineNr"> 45 </span><span class="Delimiter">:(code)</span> <span id="L46" class="LineNr"> 46 </span><span class="Normal">void</span> <a href='001help.cc.html#L46'>help_contents</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L47" class="LineNr"> 47 </span> cerr << <span class="Constant">"Available top-level topics:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L48" class="LineNr"> 48 </span> cerr << <span class="Constant">" usage</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L47" class="LineNr"> 47 </span> cerr << <span class="Constant">"Available top-level topics:\n"</span><span class="Delimiter">;</span> +<span id="L48" class="LineNr"> 48 </span> cerr << <span class="Constant">" usage\n"</span><span class="Delimiter">;</span> <span id="L49" class="LineNr"> 49 </span> <span class="Comment">// End Help Contents</span> <span id="L50" class="LineNr"> 50 </span><span class="Delimiter">}</span> <span id="L51" class="LineNr"> 51 </span> <span id="L52" class="LineNr"> 52 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L53" class="LineNr"> 53 </span>map<string<span class="Delimiter">,</span> string> <a href='001help.cc.html#L53'>Help</a><span class="Delimiter">;</span> +<span id="L53" class="LineNr"> 53 </span>map<string<span class="Delimiter">,</span> string> <span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">;</span> <span id="L54" class="LineNr"> 54 </span><span class="Delimiter">:(before "End Includes")</span> <span id="L55" class="LineNr"> 55 </span><span class="Comment">#include <map></span> <span id="L56" class="LineNr"> 56 </span><span class="Normal">using</span> std::map<span class="Delimiter">;</span> @@ -118,29 +119,29 @@ if ('onhashchange' in window) { <span id="L58" class="LineNr"> 58 </span><a href='001help.cc.html#L60'>init_help</a><span class="Delimiter">();</span> <span id="L59" class="LineNr"> 59 </span><span class="Delimiter">:(code)</span> <span id="L60" class="LineNr"> 60 </span><span class="Normal">void</span> <a href='001help.cc.html#L60'>init_help</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L61" class="LineNr"> 61 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"usage"</span><span class="Delimiter">,</span> -<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"Welcome to SubX, a better way to <a href='011run.cc.html#L99'>program</a> in machine code.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Constant">"SubX uses a subset of the x86 instruction set. SubX programs will <a href='011run.cc.html#L83'>run</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"without modification on Linux computers.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"It provides a better experience and better error messages than</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"programming directly in machine <a href='031check_operands.cc.html#L11'>code</a>, but you have to stick to the</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"instructions it supports.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L69" class="LineNr"> 69 </span> <span class="Constant">"== Ways to invoke subx</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"- Run tests:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L71" class="LineNr"> 71 </span> <span class="Constant">" subx test</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"- See this message:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Constant">" subx --help</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"- Convert a textual SubX <a href='011run.cc.html#L99'>program</a> into a standard ELF binary that you can</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L75" class="LineNr"> 75 </span> <span class="Constant">" <a href='011run.cc.html#L83'>run</a> on your computer:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Constant">" subx translate input1.subx intput2.subx ... -o <output ELF binary></span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"- Run a SubX binary using SubX itself (for better error messages):</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L78" class="LineNr"> 78 </span> <span class="Constant">" subx <a href='011run.cc.html#L83'>run</a> <ELF binary></span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"Add '--trace' to any of these commands to also emit a <a href='003trace.cc.html#L203'>trace</a>, for debugging purposes.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"However, options starting with '--' must always come before any other arguments.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"To start learning how to write SubX programs, <a href='011run.cc.html#L83'>run</a>:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L83" class="LineNr"> 83 </span> <span class="Constant">" subx help</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L61" class="LineNr"> 61 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"usage"</span><span class="Delimiter">,</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"Welcome to SubX, a better way to <a href='011run.cc.html#L99'>program</a> in machine code.\n"</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Constant">"SubX uses a subset of the x86 instruction set. SubX programs will run\n"</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"without modification on Linux computers.\n"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"It provides a better experience and better error messages than\n"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"programming directly in machine <a href='031check_operands.cc.html#L11'>code</a>, but you have to stick to the\n"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"instructions it supports.\n"</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"\n"</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">"== Ways to invoke subx\n"</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"- Run tests:\n"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Constant">" subx test\n"</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"- See this message:\n"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">" subx --help\n"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"- Convert a textual SubX <a href='011run.cc.html#L99'>program</a> into a standard ELF binary that you can\n"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">" <a href='011run.cc.html#L83'>run</a> on your computer:\n"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">" subx translate input1.subx intput2.subx ... -o <output ELF binary>\n"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">"- Run a SubX binary using SubX itself (for better error messages):\n"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">" subx <a href='011run.cc.html#L83'>run</a> <ELF binary>\n"</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Constant">"Add '--trace' to any of these commands to also emit a <a href='003trace.cc.html#L203'>trace</a>, for debugging purposes.\n"</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Constant">"However, options starting with '--' must always come before any other arguments.\n"</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"\n"</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"To start learning how to write SubX programs, <a href='011run.cc.html#L83'>run</a>:\n"</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Constant">" subx help\n"</span> <span id="L84" class="LineNr"> 84 </span> <span class="Delimiter">);</span> <span id="L85" class="LineNr"> 85 </span> <span class="Comment">// End Help Texts</span> <span id="L86" class="LineNr"> 86 </span><span class="Delimiter">}</span> @@ -237,13 +238,13 @@ if ('onhashchange' in window) { <span id="L177" class="LineNr">177 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>sig<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L178" class="LineNr">178 </span> <span class="Normal">case</span> <span class="Constant">SIGABRT</span>: <span id="L179" class="LineNr">179 </span> <span class="Comment">#ifndef __APPLE__</span> -<span id="L180" class="LineNr">180 </span> cerr << <span class="Constant">"SIGABRT: might be an integer overflow if it wasn't an assert() failure</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L180" class="LineNr">180 </span> cerr << <span class="Constant">"SIGABRT: might be an integer overflow if it wasn't an assert() failure\n"</span><span class="Delimiter">;</span> <span id="L181" class="LineNr">181 </span> _Exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L182" class="LineNr">182 </span> <span class="Comment">#endif</span> <span id="L183" class="LineNr">183 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L184" class="LineNr">184 </span> <span class="Normal">case</span> <span class="Constant">SIGILL</span>: <span id="L185" class="LineNr">185 </span> <span class="Comment">#ifdef __APPLE__</span> -<span id="L186" class="LineNr">186 </span> cerr << <span class="Constant">"SIGILL: most likely caused by integer overflow</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L186" class="LineNr">186 </span> cerr << <span class="Constant">"SIGILL: most likely caused by integer overflow\n"</span><span class="Delimiter">;</span> <span id="L187" class="LineNr">187 </span> _Exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L188" class="LineNr">188 </span> <span class="Comment">#endif</span> <span id="L189" class="LineNr">189 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -284,33 +285,33 @@ if ('onhashchange' in window) { <span id="L224" class="LineNr">224 </span><span class="Comment">//: 6. Map's operator[] being non-const is fucking evil.</span> <span id="L225" class="LineNr">225 </span><span class="Delimiter">:(before "Globals")</span> <span class="Comment">// can't generate prototypes for these</span> <span id="L226" class="LineNr">226 </span><span class="Comment">// from <a href="http://stackoverflow.com/questions/152643/idiomatic-c-for-reading-from-a-const-map">http://stackoverflow.com/questions/152643/idiomatic-c-for-reading-from-a-const-map</a></span> -<span id="L227" class="LineNr">227 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type& get<span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L228" class="LineNr">228 </span> <span class="Normal">typename</span> T::iterator iter<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">));</span> +<span id="L227" class="LineNr">227 </span><span class="Normal">template</span><<span class="Normal">typename</span> <span class="Special">T</span>> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type& get<span class="Delimiter">(</span><span class="Special">T</span>& map<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L228" class="LineNr">228 </span> <span class="Normal">typename</span> <span class="Special">T</span>::iterator iter<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">));</span> <span id="L229" class="LineNr">229 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>iter == map<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L230" class="LineNr">230 </span> cerr << <span class="Constant">"get couldn't find key '"</span> << key << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L230" class="LineNr">230 </span> cerr << <span class="Constant">"get couldn't find key '"</span> << key << <span class="Constant">"'\n"</span><span class="Delimiter">;</span> <span id="L231" class="LineNr">231 </span> assert<span class="Delimiter">(</span>iter != map<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span id="L232" class="LineNr">232 </span> <span class="Delimiter">}</span> <span id="L233" class="LineNr">233 </span> <span class="Identifier">return</span> iter<span class="Delimiter">-></span>second<span class="Delimiter">;</span> <span id="L234" class="LineNr">234 </span><span class="Delimiter">}</span> -<span id="L235" class="LineNr">235 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& get<span class="Delimiter">(</span><span class="Normal">const</span> T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L236" class="LineNr">236 </span> <span class="Normal">typename</span> T::const_iterator iter<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">));</span> +<span id="L235" class="LineNr">235 </span><span class="Normal">template</span><<span class="Normal">typename</span> <span class="Special">T</span>> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type <span class="Normal">const</span>& get<span class="Delimiter">(</span><span class="Normal">const</span> <span class="Special">T</span>& map<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L236" class="LineNr">236 </span> <span class="Normal">typename</span> <span class="Special">T</span>::const_iterator iter<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">));</span> <span id="L237" class="LineNr">237 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>iter == map<span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L238" class="LineNr">238 </span> cerr << <span class="Constant">"get couldn't find key '"</span> << key << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L238" class="LineNr">238 </span> cerr << <span class="Constant">"get couldn't find key '"</span> << key << <span class="Constant">"'\n"</span><span class="Delimiter">;</span> <span id="L239" class="LineNr">239 </span> assert<span class="Delimiter">(</span>iter != map<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span id="L240" class="LineNr">240 </span> <span class="Delimiter">}</span> <span id="L241" class="LineNr">241 </span> <span class="Identifier">return</span> iter<span class="Delimiter">-></span>second<span class="Delimiter">;</span> <span id="L242" class="LineNr">242 </span><span class="Delimiter">}</span> -<span id="L243" class="LineNr">243 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">,</span> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& value<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L243" class="LineNr">243 </span><span class="Normal">template</span><<span class="Normal">typename</span> <span class="Special">T</span>> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type <span class="Normal">const</span>& <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special">T</span>& map<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::key_type <span class="Normal">const</span>& key<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type <span class="Normal">const</span>& value<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L244" class="LineNr">244 </span> map[key] = value<span class="Delimiter">;</span> <span id="L245" class="LineNr">245 </span> <span class="Identifier">return</span> map[key]<span class="Delimiter">;</span> <span id="L246" class="LineNr">246 </span><span class="Delimiter">}</span> -<span id="L247" class="LineNr">247 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">bool</span> <a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L247" class="LineNr">247 </span><span class="Normal">template</span><<span class="Normal">typename</span> <span class="Special">T</span>> <span class="Normal">bool</span> <a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span><span class="Special">T</span>& map<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L248" class="LineNr">248 </span> <span class="Identifier">return</span> map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">)</span> != map<span class="Delimiter">.</span>end<span class="Delimiter">();</span> <span id="L249" class="LineNr">249 </span><span class="Delimiter">}</span> -<span id="L250" class="LineNr">250 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type& <a href='001help.cc.html#L250'>get_or_insert</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L250" class="LineNr">250 </span><span class="Normal">template</span><<span class="Normal">typename</span> <span class="Special">T</span>> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type& <a href='001help.cc.html#L250'>get_or_insert</a><span class="Delimiter">(</span><span class="Special">T</span>& map<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::key_type <span class="Normal">const</span>& key<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L251" class="LineNr">251 </span> <span class="Identifier">return</span> map[key]<span class="Delimiter">;</span> <span id="L252" class="LineNr">252 </span><span class="Delimiter">}</span> -<span id="L253" class="LineNr">253 </span><span class="Normal">template</span><<span class="Normal">typename</span> T> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& <a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span>T& map<span class="Delimiter">,</span> <span class="Normal">typename</span> T::key_type <span class="Normal">const</span>& key<span class="Delimiter">,</span> <span class="Normal">typename</span> T::mapped_type <span class="Normal">const</span>& value<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L253" class="LineNr">253 </span><span class="Normal">template</span><<span class="Normal">typename</span> <span class="Special">T</span>> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type <span class="Normal">const</span>& <a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special">T</span>& map<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::key_type <span class="Normal">const</span>& key<span class="Delimiter">,</span> <span class="Normal">typename</span> <span class="Special">T</span>::mapped_type <span class="Normal">const</span>& value<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L254" class="LineNr">254 </span> assert<span class="Delimiter">(</span>map<span class="Delimiter">.</span>find<span class="Delimiter">(</span>key<span class="Delimiter">)</span> == map<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span id="L255" class="LineNr">255 </span> map[key] = value<span class="Delimiter">;</span> <span id="L256" class="LineNr">256 </span> <span class="Identifier">return</span> map[key]<span class="Delimiter">;</span> diff --git a/html/subx/002test.cc.html b/html/subx/002test.cc.html index 8c3c25b9..5ae00cdf 100644 --- a/html/subx/002test.cc.html +++ b/html/subx/002test.cc.html @@ -19,6 +19,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -72,40 +73,40 @@ if ('onhashchange' in window) { <span id="L12" class="LineNr"> 12 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*test_fn<span class="Delimiter">)(</span><span class="Normal">void</span><span class="Delimiter">);</span> <span id="L13" class="LineNr"> 13 </span><span class="Delimiter">:(before "Globals")</span> <span id="L14" class="LineNr"> 14 </span><span class="Comment">// move a global ahead into types that we can't generate an extern declaration for</span> -<span id="L15" class="LineNr"> 15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> Tests[] = <span class="Delimiter">{</span> +<span id="L15" class="LineNr"> 15 </span><span class="Normal">const</span> <a href='002test.cc.html#L12'>test_fn</a> <span class="Special"><a href='002test.cc.html#L15'>Tests</a></span>[] = <span class="Delimiter">{</span> <span id="L16" class="LineNr"> 16 </span> <span class="Comment">#include "test_list" // auto-generated; see 'build*' scripts</span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">};</span> <span id="L18" class="LineNr"> 18 </span> <span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L20" class="LineNr"> 20 </span><span class="Normal">bool</span> <a href='002test.cc.html#L20'>Run_tests</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L21" class="LineNr"> 21 </span><span class="Normal">bool</span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> +<span id="L20" class="LineNr"> 20 </span><span class="Normal">bool</span> <span class="Special"><a href='002test.cc.html#L20'>Run_tests</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L21" class="LineNr"> 21 </span><span class="Normal">bool</span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> <span class="Comment">// set this to false inside any test to indicate failure</span> <span id="L22" class="LineNr"> 22 </span> <span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Includes")</span> <span id="L24" class="LineNr"> 24 </span><span class="Comment">#define CHECK(X) \</span> -<span id="L25" class="LineNr"> 25 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a> && !<span class="Delimiter">(</span>X<span class="Delimiter">))</span> <span class="Delimiter">{</span> \ -<span id="L26" class="LineNr"> 26 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): "</span> << <span class="Comment">#X << '\n'; \</span> -<span id="L27" class="LineNr"> 27 </span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ +<span id="L25" class="LineNr"> 25 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> && !<span class="Delimiter">(</span><span class="Special">X</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> \ +<span id="L26" class="LineNr"> 26 </span> cerr << <span class="Constant">"\nF - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): "</span> << <span class="Comment">#X << '\n'; \</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ <span id="L28" class="LineNr"> 28 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span> \ <span id="L29" class="LineNr"> 29 </span> <span class="Delimiter">}</span> <span id="L30" class="LineNr"> 30 </span> <span id="L31" class="LineNr"> 31 </span><span class="Comment">#define CHECK_EQ(X, Y) \</span> -<span id="L32" class="LineNr"> 32 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a> && <span class="Delimiter">(</span>X<span class="Delimiter">)</span> != <span class="Delimiter">(</span>Y<span class="Delimiter">))</span> <span class="Delimiter">{</span> \ -<span id="L33" class="LineNr"> 33 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): "</span> << <span class="Comment">#X << " == " << #Y << '\n'; \</span> -<span id="L34" class="LineNr"> 34 </span> cerr << <span class="Constant">" got "</span> << <span class="Delimiter">(</span>X<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span> \ -<span id="L35" class="LineNr"> 35 </span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ +<span id="L32" class="LineNr"> 32 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> && <span class="Delimiter">(</span><span class="Special">X</span><span class="Delimiter">)</span> != <span class="Delimiter">(</span><span class="Special">Y</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> \ +<span id="L33" class="LineNr"> 33 </span> cerr << <span class="Constant">"\nF - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): "</span> << <span class="Comment">#X << " == " << #Y << '\n'; \</span> +<span id="L34" class="LineNr"> 34 </span> cerr << <span class="Constant">" got "</span> << <span class="Delimiter">(</span><span class="Special">X</span><span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Comment">/*</span><span class="Comment"> BEWARE: multiple eval </span><span class="Comment">*/</span> \ +<span id="L35" class="LineNr"> 35 </span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ <span id="L36" class="LineNr"> 36 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span> \ <span id="L37" class="LineNr"> 37 </span> <span class="Delimiter">}</span> <span id="L38" class="LineNr"> 38 </span> <span id="L39" class="LineNr"> 39 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L40" class="LineNr"> 40 </span><a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L40" class="LineNr"> 40 </span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L41" class="LineNr"> 41 </span> <span id="L42" class="LineNr"> 42 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> <span id="L43" class="LineNr"> 43 </span><span class="Normal">if</span> <span class="Delimiter">(</span>argc > <span class="Constant">1</span> && <a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>argv[<span class="Constant">1</span>]<span class="Delimiter">,</span> <span class="Constant">"test"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L44" class="LineNr"> 44 </span> <a href='002test.cc.html#L20'>Run_tests</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Special"><a href='002test.cc.html#L20'>Run_tests</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> --argc<span class="Delimiter">;</span> ++argv<span class="Delimiter">;</span> <span class="Comment">// shift 'test' out of commandline args</span> <span id="L45" class="LineNr"> 45 </span><span class="Delimiter">}</span> <span id="L46" class="LineNr"> 46 </span> <span id="L47" class="LineNr"> 47 </span><span class="Delimiter">:(before "End Main")</span> -<span id="L48" class="LineNr"> 48 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L20'>Run_tests</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L48" class="LineNr"> 48 </span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L20'>Run_tests</a></span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L49" class="LineNr"> 49 </span> <span class="Comment">// Test Runs</span> <span id="L50" class="LineNr"> 50 </span> <span class="Comment">// we run some tests and then exit; assume no state need be maintained afterward</span> <span id="L51" class="LineNr"> 51 </span> @@ -113,10 +114,10 @@ if ('onhashchange' in window) { <span id="L53" class="LineNr"> 53 </span> <span class="Comment">// End Test Run Initialization</span> <span id="L54" class="LineNr"> 54 </span> <span class="Normal">time_t</span> t<span class="Delimiter">;</span> time<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> <span id="L55" class="LineNr"> 55 </span> cerr << <span class="Constant">"C tests: "</span> << ctime<span class="Delimiter">(</span>&t<span class="Delimiter">);</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L15'>Tests</a></span><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L15'>Tests</a></span>[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L57" class="LineNr"> 57 </span><span class="CommentedCode">//? cerr << "running " << Test_names[i] << '\n';</span> <span id="L58" class="LineNr"> 58 </span> <a href='002test.cc.html#L81'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a><span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span><span class="Delimiter">)</span> cerr << <span class="Constant">'.'</span><span class="Delimiter">;</span> <span id="L60" class="LineNr"> 60 </span> <span class="Normal">else</span> ++num_failures<span class="Delimiter">;</span> <span id="L61" class="LineNr"> 61 </span> <span class="Delimiter">}</span> <span id="L62" class="LineNr"> 62 </span> cerr << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> @@ -134,35 +135,35 @@ if ('onhashchange' in window) { <span id="L74" class="LineNr"> 74 </span><span class="Comment">//: Raise other unrecognized sub-commands as errors.</span> <span id="L75" class="LineNr"> 75 </span><span class="Comment">//: We couldn't do this until now because we want `./subx test` to always</span> <span id="L76" class="LineNr"> 76 </span><span class="Comment">//: succeed, no matter how many layers are included in the build.</span> -<span id="L77" class="LineNr"> 77 </span>cerr << <span class="Constant">"nothing to do</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L77" class="LineNr"> 77 </span>cerr << <span class="Constant">"nothing to do\n"</span><span class="Delimiter">;</span> <span id="L78" class="LineNr"> 78 </span><span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span id="L79" class="LineNr"> 79 </span> <span id="L80" class="LineNr"> 80 </span><span class="Delimiter">:(code)</span> <span id="L81" class="LineNr"> 81 </span><span class="Normal">void</span> <a href='002test.cc.html#L81'>run_test</a><span class="Delimiter">(</span><span class="Normal">size_t</span> i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= <span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L15'>Tests</a></span><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L15'>Tests</a></span>[<span class="Constant">0</span>]<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L83" class="LineNr"> 83 </span> cerr << <span class="Constant">"no test "</span> << i << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L84" class="LineNr"> 84 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L85" class="LineNr"> 85 </span> <span class="Delimiter">}</span> <span id="L86" class="LineNr"> 86 </span> <a href='000organization.cc.html#L148'>reset</a><span class="Delimiter">();</span> <span id="L87" class="LineNr"> 87 </span> <span class="Comment">// End Test Setup</span> -<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">(</span>*Tests[i]<span class="Delimiter">)();</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">(</span>*<span class="Special"><a href='002test.cc.html#L15'>Tests</a></span>[i]<span class="Delimiter">)();</span> <span id="L89" class="LineNr"> 89 </span> <span class="Comment">// End Test Teardown</span> <span id="L90" class="LineNr"> 90 </span><span class="Delimiter">}</span> <span id="L91" class="LineNr"> 91 </span> <span id="L92" class="LineNr"> 92 </span><span class="Comment">//: Convenience: run a single test</span> <span id="L93" class="LineNr"> 93 </span><span class="Delimiter">:(before "Globals")</span> <span id="L94" class="LineNr"> 94 </span><span class="Comment">// Names for each element of the 'Tests' global, respectively.</span> -<span id="L95" class="LineNr"> 95 </span><span class="Normal">const</span> string Test_names[] = <span class="Delimiter">{</span> +<span id="L95" class="LineNr"> 95 </span><span class="Normal">const</span> string <span class="Special"><a href='002test.cc.html#L95'>Test_names</a></span>[] = <span class="Delimiter">{</span> <span id="L96" class="LineNr"> 96 </span> <span class="Comment">#include "test_name_list" // auto-generated; see 'build*' scripts</span> <span id="L97" class="LineNr"> 97 </span><span class="Delimiter">};</span> <span id="L98" class="LineNr"> 98 </span><span class="Delimiter">:(after "Test Runs")</span> <span id="L99" class="LineNr"> 99 </span>string <a href='002test.cc.html#L99'>maybe_single_test_to_run</a> = argv[argc-<span class="Constant">1</span>]<span class="Delimiter">;</span> <span id="L100" class="LineNr">100 </span><span class="Normal">if</span> <span class="Delimiter">(</span>!starts_with<span class="Delimiter">(</span><a href='002test.cc.html#L99'>maybe_single_test_to_run</a><span class="Delimiter">,</span> <span class="Constant">"test_"</span><span class="Delimiter">))</span> <span id="L101" class="LineNr">101 </span> <a href='002test.cc.html#L99'>maybe_single_test_to_run</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">"test_"</span><span class="Delimiter">);</span> -<span id="L102" class="LineNr">102 </span><span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='002test.cc.html#L15'>Tests</a><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span>Tests[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L103" class="LineNr">103 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Test_names[i] == <a href='002test.cc.html#L99'>maybe_single_test_to_run</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L102" class="LineNr">102 </span><span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i=<span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L15'>Tests</a></span><span class="Delimiter">)</span>/<span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L15'>Tests</a></span>[<span class="Constant">0</span>]<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L103" class="LineNr">103 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L95'>Test_names</a></span>[i] == <a href='002test.cc.html#L99'>maybe_single_test_to_run</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L104" class="LineNr">104 </span> <a href='002test.cc.html#L81'>run_test</a><span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L105" class="LineNr">105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a><span class="Delimiter">)</span> cerr << <span class="Constant">".</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L105" class="LineNr">105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span><span class="Delimiter">)</span> cerr << <span class="Constant">".\n"</span><span class="Delimiter">;</span> <span id="L106" class="LineNr">106 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L107" class="LineNr">107 </span> <span class="Delimiter">}</span> <span id="L108" class="LineNr">108 </span><span class="Delimiter">}</span> diff --git a/html/subx/003trace.cc.html b/html/subx/003trace.cc.html index 8f4b68e1..1abc6fe9 100644 --- a/html/subx/003trace.cc.html +++ b/html/subx/003trace.cc.html @@ -18,6 +18,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -139,20 +140,20 @@ if ('onhashchange' in window) { <span id="L80" class="LineNr"> 80 </span><span class="Comment">//: Traces can have a lot of overhead, so only turn them on when asked.</span> <span id="L81" class="LineNr"> 81 </span><span class="Delimiter">:(before "End Commandline Options(*arg)")</span> <span id="L82" class="LineNr"> 82 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--trace"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L83" class="LineNr"> 83 </span> <a href='003trace.cc.html#L237'>Save_trace</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Special"><a href='003trace.cc.html#L237'>Save_trace</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L84" class="LineNr"> 84 </span><span class="Delimiter">}</span> <span id="L85" class="LineNr"> 85 </span><span class="Delimiter">:(before "End Commandline Parsing")</span> -<span id="L86" class="LineNr"> 86 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L237'>Save_trace</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L87" class="LineNr"> 87 </span> cerr << <span class="Constant">"initializing <a href='003trace.cc.html#L203'>trace</a></span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L88" class="LineNr"> 88 </span> <a href='003trace.cc.html#L174'>Trace_stream</a> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> +<span id="L86" class="LineNr"> 86 </span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L237'>Save_trace</a></span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L87" class="LineNr"> 87 </span> cerr << <span class="Constant">"initializing trace\n"</span><span class="Delimiter">;</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> <span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> <span id="L90" class="LineNr"> 90 </span><span class="Delimiter">:(code)</span> <span id="L91" class="LineNr"> 91 </span><span class="Normal">void</span> <a href='003trace.cc.html#L91'>cleanup_main</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L93" class="LineNr"> 93 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L237'>Save_trace</a><span class="Delimiter">)</span> -<span id="L94" class="LineNr"> 94 </span> <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L133'>save</a><span class="Delimiter">();</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Normal">delete</span> <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">;</span> -<span id="L96" class="LineNr"> 96 </span> <a href='003trace.cc.html#L174'>Trace_stream</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!<span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L237'>Save_trace</a></span><span class="Delimiter">)</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L133'>save</a><span class="Delimiter">();</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Normal">delete</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">;</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span> = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span id="L97" class="LineNr"> 97 </span><span class="Delimiter">}</span> <span id="L98" class="LineNr"> 98 </span><span class="Delimiter">:(before "End One-time Setup")</span> <span id="L99" class="LineNr"> 99 </span>atexit<span class="Delimiter">(</span><a href='003trace.cc.html#L91'>cleanup_main</a><span class="Delimiter">);</span> @@ -161,9 +162,9 @@ if ('onhashchange' in window) { <span id="L102" class="LineNr">102 </span><span class="Comment">// Pre-define some global constants that trace_stream needs to know about.</span> <span id="L103" class="LineNr">103 </span><span class="Comment">// Since they're in the Types section, they'll be included in any cleaved</span> <span id="L104" class="LineNr">104 </span><span class="Comment">// compilation units. So no extern linkage.</span> -<span id="L105" class="LineNr">105 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='003trace.cc.html#L105'>Max_depth</a> = <span class="Constant">9999</span><span class="Delimiter">;</span> -<span id="L106" class="LineNr">106 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='003trace.cc.html#L106'>Error_depth</a> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// definitely always print errors</span> -<span id="L107" class="LineNr">107 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='003trace.cc.html#L107'>Warn_depth</a> = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L105" class="LineNr">105 </span><span class="Normal">const</span> <span class="Normal">int</span> <span class="Special"><a href='003trace.cc.html#L105'>Max_depth</a></span> = <span class="Constant">9999</span><span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span><span class="Normal">const</span> <span class="Normal">int</span> <span class="Special"><a href='003trace.cc.html#L106'>Error_depth</a></span> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// definitely always print errors</span> +<span id="L107" class="LineNr">107 </span><span class="Normal">const</span> <span class="Normal">int</span> <span class="Special"><a href='003trace.cc.html#L107'>Warn_depth</a></span> = <span class="Constant">1</span><span class="Delimiter">;</span> <span id="L108" class="LineNr">108 </span> <span id="L109" class="LineNr">109 </span><span class="Normal">struct</span> trace_stream <span class="Delimiter">{</span> <span id="L110" class="LineNr">110 </span> vector<trace_line> <a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">;</span> @@ -173,11 +174,11 @@ if ('onhashchange' in window) { <span id="L114" class="LineNr">114 </span> <span class="Normal">int</span> <a href='003trace.cc.html#L114'>curr_depth</a><span class="Delimiter">;</span> <span id="L115" class="LineNr">115 </span> <span class="Normal">int</span> <a href='003trace.cc.html#L115'>collect_depth</a><span class="Delimiter">;</span> <span id="L116" class="LineNr">116 </span> ofstream<span class="Constant"> null</span>_stream<span class="Delimiter">;</span> <span class="Comment">// never opens a file, so writes silently fail</span> -<span id="L117" class="LineNr">117 </span> trace_stream<span class="Delimiter">()</span> :<a href='003trace.cc.html#L112'>curr_stream</a><span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> <a href='003trace.cc.html#L114'>curr_depth</a><span class="Delimiter">(</span><a href='003trace.cc.html#L105'>Max_depth</a><span class="Delimiter">),</span> <a href='003trace.cc.html#L115'>collect_depth</a><span class="Delimiter">(</span><a href='003trace.cc.html#L105'>Max_depth</a><span class="Delimiter">)</span> <span class="Delimiter">{}</span> +<span id="L117" class="LineNr">117 </span> trace_stream<span class="Delimiter">()</span> :<a href='003trace.cc.html#L112'>curr_stream</a><span class="Delimiter">(</span><span class="Constant">NULL</span><span class="Delimiter">),</span> <a href='003trace.cc.html#L114'>curr_depth</a><span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L105'>Max_depth</a></span><span class="Delimiter">),</span> <a href='003trace.cc.html#L115'>collect_depth</a><span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L105'>Max_depth</a></span><span class="Delimiter">)</span> <span class="Delimiter">{}</span> <span id="L118" class="LineNr">118 </span> <a href='003trace.cc.html#L118'>~trace_stream</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L112'>curr_stream</a><span class="Delimiter">)</span> <span class="Normal">delete</span> <a href='003trace.cc.html#L112'>curr_stream</a><span class="Delimiter">;</span> <span class="Delimiter">}</span> <span id="L119" class="LineNr">119 </span> <span id="L120" class="LineNr">120 </span> ostream& stream<span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L121" class="LineNr">121 </span> <span class="Identifier">return</span> stream<span class="Delimiter">(</span><a href='003trace.cc.html#L105'>Max_depth</a><span class="Delimiter">,</span> label<span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <span class="Identifier">return</span> stream<span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L105'>Max_depth</a></span><span class="Delimiter">,</span> label<span class="Delimiter">);</span> <span id="L122" class="LineNr">122 </span> <span class="Delimiter">}</span> <span id="L123" class="LineNr">123 </span> <span id="L124" class="LineNr">124 </span> ostream& stream<span class="Delimiter">(</span><span class="Normal">int</span> <a href='003trace.cc.html#L72'>depth</a><span class="Delimiter">,</span> string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -190,7 +191,7 @@ if ('onhashchange' in window) { <span id="L131" class="LineNr">131 </span> <span class="Delimiter">}</span> <span id="L132" class="LineNr">132 </span> <span id="L133" class="LineNr">133 </span> <span class="Normal">void</span> <a href='003trace.cc.html#L133'>save</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L134" class="LineNr">134 </span> cerr << <span class="Constant">"saving <a href='003trace.cc.html#L203'>trace</a> to 'last_run'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L134" class="LineNr">134 </span> cerr << <span class="Constant">"saving <a href='003trace.cc.html#L203'>trace</a> to 'last_run'\n"</span><span class="Delimiter">;</span> <span id="L135" class="LineNr">135 </span> ofstream fout<span class="Delimiter">(</span><span class="Constant">"last_run"</span><span class="Delimiter">);</span> <span id="L136" class="LineNr">136 </span> fout << <a href='003trace.cc.html#L164'>readable_contents</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> <span id="L137" class="LineNr">137 </span> fout<span class="Delimiter">.</span>close<span class="Delimiter">();</span> @@ -208,16 +209,16 @@ if ('onhashchange' in window) { <span id="L149" class="LineNr">149 </span> string curr_contents = <a href='003trace.cc.html#L112'>curr_stream</a><span class="Delimiter">-></span>str<span class="Delimiter">();</span> <span id="L150" class="LineNr">150 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!curr_contents<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span id="L151" class="LineNr">151 </span> <a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>trace_line<span class="Delimiter">(</span><a href='003trace.cc.html#L114'>curr_depth</a><span class="Delimiter">,</span> <a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span><a href='003trace.cc.html#L113'>curr_label</a><span class="Delimiter">),</span> curr_contents<span class="Delimiter">));</span> <span class="Comment">// preserve indent in contents</span> -<span id="L152" class="LineNr">152 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>!Hide_errors && <a href='003trace.cc.html#L114'>curr_depth</a> == <a href='003trace.cc.html#L106'>Error_depth</a><span class="Delimiter">)</span> -<span id="L153" class="LineNr">153 </span> || <span class="Delimiter">(</span>!Hide_warnings && !Hide_errors && <a href='003trace.cc.html#L114'>curr_depth</a> == <a href='003trace.cc.html#L107'>Warn_depth</a><span class="Delimiter">)</span> -<span id="L154" class="LineNr">154 </span> || <a href='003trace.cc.html#L188'>Dump_trace</a> -<span id="L155" class="LineNr">155 </span> || <span class="Delimiter">(</span>!Dump_label<span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && <a href='003trace.cc.html#L113'>curr_label</a> == <a href='003trace.cc.html#L189'>Dump_label</a><span class="Delimiter">))</span> +<span id="L152" class="LineNr">152 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>!<span class="Special">Hide_errors</span> && <a href='003trace.cc.html#L114'>curr_depth</a> == <span class="Special"><a href='003trace.cc.html#L106'>Error_depth</a></span><span class="Delimiter">)</span> +<span id="L153" class="LineNr">153 </span> || <span class="Delimiter">(</span>!<span class="Special">Hide_warnings</span> && !<span class="Special">Hide_errors</span> && <a href='003trace.cc.html#L114'>curr_depth</a> == <span class="Special"><a href='003trace.cc.html#L107'>Warn_depth</a></span><span class="Delimiter">)</span> +<span id="L154" class="LineNr">154 </span> || <span class="Special"><a href='003trace.cc.html#L188'>Dump_trace</a></span> +<span id="L155" class="LineNr">155 </span> || <span class="Delimiter">(</span>!<span class="Special"><a href='003trace.cc.html#L189'>Dump_label</a></span><span class="Delimiter">.</span>empty<span class="Delimiter">()</span> && <a href='003trace.cc.html#L113'>curr_label</a> == <span class="Special"><a href='003trace.cc.html#L189'>Dump_label</a></span><span class="Delimiter">))</span> <span id="L156" class="LineNr">156 </span> cerr << <a href='003trace.cc.html#L113'>curr_label</a> << <span class="Constant">": "</span> << curr_contents << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L157" class="LineNr">157 </span> <span class="Delimiter">}</span> <span id="L158" class="LineNr">158 </span> <span class="Normal">delete</span> <a href='003trace.cc.html#L112'>curr_stream</a><span class="Delimiter">;</span> <span id="L159" class="LineNr">159 </span> <a href='003trace.cc.html#L112'>curr_stream</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span id="L160" class="LineNr">160 </span> <a href='003trace.cc.html#L113'>curr_label</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> -<span id="L161" class="LineNr">161 </span> <a href='003trace.cc.html#L114'>curr_depth</a> = <a href='003trace.cc.html#L105'>Max_depth</a><span class="Delimiter">;</span> +<span id="L161" class="LineNr">161 </span> <a href='003trace.cc.html#L114'>curr_depth</a> = <span class="Special"><a href='003trace.cc.html#L105'>Max_depth</a></span><span class="Delimiter">;</span> <span id="L162" class="LineNr">162 </span><span class="Delimiter">}</span> <span id="L163" class="LineNr">163 </span> <span id="L164" class="LineNr">164 </span>string trace_stream::<a href='003trace.cc.html#L164'>readable_contents</a><span class="Delimiter">(</span>string label<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -230,30 +231,30 @@ if ('onhashchange' in window) { <span id="L171" class="LineNr">171 </span><span class="Delimiter">}</span> <span id="L172" class="LineNr">172 </span> <span id="L173" class="LineNr">173 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L174" class="LineNr">174 </span>trace_stream* <a href='003trace.cc.html#L174'>Trace_stream</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> -<span id="L175" class="LineNr">175 </span><span class="Normal">int</span> <a href='003trace.cc.html#L175'>Trace_errors</a> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// used only when Trace_stream is NULL</span> +<span id="L174" class="LineNr">174 </span>trace_stream* <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span> = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L175" class="LineNr">175 </span><span class="Normal">int</span> <span class="Special"><a href='003trace.cc.html#L175'>Trace_errors</a></span> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// used only when Trace_stream is NULL</span> <span id="L176" class="LineNr">176 </span> <span id="L177" class="LineNr">177 </span><span class="Comment">//: option to print trace to the screen</span> <span id="L178" class="LineNr">178 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L179" class="LineNr">179 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L179'>Flag_dump_trace</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L179" class="LineNr">179 </span><span class="Normal">bool</span> <span class="Special"><a href='003trace.cc.html#L179'>Flag_dump_trace</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L180" class="LineNr">180 </span><span class="Delimiter">:(before "End Commandline Options(*arg)")</span> <span id="L181" class="LineNr">181 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--dump"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L182" class="LineNr">182 </span> <a href='003trace.cc.html#L179'>Flag_dump_trace</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L182" class="LineNr">182 </span> <span class="Special"><a href='003trace.cc.html#L179'>Flag_dump_trace</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L183" class="LineNr">183 </span><span class="Delimiter">}</span> <span id="L184" class="LineNr">184 </span> <span id="L185" class="LineNr">185 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L186" class="LineNr">186 </span><span class="Normal">bool</span> Hide_errors =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, don't print even error trace lines to screen</span> -<span id="L187" class="LineNr">187 </span><span class="Normal">bool</span> Hide_warnings =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, don't print warnings to screen</span> -<span id="L188" class="LineNr">188 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L188'>Dump_trace</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, print trace lines to screen</span> -<span id="L189" class="LineNr">189 </span>string <a href='003trace.cc.html#L189'>Dump_label</a> = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Comment">// if set, print trace lines matching a single label to screen</span> +<span id="L186" class="LineNr">186 </span><span class="Normal">bool</span> <span class="Special">Hide_errors</span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, don't print even error trace lines to screen</span> +<span id="L187" class="LineNr">187 </span><span class="Normal">bool</span> <span class="Special">Hide_warnings</span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, don't print warnings to screen</span> +<span id="L188" class="LineNr">188 </span><span class="Normal">bool</span> <span class="Special"><a href='003trace.cc.html#L188'>Dump_trace</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, print trace lines to screen</span> +<span id="L189" class="LineNr">189 </span>string <span class="Special"><a href='003trace.cc.html#L189'>Dump_label</a></span> = <span class="Constant">""</span><span class="Delimiter">;</span> <span class="Comment">// if set, print trace lines matching a single label to screen</span> <span id="L190" class="LineNr">190 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L191" class="LineNr">191 </span>Hide_errors =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L192" class="LineNr">192 </span>Hide_warnings =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L193" class="LineNr">193 </span><a href='003trace.cc.html#L188'>Dump_trace</a> = <a href='003trace.cc.html#L179'>Flag_dump_trace</a><span class="Delimiter">;</span> -<span id="L194" class="LineNr">194 </span><a href='003trace.cc.html#L189'>Dump_label</a> = <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L191" class="LineNr">191 </span><span class="Special">Hide_errors</span> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L192" class="LineNr">192 </span><span class="Special">Hide_warnings</span> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L193" class="LineNr">193 </span><span class="Special"><a href='003trace.cc.html#L188'>Dump_trace</a></span> = <span class="Special"><a href='003trace.cc.html#L179'>Flag_dump_trace</a></span><span class="Delimiter">;</span> +<span id="L194" class="LineNr">194 </span><span class="Special"><a href='003trace.cc.html#L189'>Dump_label</a></span> = <span class="Constant">""</span><span class="Delimiter">;</span> <span id="L195" class="LineNr">195 </span><span class="Comment">//: Never dump warnings in scenarios</span> <span id="L196" class="LineNr">196 </span><span class="Delimiter">:(before "End Test Setup")</span> -<span id="L197" class="LineNr">197 </span>Hide_warnings =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L197" class="LineNr">197 </span><span class="Special">Hide_warnings</span> =<span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L198" class="LineNr">198 </span> <span id="L199" class="LineNr">199 </span><span class="Delimiter">:(before "End Includes")</span> <span id="L200" class="LineNr">200 </span><span class="Comment">#define CLEAR_TRACE delete Trace_stream, Trace_stream = new trace_stream;</span> @@ -276,24 +277,24 @@ if ('onhashchange' in window) { <span id="L217" class="LineNr">217 </span><span class="Comment">// Inside tests, fail any tests that displayed (unexpected) errors.</span> <span id="L218" class="LineNr">218 </span><span class="Comment">// Expected errors in tests should always be hidden and silently checked for.</span> <span id="L219" class="LineNr">219 </span><span class="Delimiter">:(before "End Test Teardown")</span> -<span id="L220" class="LineNr">220 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a> && !Hide_errors && <a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L221" class="LineNr">221 </span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L220" class="LineNr">220 </span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> && !<span class="Special">Hide_errors</span> && <a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L221" class="LineNr">221 </span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L222" class="LineNr">222 </span><span class="Delimiter">}</span> <span id="L223" class="LineNr">223 </span><span class="Delimiter">:(code)</span> <span id="L224" class="LineNr">224 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L225" class="LineNr">225 </span> <span class="Identifier">return</span> <a href='003trace.cc.html#L175'>Trace_errors</a> > <span class="Constant">0</span> || trace_count<span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L225" class="LineNr">225 </span> <span class="Identifier">return</span> <span class="Special"><a href='003trace.cc.html#L175'>Trace_errors</a></span> > <span class="Constant">0</span> || trace_count<span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">)</span> > <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L226" class="LineNr">226 </span><span class="Delimiter">}</span> <span id="L227" class="LineNr">227 </span> <span id="L228" class="LineNr">228 </span><span class="Delimiter">:(before "End Types")</span> <span id="L229" class="LineNr">229 </span><span class="Normal">struct</span> end <span class="Delimiter">{};</span> <span id="L230" class="LineNr">230 </span><span class="Delimiter">:(code)</span> <span id="L231" class="LineNr">231 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& os<span class="Delimiter">,</span> end <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L232" class="LineNr">232 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">)</span> <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L147'>newline</a><span class="Delimiter">();</span> +<span id="L232" class="LineNr">232 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">)</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L147'>newline</a><span class="Delimiter">();</span> <span id="L233" class="LineNr">233 </span> <span class="Identifier">return</span> os<span class="Delimiter">;</span> <span id="L234" class="LineNr">234 </span><span class="Delimiter">}</span> <span id="L235" class="LineNr">235 </span> <span id="L236" class="LineNr">236 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L237" class="LineNr">237 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L237'>Save_trace</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, write out trace to disk</span> +<span id="L237" class="LineNr">237 </span><span class="Normal">bool</span> <span class="Special"><a href='003trace.cc.html#L237'>Save_trace</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// if set, write out trace to disk</span> <span id="L238" class="LineNr">238 </span> <span id="L239" class="LineNr">239 </span><span class="Comment">// Trace_stream is a resource, lease_tracer uses RAII to manage it.</span> <span id="L240" class="LineNr">240 </span><span class="Delimiter">:(before "End Types")</span> @@ -302,10 +303,10 @@ if ('onhashchange' in window) { <span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L247'>~lease_tracer</a><span class="Delimiter">();</span> <span id="L244" class="LineNr">244 </span><span class="Delimiter">};</span> <span id="L245" class="LineNr">245 </span><span class="Delimiter">:(code)</span> -<span id="L246" class="LineNr">246 </span>lease_tracer::lease_tracer<span class="Delimiter">()</span> <span class="Delimiter">{</span> <a href='003trace.cc.html#L174'>Trace_stream</a> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> +<span id="L246" class="LineNr">246 </span>lease_tracer::lease_tracer<span class="Delimiter">()</span> <span class="Delimiter">{</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span> = <span class="Normal">new</span> trace_stream<span class="Delimiter">;</span> <span class="Delimiter">}</span> <span id="L247" class="LineNr">247 </span>lease_tracer::<a href='003trace.cc.html#L247'>~lease_tracer</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L248" class="LineNr">248 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L237'>Save_trace</a><span class="Delimiter">)</span> <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L133'>save</a><span class="Delimiter">();</span> -<span id="L249" class="LineNr">249 </span> <span class="Normal">delete</span> <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">,</span> <a href='003trace.cc.html#L174'>Trace_stream</a> = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L248" class="LineNr">248 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L237'>Save_trace</a></span><span class="Delimiter">)</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L133'>save</a><span class="Delimiter">();</span> +<span id="L249" class="LineNr">249 </span> <span class="Normal">delete</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">,</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span> = <span class="Constant">NULL</span><span class="Delimiter">;</span> <span id="L250" class="LineNr">250 </span><span class="Delimiter">}</span> <span id="L251" class="LineNr">251 </span><span class="Delimiter">:(before "End Includes")</span> <span id="L252" class="LineNr">252 </span><span class="Comment">#define START_TRACING_UNTIL_END_OF_SCOPE lease_tracer leased_tracer;</span> @@ -317,19 +318,19 @@ if ('onhashchange' in window) { <span id="L258" class="LineNr">258 </span> <span id="L259" class="LineNr">259 </span><span class="Comment">#define CHECK_TRACE_CONTAINS_ERRORS() CHECK(trace_contains_errors())</span> <span id="L260" class="LineNr">260 </span><span class="Comment">#define CHECK_TRACE_DOESNT_CONTAIN_ERRORS() \</span> -<span id="L261" class="LineNr">261 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a> && <a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> \ -<span id="L262" class="LineNr">262 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): unexpected errors</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> \ +<span id="L261" class="LineNr">261 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> && <a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> \ +<span id="L262" class="LineNr">262 </span> cerr << <span class="Constant">"\nF - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): unexpected errors\n"</span><span class="Delimiter">;</span> \ <span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">"error"</span><span class="Delimiter">);</span> \ -<span id="L264" class="LineNr">264 </span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ +<span id="L264" class="LineNr">264 </span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ <span id="L265" class="LineNr">265 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> \ <span id="L266" class="LineNr">266 </span> <span class="Delimiter">}</span> <span id="L267" class="LineNr">267 </span> <span id="L268" class="LineNr">268 </span><span class="Comment">#define CHECK_TRACE_COUNT(label, count) \</span> -<span id="L269" class="LineNr">269 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='002test.cc.html#L21'>Passed</a> && trace_count<span class="Delimiter">(</span>label<span class="Delimiter">)</span> != <span class="Delimiter">(</span>count<span class="Delimiter">))</span> <span class="Delimiter">{</span> \ -<span id="L270" class="LineNr">270 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): trace_count of "</span> << label << <span class="Constant">" should be "</span> << count << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> \ +<span id="L269" class="LineNr">269 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> && trace_count<span class="Delimiter">(</span>label<span class="Delimiter">)</span> != <span class="Delimiter">(</span>count<span class="Delimiter">))</span> <span class="Delimiter">{</span> \ +<span id="L270" class="LineNr">270 </span> cerr << <span class="Constant">"\nF - "</span> << __FUNCTION__ << <span class="Constant">"("</span> << <span class="Constant">__FILE__</span> << <span class="Constant">":"</span> << <span class="Constant">__LINE__</span> << <span class="Constant">"): trace_count of "</span> << label << <span class="Constant">" should be "</span> << count << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> \ <span id="L271" class="LineNr">271 </span> cerr << <span class="Constant">" got "</span> << trace_count<span class="Delimiter">(</span>label<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span class="Comment">/*</span><span class="Comment"> multiple eval </span><span class="Comment">*/</span> \ <span id="L272" class="LineNr">272 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> \ -<span id="L273" class="LineNr">273 </span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ +<span id="L273" class="LineNr">273 </span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ <span id="L274" class="LineNr">274 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">/*</span><span class="Comment"> Currently we stop at the very first failure. </span><span class="Comment">*/</span> \ <span id="L275" class="LineNr">275 </span> <span class="Delimiter">}</span> <span id="L276" class="LineNr">276 </span> @@ -337,8 +338,8 @@ if ('onhashchange' in window) { <span id="L278" class="LineNr">278 </span> <span id="L279" class="LineNr">279 </span><span class="Delimiter">:(code)</span> <span id="L280" class="LineNr">280 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L280'>check_trace_contents</a><span class="Delimiter">(</span>string FUNCTION<span class="Delimiter">,</span> string <span class="Normal">FILE</span><span class="Delimiter">,</span> <span class="Normal">int</span> LINE<span class="Delimiter">,</span> string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L281" class="LineNr">281 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Passed<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L282" class="LineNr">282 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L281" class="LineNr">281 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!<span class="Special"><a href='002test.cc.html#L21'>Passed</a></span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L282" class="LineNr">282 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!<span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L283" class="LineNr">283 </span> vector<string> expected_lines = <a href='003trace.cc.html#L374'>split</a><span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">"^D"</span><span class="Delimiter">);</span> <span id="L284" class="LineNr">284 </span> <span class="Normal">int</span> curr_expected_line = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L285" class="LineNr">285 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>curr_expected_line < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">)</span> && expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">).</span>empty<span class="Delimiter">())</span> @@ -346,7 +347,7 @@ if ('onhashchange' in window) { <span id="L287" class="LineNr">287 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr_expected_line == <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L288" class="LineNr">288 </span> string label<span class="Delimiter">,</span> <a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">;</span> <span id="L289" class="LineNr">289 </span> <a href='003trace.cc.html#L312'>split_label_contents</a><span class="Delimiter">(</span>expected_lines<span class="Delimiter">.</span>at<span class="Delimiter">(</span>curr_expected_line<span class="Delimiter">),</span> &label<span class="Delimiter">,</span> &contents<span class="Delimiter">);</span> -<span id="L290" class="LineNr">290 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L290" class="LineNr">290 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L291" class="LineNr">291 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L292" class="LineNr">292 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L74'>contents</a> != <a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L293" class="LineNr">293 </span> ++curr_expected_line<span class="Delimiter">;</span> @@ -357,14 +358,14 @@ if ('onhashchange' in window) { <span id="L298" class="LineNr">298 </span> <span class="Delimiter">}</span> <span id="L299" class="LineNr">299 </span> <span id="L300" class="LineNr">300 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L325'>line_exists_anywhere</a><span class="Delimiter">(</span>label<span class="Delimiter">,</span> <a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L301" class="LineNr">301 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << <span class="Normal">FILE</span> << <span class="Constant">":"</span> << LINE << <span class="Constant">"): <a href='011run.cc.html#L117'>line</a> ["</span> << label << <span class="Constant">": "</span> << <a href='003trace.cc.html#L74'>contents</a> << <span class="Constant">"] out of order in <a href='003trace.cc.html#L203'>trace</a>:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L301" class="LineNr">301 </span> cerr << <span class="Constant">"\nF - "</span> << FUNCTION << <span class="Constant">"("</span> << <span class="Normal">FILE</span> << <span class="Constant">":"</span> << LINE << <span class="Constant">"): <a href='011run.cc.html#L117'>line</a> ["</span> << label << <span class="Constant">": "</span> << <a href='003trace.cc.html#L74'>contents</a> << <span class="Constant">"] out of order in <a href='003trace.cc.html#L203'>trace</a>:\n"</span><span class="Delimiter">;</span> <span id="L302" class="LineNr">302 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> <span id="L303" class="LineNr">303 </span> <span class="Delimiter">}</span> <span id="L304" class="LineNr">304 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L305" class="LineNr">305 </span> cerr << <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">F - "</span> << FUNCTION << <span class="Constant">"("</span> << <span class="Normal">FILE</span> << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << <a href='003trace.cc.html#L74'>contents</a> << <span class="Constant">"] in <a href='003trace.cc.html#L203'>trace</a>:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L305" class="LineNr">305 </span> cerr << <span class="Constant">"\nF - "</span> << FUNCTION << <span class="Constant">"("</span> << <span class="Normal">FILE</span> << <span class="Constant">":"</span> << LINE << <span class="Constant">"): missing ["</span> << <a href='003trace.cc.html#L74'>contents</a> << <span class="Constant">"] in <a href='003trace.cc.html#L203'>trace</a>:\n"</span><span class="Delimiter">;</span> <span id="L306" class="LineNr">306 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> <span id="L307" class="LineNr">307 </span> <span class="Delimiter">}</span> -<span id="L308" class="LineNr">308 </span> <a href='002test.cc.html#L21'>Passed</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L308" class="LineNr">308 </span> <span class="Special"><a href='002test.cc.html#L21'>Passed</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L309" class="LineNr">309 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L310" class="LineNr">310 </span><span class="Delimiter">}</span> <span id="L311" class="LineNr">311 </span> @@ -382,7 +383,7 @@ if ('onhashchange' in window) { <span id="L323" class="LineNr">323 </span><span class="Delimiter">}</span> <span id="L324" class="LineNr">324 </span> <span id="L325" class="LineNr">325 </span><span class="Normal">bool</span> <a href='003trace.cc.html#L325'>line_exists_anywhere</a><span class="Delimiter">(</span><span class="Normal">const</span> string& label<span class="Delimiter">,</span> <span class="Normal">const</span> string& <a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L326" class="LineNr">326 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L326" class="LineNr">326 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L327" class="LineNr">327 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label != p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L328" class="LineNr">328 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L74'>contents</a> == <a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L329" class="LineNr">329 </span> <span class="Delimiter">}</span> @@ -394,9 +395,9 @@ if ('onhashchange' in window) { <span id="L335" class="LineNr">335 </span><span class="Delimiter">}</span> <span id="L336" class="LineNr">336 </span> <span id="L337" class="LineNr">337 </span><span class="Normal">int</span> trace_count<span class="Delimiter">(</span>string label<span class="Delimiter">,</span> string <a href='011run.cc.html#L117'>line</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L338" class="LineNr">338 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L338" class="LineNr">338 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!<span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L339" class="LineNr">339 </span> <span class="Normal">long</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L340" class="LineNr">340 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L340" class="LineNr">340 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L341" class="LineNr">341 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L342" class="LineNr">342 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L117'>line</a> == <span class="Constant">""</span> || <a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span><a href='011run.cc.html#L117'>line</a><span class="Delimiter">)</span> == <a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">))</span> <span id="L343" class="LineNr">343 </span> ++result<span class="Delimiter">;</span> @@ -406,9 +407,9 @@ if ('onhashchange' in window) { <span id="L347" class="LineNr">347 </span><span class="Delimiter">}</span> <span id="L348" class="LineNr">348 </span> <span id="L349" class="LineNr">349 </span><span class="Normal">int</span> <a href='003trace.cc.html#L349'>trace_count_prefix</a><span class="Delimiter">(</span>string label<span class="Delimiter">,</span> string prefix<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L350" class="LineNr">350 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!Trace_stream<span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L350" class="LineNr">350 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!<span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L351" class="LineNr">351 </span> <span class="Normal">long</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L352" class="LineNr">352 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L352" class="LineNr">352 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>vector<trace_line>::iterator p = <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L110'>past_lines</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L353" class="LineNr">353 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>label == p<span class="Delimiter">-></span>label<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L354" class="LineNr">354 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L93'>starts_with</a><span class="Delimiter">(</span><a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span>p<span class="Delimiter">-></span><a href='003trace.cc.html#L74'>contents</a><span class="Delimiter">),</span> <a href='003trace.cc.html#L398'>trim</a><span class="Delimiter">(</span>prefix<span class="Delimiter">)))</span> <span id="L355" class="LineNr">355 </span> ++result<span class="Delimiter">;</span> @@ -424,7 +425,7 @@ if ('onhashchange' in window) { <span id="L365" class="LineNr">365 </span><span class="Normal">bool</span> trace_doesnt_contain<span class="Delimiter">(</span>string expected<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L366" class="LineNr">366 </span> vector<string> tmp = <a href='003trace.cc.html#L389'>split_first</a><span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <span class="Constant">": "</span><span class="Delimiter">);</span> <span id="L367" class="LineNr">367 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>tmp<span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L368" class="LineNr">368 </span> <a href='003trace.cc.html#L210'>raise</a> << expected << <span class="Constant">": missing label or <a href='003trace.cc.html#L74'>contents</a> in <a href='003trace.cc.html#L203'>trace</a> <a href='011run.cc.html#L117'>line</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L368" class="LineNr">368 </span> <a href='003trace.cc.html#L210'>raise</a> << expected << <span class="Constant">": missing label or <a href='003trace.cc.html#L74'>contents</a> in <a href='003trace.cc.html#L203'>trace</a> line\n"</span> << end<span class="Delimiter">();</span> <span id="L369" class="LineNr">369 </span> assert<span class="Delimiter">(</span><span class="Constant">false</span><span class="Delimiter">);</span> <span id="L370" class="LineNr">370 </span> <span class="Delimiter">}</span> <span id="L371" class="LineNr">371 </span> <span class="Identifier">return</span> trace_doesnt_contain<span class="Delimiter">(</span>tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> tmp<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> diff --git a/html/subx/003trace.test.cc.html b/html/subx/003trace.test.cc.html index e6e3689c..243c5075 100644 --- a/html/subx/003trace.test.cc.html +++ b/html/subx/003trace.test.cc.html @@ -21,7 +21,6 @@ a:hover { text-decoration: underline; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.cSpecial { color: #008000; } --> </style> @@ -87,7 +86,7 @@ if ('onhashchange' in window) { <span id="L29" class="LineNr"> 29 </span><span class="Delimiter">}</span> <span id="L30" class="LineNr"> 30 </span> <span id="L31" class="LineNr"> 31 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L31'>test_trace_ignores_trailing_whitespace</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L32" class="LineNr"> 32 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L32" class="LineNr"> 32 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo\n"</span> << end<span class="Delimiter">();</span> <span id="L33" class="LineNr"> 33 </span> <a href='003trace.cc.html#L257'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span><span class="Constant">"test layer 1: foo"</span><span class="Delimiter">);</span> <span id="L34" class="LineNr"> 34 </span><span class="Delimiter">}</span> <span id="L35" class="LineNr"> 35 </span> @@ -116,7 +115,7 @@ if ('onhashchange' in window) { <span id="L58" class="LineNr"> 58 </span><span class="Delimiter">}</span> <span id="L59" class="LineNr"> 59 </span> <span id="L60" class="LineNr"> 60 </span><span class="Normal">void</span> <a href='003trace.test.cc.html#L60'>test_trace_count_ignores_trailing_whitespace</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">)</span> << <span class="Constant">"foo\n"</span> << end<span class="Delimiter">();</span> <span id="L62" class="LineNr"> 62 </span> <a href='002test.cc.html#L31'>CHECK_EQ</a><span class="Delimiter">(</span>trace_count<span class="Delimiter">(</span><span class="Constant">"test layer 1"</span><span class="Delimiter">,</span> <span class="Constant">"foo"</span><span class="Delimiter">),</span> <span class="Constant">1</span><span class="Delimiter">);</span> <span id="L63" class="LineNr"> 63 </span><span class="Delimiter">}</span> <span id="L64" class="LineNr"> 64 </span> diff --git a/html/subx/010---vm.cc.html b/html/subx/010---vm.cc.html index 4ea1a84c..6ae23a23 100644 --- a/html/subx/010---vm.cc.html +++ b/html/subx/010---vm.cc.html @@ -20,6 +20,7 @@ a:hover { text-decoration: underline; } .Constant { color: #00a0a0; } .CommentedCode { color: #6c6c6c; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -86,53 +87,53 @@ if ('onhashchange' in window) { <span id="L25" class="LineNr"> 25 </span> <span class="Normal">uint32_t</span> u<span class="Delimiter">;</span> <span id="L26" class="LineNr"> 26 </span><span class="Delimiter">};</span> <span id="L27" class="LineNr"> 27 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L28" class="LineNr"> 28 </span><a href='010---vm.cc.html#L23'>reg</a> Reg[NUM_INT_REGISTERS] = <span class="Delimiter">{</span> <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">}</span> <span class="Delimiter">};</span> +<span id="L28" class="LineNr"> 28 </span><a href='010---vm.cc.html#L23'>reg</a> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[NUM_INT_REGISTERS] = <span class="Delimiter">{</span> <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">}</span> <span class="Delimiter">};</span> <span id="L29" class="LineNr"> 29 </span><span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L29'>EIP</a> = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// preserve null pointer</span> <span id="L30" class="LineNr"> 30 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L31" class="LineNr"> 31 </span>bzero<span class="Delimiter">(</span><a href='010---vm.cc.html#L28'>Reg</a><span class="Delimiter">,</span> <span class="Normal">sizeof</span><span class="Delimiter">(</span><a href='010---vm.cc.html#L28'>Reg</a><span class="Delimiter">));</span> +<span id="L31" class="LineNr"> 31 </span>bzero<span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span><span class="Delimiter">,</span> <span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span><span class="Delimiter">));</span> <span id="L32" class="LineNr"> 32 </span><a href='010---vm.cc.html#L29'>EIP</a> = <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// preserve null pointer</span> <span id="L33" class="LineNr"> 33 </span> <span id="L34" class="LineNr"> 34 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> -<span id="L35" class="LineNr"> 35 </span>cerr << <span class="Constant">" registers</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L35" class="LineNr"> 35 </span>cerr << <span class="Constant">" registers\n"</span><span class="Delimiter">;</span> <span id="L36" class="LineNr"> 36 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> -<span id="L37" class="LineNr"> 37 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"registers"</span><span class="Delimiter">,</span> -<span id="L38" class="LineNr"> 38 </span> <span class="Constant">"SubX currently supports eight 32-bit integer registers. From 0 to 7, they are:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L39" class="LineNr"> 39 </span> <span class="Constant">" <a href='010---vm.cc.html#L13'>EAX</a> <a href='010---vm.cc.html#L14'>ECX</a> <a href='010---vm.cc.html#L15'>EDX</a> <a href='010---vm.cc.html#L16'>EBX</a> <a href='010---vm.cc.html#L17'>ESP</a> <a href='010---vm.cc.html#L18'>EBP</a> <a href='010---vm.cc.html#L19'>ESI</a> <a href='010---vm.cc.html#L20'>EDI</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L40" class="LineNr"> 40 </span> <span class="Constant">"ESP contains the top of the stack.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L41" class="LineNr"> 41 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L42" class="LineNr"> 42 </span> <span class="Constant">"-- 8-bit registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L43" class="LineNr"> 43 </span> <span class="Constant">"Some instructions operate on eight *overlapping* 8-bit registers.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L44" class="LineNr"> 44 </span> <span class="Constant">"From 0 to 7, they are:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L45" class="LineNr"> 45 </span> <span class="Constant">" AL CL DL BL AH CH DH BH</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L46" class="LineNr"> 46 </span> <span class="Constant">"The 8-bit registers overlap with the 32-bit ones. AL is the lowest signicant byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L47" class="LineNr"> 47 </span> <span class="Constant">"of <a href='010---vm.cc.html#L13'>EAX</a>, AH is the second lowest significant byte, and so on.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L48" class="LineNr"> 48 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L49" class="LineNr"> 49 </span> <span class="Constant">"For example, if <a href='010---vm.cc.html#L16'>EBX</a> contains 0x11223344, then BL contains 0x44, and BH contains 0x33.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"There is no way to access bytes within <a href='010---vm.cc.html#L17'>ESP</a>, <a href='010---vm.cc.html#L18'>EBP</a>, <a href='010---vm.cc.html#L19'>ESI</a> or EDI.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"For complete details consult the IA-32 software developer's manual, volume 2,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L54" class="LineNr"> 54 </span> <span class="Constant">"table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing forms with the ModR/M byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L55" class="LineNr"> 55 </span> <span class="Constant">"It is included in this repository as 'modrm.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Constant">"The register encodings are described in the top row of the table, but you'll need</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L57" class="LineNr"> 57 </span> <span class="Constant">"to spend some time with it.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L58" class="LineNr"> 58 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Constant">"-- flag registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Constant">"Various instructions (particularly 'compare') modify one or more of three 1-bit 'flag'</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"registers, as a side-effect:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"- the sign flag (SF): usually set if an arithmetic result is negative, or</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Constant">" <a href='000organization.cc.html#L148'>reset</a> if not.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"- the zero flag (ZF): usually set if a result is zero, or <a href='000organization.cc.html#L148'>reset</a> if not.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"- the overflow flag (OF): usually set if an arithmetic result overflows.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"The flag bits are read by conditional jumps.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"For complete details on how different instructions update the flags, consult the IA-32</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L69" class="LineNr"> 69 </span> <span class="Constant">"manual (volume 2). There's various versions of it online, such as <a href="https://c9x.me/x86">https://c9x.me/x86</a>,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"though of course you'll need to be careful to ignore instructions and flag registers</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L71" class="LineNr"> 71 </span> <span class="Constant">"that SubX doesn't support.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"It isn't simple, but if this is the processor you have running on your computer,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"might as well get good at it.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L37" class="LineNr"> 37 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"registers"</span><span class="Delimiter">,</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Constant">"SubX currently supports eight 32-bit integer registers. From 0 to 7, they are:\n"</span> +<span id="L39" class="LineNr"> 39 </span> <span class="Constant">" <a href='010---vm.cc.html#L13'>EAX</a> <a href='010---vm.cc.html#L14'>ECX</a> <a href='010---vm.cc.html#L15'>EDX</a> <a href='010---vm.cc.html#L16'>EBX</a> <a href='010---vm.cc.html#L17'>ESP</a> <a href='010---vm.cc.html#L18'>EBP</a> <a href='010---vm.cc.html#L19'>ESI</a> EDI\n"</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Constant">"ESP contains the top of the stack.\n"</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Constant">"\n"</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Constant">"-- 8-bit registers\n"</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Constant">"Some instructions operate on eight *overlapping* 8-bit registers.\n"</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Constant">"From 0 to 7, they are:\n"</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Constant">" AL CL DL BL AH CH DH BH\n"</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Constant">"The 8-bit registers overlap with the 32-bit ones. AL is the lowest signicant byte\n"</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Constant">"of <a href='010---vm.cc.html#L13'>EAX</a>, AH is the second lowest significant byte, and so on.\n"</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Constant">"\n"</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Constant">"For example, if <a href='010---vm.cc.html#L16'>EBX</a> contains 0x11223344, then BL contains 0x44, and BH contains 0x33.\n"</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Constant">"\n"</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Constant">"There is no way to access bytes within <a href='010---vm.cc.html#L17'>ESP</a>, <a href='010---vm.cc.html#L18'>EBP</a>, <a href='010---vm.cc.html#L19'>ESI</a> or EDI.\n"</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Constant">"\n"</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Constant">"For complete details consult the IA-32 software developer's manual, volume 2,\n"</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Constant">"table 2-2, \"</span><span class="Constant">32</span>-bit addressing forms with the ModR/<span class="Special">M</span> byte\<span class="Constant">".\n"</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Constant">"It is included in this repository as 'modrm.pdf'.\n"</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Constant">"The register encodings are described in the top row of the table, but you'll need\n"</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Constant">"to spend some time with it.\n"</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Constant">"\n"</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Constant">"-- flag registers\n"</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Constant">"Various instructions (particularly 'compare') modify one or more of three 1-bit 'flag'\n"</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"registers, as a side-effect:\n"</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"- the sign flag (SF): usually set if an arithmetic result is negative, or\n"</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Constant">" <a href='000organization.cc.html#L148'>reset</a> if not.\n"</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"- the zero flag (ZF): usually set if a result is zero, or <a href='000organization.cc.html#L148'>reset</a> if not.\n"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">"- the overflow flag (OF): usually set if an arithmetic result overflows.\n"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"The flag bits are read by conditional jumps.\n"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">"\n"</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"For complete details on how different instructions update the flags, consult the IA-32\n"</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">"manual (volume 2). There's various versions of it online, such as <a href="https://c9x.me/x86">https://c9x.me/x86</a>,\n"</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"though of course you'll need to be careful to ignore instructions and flag registers\n"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Constant">"that SubX doesn't support.\n"</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">"\n"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">"It isn't simple, but if this is the processor you have running on your computer,\n"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"might as well get good at it.\n"</span> <span id="L75" class="LineNr"> 75 </span><span class="Delimiter">);</span> <span id="L76" class="LineNr"> 76 </span> <span id="L77" class="LineNr"> 77 </span><span class="Delimiter">:(before "End Globals")</span> @@ -153,7 +154,7 @@ if ('onhashchange' in window) { <span id="L92" class="LineNr"> 92 </span> <span class="Comment">/*</span><span class="Comment"> arg1 and arg2 must be signed </span><span class="Comment">*/</span> \ <span id="L93" class="LineNr"> 93 </span> <span class="Normal">int64_t</span> tmp = arg1 op arg2<span class="Delimiter">;</span> \ <span id="L94" class="LineNr"> 94 </span> arg1 = arg1 op arg2<span class="Delimiter">;</span> \ -<span id="L95" class="LineNr"> 95 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg1 << end<span class="Delimiter">();</span> \ +<span id="L95" class="LineNr"> 95 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg1 << end<span class="Delimiter">();</span> \ <span id="L96" class="LineNr"> 96 </span> SF = <span class="Delimiter">(</span>arg1 < <span class="Constant">0</span><span class="Delimiter">);</span> \ <span id="L97" class="LineNr"> 97 </span> ZF = <span class="Delimiter">(</span>arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> \ <span id="L98" class="LineNr"> 98 </span> <a href='010---vm.cc.html#L81'>OF</a> = <span class="Delimiter">(</span>arg1 != tmp<span class="Delimiter">);</span> \ @@ -164,7 +165,7 @@ if ('onhashchange' in window) { <span id="L103" class="LineNr">103 </span><span class="Comment">#define BINARY_BITWISE_OP(op, arg1, arg2) { \</span> <span id="L104" class="LineNr">104 </span> <span class="Comment">/*</span><span class="Comment"> arg1 and arg2 must be unsigned </span><span class="Comment">*/</span> \ <span id="L105" class="LineNr">105 </span> arg1 = arg1 op arg2<span class="Delimiter">;</span> \ -<span id="L106" class="LineNr">106 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg1 << end<span class="Delimiter">();</span> \ +<span id="L106" class="LineNr">106 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg1 << end<span class="Delimiter">();</span> \ <span id="L107" class="LineNr">107 </span> SF = <span class="Delimiter">(</span>arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> \ <span id="L108" class="LineNr">108 </span> ZF = <span class="Delimiter">(</span>arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> \ <span id="L109" class="LineNr">109 </span> <a href='010---vm.cc.html#L81'>OF</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> \ @@ -173,299 +174,308 @@ if ('onhashchange' in window) { <span id="L112" class="LineNr">112 </span><span class="SalientComment">//:: simulated RAM</span> <span id="L113" class="LineNr">113 </span> <span id="L114" class="LineNr">114 </span><span class="Delimiter">:(before "End Types")</span> -<span id="L115" class="LineNr">115 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L115'>INITIAL_SEGMENT_SIZE</a> = <span class="Constant">0x1000</span> - <span class="Constant">1</span><span class="Delimiter">;</span> -<span id="L116" class="LineNr">116 </span><span class="Comment">// Subtract one just so we can start the first segment at address 1 without</span> -<span id="L117" class="LineNr">117 </span><span class="Comment">// overflowing the first segment. Other segments will learn to adjust.</span> -<span id="L118" class="LineNr">118 </span> -<span id="L119" class="LineNr">119 </span><span class="Comment">// Like in real-world Linux, we'll allocate RAM for our programs in disjoint</span> -<span id="L120" class="LineNr">120 </span><span class="Comment">// slabs called VMAs or Virtual Memory Areas.</span> -<span id="L121" class="LineNr">121 </span><span class="Normal">struct</span> vma <span class="Delimiter">{</span> -<span id="L122" class="LineNr">122 </span> <span class="Normal">uint32_t</span> start<span class="Delimiter">;</span> <span class="Comment">// inclusive</span> -<span id="L123" class="LineNr">123 </span> <span class="Normal">uint32_t</span> end<span class="Delimiter">;</span> <span class="Comment">// exclusive</span> -<span id="L124" class="LineNr">124 </span> vector<<span class="Normal">uint8_t</span>> <a href='010---vm.cc.html#L124'>_data</a><span class="Delimiter">;</span> -<span id="L125" class="LineNr">125 </span> vma<span class="Delimiter">(</span><span class="Normal">uint32_t</span> s<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> e<span class="Delimiter">)</span> :start<span class="Delimiter">(</span>s<span class="Delimiter">),</span> end<span class="Delimiter">(</span>e<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L126" class="LineNr">126 </span> <a href='010---vm.cc.html#L124'>_data</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span>end-start<span class="Delimiter">);</span> -<span id="L127" class="LineNr">127 </span> <span class="Delimiter">}</span> -<span id="L128" class="LineNr">128 </span> vma<span class="Delimiter">(</span><span class="Normal">uint32_t</span> s<span class="Delimiter">)</span> :start<span class="Delimiter">(</span>s<span class="Delimiter">),</span> end<span class="Delimiter">(</span>s+INITIAL_SEGMENT_SIZE<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L129" class="LineNr">129 </span> <a href='010---vm.cc.html#L124'>_data</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span>end-start<span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L115'>SEGMENT_ALIGNMENT</a> = <span class="Constant">0x1000000</span><span class="Delimiter">;</span> +<span id="L116" class="LineNr">116 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L116'>align_upwards</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> x<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> align<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L117" class="LineNr">117 </span> <span class="Identifier">return</span> <span class="Delimiter">(</span>x+align-<span class="Constant">1</span><span class="Delimiter">)</span> & -<span class="Delimiter">(</span>align<span class="Delimiter">);</span> +<span id="L118" class="LineNr">118 </span><span class="Delimiter">}</span> +<span id="L119" class="LineNr">119 </span> +<span id="L120" class="LineNr">120 </span><span class="Comment">// Like in real-world Linux, we'll allocate RAM for our programs in disjoint</span> +<span id="L121" class="LineNr">121 </span><span class="Comment">// slabs called VMAs or Virtual Memory Areas.</span> +<span id="L122" class="LineNr">122 </span><span class="Normal">struct</span> vma <span class="Delimiter">{</span> +<span id="L123" class="LineNr">123 </span> <span class="Normal">uint32_t</span> start<span class="Delimiter">;</span> <span class="Comment">// inclusive</span> +<span id="L124" class="LineNr">124 </span> <span class="Normal">uint32_t</span> end<span class="Delimiter">;</span> <span class="Comment">// exclusive</span> +<span id="L125" class="LineNr">125 </span> vector<<span class="Normal">uint8_t</span>> <a href='010---vm.cc.html#L125'>_data</a><span class="Delimiter">;</span> +<span id="L126" class="LineNr">126 </span> vma<span class="Delimiter">(</span><span class="Normal">uint32_t</span> s<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> e<span class="Delimiter">)</span> :start<span class="Delimiter">(</span>s<span class="Delimiter">),</span> end<span class="Delimiter">(</span>e<span class="Delimiter">)</span> <span class="Delimiter">{}</span> +<span id="L127" class="LineNr">127 </span> vma<span class="Delimiter">(</span><span class="Normal">uint32_t</span> s<span class="Delimiter">)</span> :start<span class="Delimiter">(</span>s<span class="Delimiter">),</span> end<span class="Delimiter">(</span><a href='010---vm.cc.html#L116'>align_upwards</a><span class="Delimiter">(</span>s+<span class="Constant">1</span><span class="Delimiter">,</span> <a href='010---vm.cc.html#L115'>SEGMENT_ALIGNMENT</a><span class="Delimiter">))</span> <span class="Delimiter">{}</span> +<span id="L128" class="LineNr">128 </span> <span class="Normal">bool</span> <a href='010---vm.cc.html#L128'>match</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L129" class="LineNr">129 </span> <span class="Identifier">return</span> a >= start && a < end<span class="Delimiter">;</span> <span id="L130" class="LineNr">130 </span> <span class="Delimiter">}</span> -<span id="L131" class="LineNr">131 </span> <span class="Normal">bool</span> <a href='010---vm.cc.html#L131'>match</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L132" class="LineNr">132 </span> <span class="Identifier">return</span> a >= start && a < end<span class="Delimiter">;</span> +<span id="L131" class="LineNr">131 </span> <span class="Normal">bool</span> <a href='010---vm.cc.html#L131'>match32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L132" class="LineNr">132 </span> <span class="Identifier">return</span> a >= start && a+<span class="Constant">4</span> <= end<span class="Delimiter">;</span> <span id="L133" class="LineNr">133 </span> <span class="Delimiter">}</span> -<span id="L134" class="LineNr">134 </span> <span class="Normal">bool</span> <a href='010---vm.cc.html#L134'>match32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L135" class="LineNr">135 </span> <span class="Identifier">return</span> a >= start && a+<span class="Constant">4</span> <= end<span class="Delimiter">;</span> -<span id="L136" class="LineNr">136 </span> <span class="Delimiter">}</span> -<span id="L137" class="LineNr">137 </span> <span class="Normal">uint8_t</span>& data<span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L138" class="LineNr">138 </span> assert<span class="Delimiter">(</span><a href='010---vm.cc.html#L131'>match</a><span class="Delimiter">(</span>a<span class="Delimiter">));</span> -<span id="L139" class="LineNr">139 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L124'>_data</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>a-start<span class="Delimiter">);</span> -<span id="L140" class="LineNr">140 </span> <span class="Delimiter">}</span> -<span id="L141" class="LineNr">141 </span> <span class="Normal">void</span> <a href='010---vm.cc.html#L141'>grow_until</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L142" class="LineNr">142 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_end_address < end<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L143" class="LineNr">143 </span> <span class="Comment">// Ugly: vma knows about the global Memory list of vmas</span> -<span id="L144" class="LineNr">144 </span> <span class="Normal">void</span> <a href='010---vm.cc.html#L152'>sanity_check</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> start<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> end<span class="Delimiter">);</span> -<span id="L145" class="LineNr">145 </span> <a href='010---vm.cc.html#L152'>sanity_check</a><span class="Delimiter">(</span>start<span class="Delimiter">,</span> new_end_address<span class="Delimiter">);</span> -<span id="L146" class="LineNr">146 </span> end = new_end_address<span class="Delimiter">;</span> -<span id="L147" class="LineNr">147 </span> <a href='010---vm.cc.html#L124'>_data</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span>new_end_address - start<span class="Delimiter">);</span> -<span id="L148" class="LineNr">148 </span> <span class="Delimiter">}</span> -<span id="L149" class="LineNr">149 </span> <span class="Comment">// End vma Methods</span> -<span id="L150" class="LineNr">150 </span><span class="Delimiter">};</span> -<span id="L151" class="LineNr">151 </span><span class="Delimiter">:(code)</span> -<span id="L152" class="LineNr">152 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L152'>sanity_check</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> start<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> end<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L153" class="LineNr">153 </span> <span class="Normal">bool</span> dup_found =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L154" class="LineNr">154 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L155" class="LineNr">155 </span> <span class="Normal">const</span> vma& curr = <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L156" class="LineNr">156 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start == start<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L157" class="LineNr">157 </span> assert<span class="Delimiter">(</span>!dup_found<span class="Delimiter">);</span> -<span id="L158" class="LineNr">158 </span> dup_found =<span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L159" class="LineNr">159 </span> <span class="Delimiter">}</span> -<span id="L160" class="LineNr">160 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start > start<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L161" class="LineNr">161 </span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start > end<span class="Delimiter">);</span> -<span id="L162" class="LineNr">162 </span> <span class="Delimiter">}</span> -<span id="L163" class="LineNr">163 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start < start<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L164" class="LineNr">164 </span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>end < start<span class="Delimiter">);</span> -<span id="L165" class="LineNr">165 </span> <span class="Delimiter">}</span> -<span id="L166" class="LineNr">166 </span> <span class="Delimiter">}</span> -<span id="L167" class="LineNr">167 </span><span class="Delimiter">}</span> -<span id="L168" class="LineNr">168 </span> -<span id="L169" class="LineNr">169 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L170" class="LineNr">170 </span><span class="Comment">// RAM is made of VMAs.</span> -<span id="L171" class="LineNr">171 </span>vector<vma> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">;</span> -<span id="L172" class="LineNr">172 </span><span class="Delimiter">:(code)</span> -<span id="L173" class="LineNr">173 </span><span class="Comment">// The first 3 VMAs are special. When loading ELF binaries in later layers,</span> -<span id="L174" class="LineNr">174 </span><span class="Comment">// we'll assume that the first VMA is for code, the second is for data</span> -<span id="L175" class="LineNr">175 </span><span class="Comment">// (including the heap), and the third for the stack.</span> -<span id="L176" class="LineNr">176 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L176'>grow_code_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L177" class="LineNr">177 </span> assert<span class="Delimiter">(</span>!Mem<span class="Delimiter">.</span>empty<span class="Delimiter">());</span> -<span id="L178" class="LineNr">178 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span><a href='010---vm.cc.html#L141'>grow_until</a><span class="Delimiter">(</span>new_end_address<span class="Delimiter">);</span> -<span id="L179" class="LineNr">179 </span><span class="Delimiter">}</span> -<span id="L180" class="LineNr">180 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L180'>grow_data_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L181" class="LineNr">181 </span> assert<span class="Delimiter">(</span><a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L182" class="LineNr">182 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span><a href='010---vm.cc.html#L141'>grow_until</a><span class="Delimiter">(</span>new_end_address<span class="Delimiter">);</span> -<span id="L183" class="LineNr">183 </span><span class="Delimiter">}</span> -<span id="L184" class="LineNr">184 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L185" class="LineNr">185 </span><span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L185'>End_of_program</a> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// when the program executes past this address in tests we'll stop the test</span> -<span id="L186" class="LineNr">186 </span><span class="Comment">// The stack grows downward. Can't increase its size for now.</span> -<span id="L187" class="LineNr">187 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L188" class="LineNr">188 </span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> -<span id="L189" class="LineNr">189 </span><a href='010---vm.cc.html#L185'>End_of_program</a> = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L190" class="LineNr">190 </span><span class="Delimiter">:(code)</span> -<span id="L191" class="LineNr">191 </span><span class="Comment">// These helpers depend on Mem being laid out contiguously (so you can't use a</span> -<span id="L192" class="LineNr">192 </span><span class="Comment">// map, etc.) and on the host also being little-endian.</span> -<span id="L193" class="LineNr">193 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L193'>read_mem_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L194" class="LineNr">194 </span> <span class="Normal">uint8_t</span>* handle = <a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> <span class="Comment">// error messages get printed here</span> -<span id="L195" class="LineNr">195 </span> <span class="Identifier">return</span> handle ? *handle : <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L196" class="LineNr">196 </span><span class="Delimiter">}</span> -<span id="L197" class="LineNr">197 </span><span class="Normal">inline</span> <span class="Normal">int8_t</span> <a href='010---vm.cc.html#L197'>read_mem_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L198" class="LineNr">198 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int8_t</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L193'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> -<span id="L199" class="LineNr">199 </span><span class="Delimiter">}</span> -<span id="L200" class="LineNr">200 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L201" class="LineNr">201 </span> <span class="Normal">uint32_t</span>* handle = <a href='010---vm.cc.html#L224'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> <span class="Comment">// error messages get printed here</span> -<span id="L202" class="LineNr">202 </span> <span class="Identifier">return</span> handle ? *handle : <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L203" class="LineNr">203 </span><span class="Delimiter">}</span> -<span id="L204" class="LineNr">204 </span><span class="Normal">inline</span> <span class="Normal">int32_t</span> <a href='010---vm.cc.html#L204'>read_mem_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L205" class="LineNr">205 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> -<span id="L206" class="LineNr">206 </span><span class="Delimiter">}</span> -<span id="L207" class="LineNr">207 </span> -<span id="L208" class="LineNr">208 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span>* <a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L209" class="LineNr">209 </span> <span class="Normal">uint8_t</span>* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> -<span id="L210" class="LineNr">210 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L211" class="LineNr">211 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010---vm.cc.html#L131'>match</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L212" class="LineNr">212 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> -<span id="L213" class="LineNr">213 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" is in two <a href='011run.cc.html#L100'>segments</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L214" class="LineNr">214 </span> result = &Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L215" class="LineNr">215 </span> <span class="Delimiter">}</span> -<span id="L216" class="LineNr">216 </span> <span class="Delimiter">}</span> -<span id="L217" class="LineNr">217 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> -<span id="L218" class="LineNr">218 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Tried to access uninitialized memory at address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L219" class="LineNr">219 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L220" class="LineNr">220 </span><span class="Delimiter">}</span> -<span id="L221" class="LineNr">221 </span><span class="Normal">inline</span> <span class="Normal">int8_t</span>* <a href='010---vm.cc.html#L221'>mem_addr_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L222" class="LineNr">222 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">int8_t</span>*><span class="Delimiter">(</span><a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> -<span id="L223" class="LineNr">223 </span><span class="Delimiter">}</span> -<span id="L224" class="LineNr">224 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span>* <a href='010---vm.cc.html#L224'>mem_addr_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L225" class="LineNr">225 </span> <span class="Normal">uint32_t</span>* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> -<span id="L226" class="LineNr">226 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L227" class="LineNr">227 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010---vm.cc.html#L134'>match32</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L228" class="LineNr">228 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> -<span id="L229" class="LineNr">229 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" is in two <a href='011run.cc.html#L100'>segments</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L230" class="LineNr">230 </span> result = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>&Mem<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">(</span>addr<span class="Delimiter">));</span> -<span id="L231" class="LineNr">231 </span> <span class="Delimiter">}</span> -<span id="L232" class="LineNr">232 </span> <span class="Delimiter">}</span> -<span id="L233" class="LineNr">233 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L234" class="LineNr">234 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Tried to access uninitialized memory at address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L235" class="LineNr">235 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"The entire 4-byte <a href='011run.cc.html#L123'>word</a> should be initialized and lie in a single segment.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L236" class="LineNr">236 </span> <span class="Delimiter">}</span> -<span id="L237" class="LineNr">237 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L238" class="LineNr">238 </span><span class="Delimiter">}</span> -<span id="L239" class="LineNr">239 </span><span class="Normal">inline</span> <span class="Normal">int32_t</span>* <a href='010---vm.cc.html#L239'>mem_addr_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L240" class="LineNr">240 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">int32_t</span>*><span class="Delimiter">(</span><a href='010---vm.cc.html#L224'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> -<span id="L241" class="LineNr">241 </span><span class="Delimiter">}</span> -<span id="L242" class="LineNr">242 </span><span class="Comment">// helper for some syscalls. But read-only.</span> -<span id="L243" class="LineNr">243 </span><span class="Normal">inline</span> <span class="Normal">const</span> <span class="Normal">char</span>* <a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L244" class="LineNr">244 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">const</span> <span class="Normal">char</span>*><span class="Delimiter">(</span><a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> -<span id="L245" class="LineNr">245 </span><span class="Delimiter">}</span> -<span id="L246" class="LineNr">246 </span><span class="Normal">inline</span> string <a href='010---vm.cc.html#L246'>mem_addr_string</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L247" class="LineNr">247 </span> ostringstream out<span class="Delimiter">;</span> -<span id="L248" class="LineNr">248 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> -<span id="L249" class="LineNr">249 </span> out << <a href='010---vm.cc.html#L193'>read_mem_u8</a><span class="Delimiter">(</span>addr+i<span class="Delimiter">);</span> -<span id="L250" class="LineNr">250 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span id="L251" class="LineNr">251 </span><span class="Delimiter">}</span> -<span id="L252" class="LineNr">252 </span> -<span id="L253" class="LineNr">253 </span> -<span id="L254" class="LineNr">254 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L254'>write_mem_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L255" class="LineNr">255 </span> <span class="Normal">uint8_t</span>* handle = <a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L256" class="LineNr">256 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> -<span id="L257" class="LineNr">257 </span><span class="Delimiter">}</span> -<span id="L258" class="LineNr">258 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L258'>write_mem_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">int8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L259" class="LineNr">259 </span> <span class="Normal">int8_t</span>* handle = <a href='010---vm.cc.html#L221'>mem_addr_i8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L260" class="LineNr">260 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> -<span id="L261" class="LineNr">261 </span><span class="Delimiter">}</span> -<span id="L262" class="LineNr">262 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L262'>write_mem_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L263" class="LineNr">263 </span> <span class="Normal">uint32_t</span>* handle = <a href='010---vm.cc.html#L224'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L264" class="LineNr">264 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> -<span id="L265" class="LineNr">265 </span><span class="Delimiter">}</span> -<span id="L266" class="LineNr">266 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L266'>write_mem_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">int32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L267" class="LineNr">267 </span> <span class="Normal">int32_t</span>* handle = <a href='010---vm.cc.html#L239'>mem_addr_i32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L268" class="LineNr">268 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> -<span id="L269" class="LineNr">269 </span><span class="Delimiter">}</span> -<span id="L270" class="LineNr">270 </span> -<span id="L271" class="LineNr">271 </span><span class="Normal">inline</span> <span class="Normal">bool</span> <a href='010---vm.cc.html#L271'>already_allocated</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L272" class="LineNr">272 </span> <span class="Normal">bool</span> result =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L273" class="LineNr">273 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L274" class="LineNr">274 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010---vm.cc.html#L131'>match</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L275" class="LineNr">275 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> -<span id="L276" class="LineNr">276 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" is in two <a href='011run.cc.html#L100'>segments</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L277" class="LineNr">277 </span> result =<span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L278" class="LineNr">278 </span> <span class="Delimiter">}</span> -<span id="L279" class="LineNr">279 </span> <span class="Delimiter">}</span> -<span id="L280" class="LineNr">280 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L281" class="LineNr">281 </span><span class="Delimiter">}</span> -<span id="L282" class="LineNr">282 </span> -<span id="L283" class="LineNr">283 </span><span class="SalientComment">//:: core interpreter loop</span> -<span id="L284" class="LineNr">284 </span> -<span id="L285" class="LineNr">285 </span><span class="Delimiter">:(code)</span> -<span id="L286" class="LineNr">286 </span><span class="Comment">// skeleton of how x86 instructions are decoded</span> -<span id="L287" class="LineNr">287 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L287'>run_one_instruction</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L288" class="LineNr">288 </span> <span class="Normal">uint8_t</span> op=<span class="Constant">0</span><span class="Delimiter">,</span> op2=<span class="Constant">0</span><span class="Delimiter">,</span> op3=<span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L289" class="LineNr">289 </span> <span class="Comment">// Run One Instruction</span> -<span id="L290" class="LineNr">290 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"inst: 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> -<span id="L291" class="LineNr">291 </span> op = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> -<span id="L292" class="LineNr">292 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L188'>Dump_trace</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L293" class="LineNr">293 </span> cerr << <span class="Constant">"opcode: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L294" class="LineNr">294 </span> cerr << <span class="Constant">"registers at start: "</span><span class="Delimiter">;</span> -<span id="L295" class="LineNr">295 </span> <a href='010---vm.cc.html#L359'>dump_registers</a><span class="Delimiter">();</span> -<span id="L296" class="LineNr">296 </span><span class="CommentedCode">//? dump_stack(); // for debugging; not defined until later layer</span> -<span id="L297" class="LineNr">297 </span> <span class="Delimiter">}</span> -<span id="L298" class="LineNr">298 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L299" class="LineNr">299 </span> <span class="Normal">case</span> <span class="Constant">0xf4</span>: <span class="Comment">// hlt</span> -<span id="L300" class="LineNr">300 </span> <a href='010---vm.cc.html#L29'>EIP</a> = <a href='010---vm.cc.html#L185'>End_of_program</a><span class="Delimiter">;</span> -<span id="L301" class="LineNr">301 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L302" class="LineNr">302 </span> <span class="Comment">// End Single-Byte Opcodes</span> -<span id="L303" class="LineNr">303 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: -<span id="L304" class="LineNr">304 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L305" class="LineNr">305 </span> <span class="Comment">// End Two-Byte Opcodes Starting With 0f</span> -<span id="L306" class="LineNr">306 </span> <span class="Normal">default</span>: -<span id="L307" class="LineNr">307 </span> cerr << <span class="Constant">"unrecognized second opcode after 0f: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L308" class="LineNr">308 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L309" class="LineNr">309 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L310" class="LineNr">310 </span> <span class="Delimiter">}</span> -<span id="L311" class="LineNr">311 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L312" class="LineNr">312 </span> <span class="Normal">case</span> <span class="Constant">0xf2</span>: -<span id="L313" class="LineNr">313 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L314" class="LineNr">314 </span> <span class="Comment">// End Two-Byte Opcodes Starting With f2</span> -<span id="L315" class="LineNr">315 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: -<span id="L316" class="LineNr">316 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op3 = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L317" class="LineNr">317 </span> <span class="Comment">// End Three-Byte Opcodes Starting With f2 0f</span> -<span id="L318" class="LineNr">318 </span> <span class="Normal">default</span>: -<span id="L319" class="LineNr">319 </span> cerr << <span class="Constant">"unrecognized third opcode after f2 0f: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op3<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L320" class="LineNr">320 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L321" class="LineNr">321 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L322" class="LineNr">322 </span> <span class="Delimiter">}</span> -<span id="L323" class="LineNr">323 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L324" class="LineNr">324 </span> <span class="Normal">default</span>: -<span id="L325" class="LineNr">325 </span> cerr << <span class="Constant">"unrecognized second opcode after f2: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L326" class="LineNr">326 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L327" class="LineNr">327 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L328" class="LineNr">328 </span> <span class="Delimiter">}</span> -<span id="L329" class="LineNr">329 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L330" class="LineNr">330 </span> <span class="Normal">case</span> <span class="Constant">0xf3</span>: -<span id="L331" class="LineNr">331 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L332" class="LineNr">332 </span> <span class="Comment">// End Two-Byte Opcodes Starting With f3</span> -<span id="L333" class="LineNr">333 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: -<span id="L334" class="LineNr">334 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op3 = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L335" class="LineNr">335 </span> <span class="Comment">// End Three-Byte Opcodes Starting With f3 0f</span> -<span id="L336" class="LineNr">336 </span> <span class="Normal">default</span>: -<span id="L337" class="LineNr">337 </span> cerr << <span class="Constant">"unrecognized third opcode after f3 0f: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op3<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L338" class="LineNr">338 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L339" class="LineNr">339 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L340" class="LineNr">340 </span> <span class="Delimiter">}</span> -<span id="L341" class="LineNr">341 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L342" class="LineNr">342 </span> <span class="Normal">default</span>: -<span id="L343" class="LineNr">343 </span> cerr << <span class="Constant">"unrecognized second opcode after f3: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L344" class="LineNr">344 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L345" class="LineNr">345 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L346" class="LineNr">346 </span> <span class="Delimiter">}</span> -<span id="L347" class="LineNr">347 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L348" class="LineNr">348 </span> <span class="Normal">default</span>: -<span id="L349" class="LineNr">349 </span> cerr << <span class="Constant">"unrecognized opcode: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L350" class="LineNr">350 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> -<span id="L351" class="LineNr">351 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L352" class="LineNr">352 </span> <span class="Delimiter">}</span> -<span id="L353" class="LineNr">353 </span><span class="Delimiter">}</span> -<span id="L354" class="LineNr">354 </span> -<span id="L355" class="LineNr">355 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L356" class="LineNr">356 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L193'>read_mem_u8</a><span class="Delimiter">(</span>EIP++<span class="Delimiter">);</span> -<span id="L357" class="LineNr">357 </span><span class="Delimiter">}</span> -<span id="L358" class="LineNr">358 </span> -<span id="L359" class="LineNr">359 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L359'>dump_registers</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L360" class="LineNr">360 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='010---vm.cc.html#L21'>NUM_INT_REGISTERS</a><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L361" class="LineNr">361 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> cerr << <span class="Constant">"; "</span><span class="Delimiter">;</span> -<span id="L362" class="LineNr">362 </span> cerr << <span class="Constant">" "</span> << i << <span class="Constant">": "</span> << std::hex << std::setw<span class="Delimiter">(</span><span class="Constant">8</span><span class="Delimiter">)</span> << std::setfill<span class="Delimiter">(</span><span class="Constant">'_'</span><span class="Delimiter">)</span> << Reg[i]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L363" class="LineNr">363 </span> <span class="Delimiter">}</span> -<span id="L364" class="LineNr">364 </span> cerr << <span class="Constant">" -- SF: "</span> << SF << <span class="Constant">"; ZF: "</span> << ZF << <span class="Constant">"; <a href='010---vm.cc.html#L81'>OF</a>: "</span> << <a href='010---vm.cc.html#L81'>OF</a> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L365" class="LineNr">365 </span><span class="Delimiter">}</span> -<span id="L366" class="LineNr">366 </span> -<span id="L367" class="LineNr">367 </span><span class="Comment">//: start tracking supported opcodes</span> -<span id="L368" class="LineNr">368 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L369" class="LineNr">369 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">;</span> -<span id="L370" class="LineNr">370 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">;</span> -<span id="L371" class="LineNr">371 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010---vm.cc.html#L371'>Name_f3</a><span class="Delimiter">;</span> -<span id="L372" class="LineNr">372 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <a href='010---vm.cc.html#L372'>Name_f3_0f</a><span class="Delimiter">;</span> -<span id="L373" class="LineNr">373 </span><span class="Delimiter">:(before "End One-time Setup")</span> -<span id="L374" class="LineNr">374 </span><a href='010---vm.cc.html#L376'>init_op_names</a><span class="Delimiter">();</span> -<span id="L375" class="LineNr">375 </span><span class="Delimiter">:(code)</span> -<span id="L376" class="LineNr">376 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L376'>init_op_names</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L377" class="LineNr">377 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"f4"</span><span class="Delimiter">,</span> <span class="Constant">"halt (hlt)"</span><span class="Delimiter">);</span> -<span id="L378" class="LineNr">378 </span> <span class="Comment">// End Initialize Op Names</span> -<span id="L379" class="LineNr">379 </span><span class="Delimiter">}</span> -<span id="L380" class="LineNr">380 </span> -<span id="L381" class="LineNr">381 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Special-cases(key)")</span> -<span id="L382" class="LineNr">382 </span><span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">"opcodes"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L383" class="LineNr">383 </span> cerr << <span class="Constant">"Opcodes currently supported by SubX:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L384" class="LineNr">384 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> -<span id="L385" class="LineNr">385 </span> cerr << <span class="Constant">" "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L386" class="LineNr">386 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> -<span id="L387" class="LineNr">387 </span> cerr << <span class="Constant">" 0f "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L388" class="LineNr">388 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010---vm.cc.html#L371'>Name_f3</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010---vm.cc.html#L371'>Name_f3</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> -<span id="L389" class="LineNr">389 </span> cerr << <span class="Constant">" f3 "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L390" class="LineNr">390 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <a href='010---vm.cc.html#L372'>Name_f3_0f</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='010---vm.cc.html#L372'>Name_f3_0f</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> -<span id="L391" class="LineNr">391 </span> cerr << <span class="Constant">" f3 0f "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L392" class="LineNr">392 </span> cerr << <span class="Constant">"Run `subx help instructions` for details on <a href='011run.cc.html#L118'>words</a> like 'r32' and 'disp8'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L393" class="LineNr">393 </span> <span class="Constant">"For complete details on these instructions, consult the IA-32 manual (volume 2).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L394" class="LineNr">394 </span> <span class="Constant">"There's various versions of it online, such as <a href="https://c9x.me/x86">https://c9x.me/x86</a>.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L395" class="LineNr">395 </span> <span class="Constant">"The mnemonics in brackets will help you locate each instruction.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L396" class="LineNr">396 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L397" class="LineNr">397 </span><span class="Delimiter">}</span> -<span id="L398" class="LineNr">398 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> -<span id="L399" class="LineNr">399 </span>cerr << <span class="Constant">" opcodes</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L400" class="LineNr">400 </span> -<span id="L401" class="LineNr">401 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L402" class="LineNr">402 </span><span class="Comment">#include <iomanip></span> -<span id="L403" class="LineNr">403 </span><span class="Comment">#define HEXBYTE std::hex << std::setw(2) << std::setfill('0')</span> -<span id="L404" class="LineNr">404 </span><span class="Comment">#define HEXWORD std::hex << std::setw(8) << std::setfill('0')</span> -<span id="L405" class="LineNr">405 </span><span class="Comment">// ugly that iostream doesn't print uint8_t as an integer</span> -<span id="L406" class="LineNr">406 </span><span class="Comment">#define NUM(X) static_cast<int>(X)</span> -<span id="L407" class="LineNr">407 </span><span class="Comment">#include <stdint.h></span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">uint8_t</span>& data<span class="Delimiter">(</span><span class="Normal">uint32_t</span> a<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L135" class="LineNr">135 </span> assert<span class="Delimiter">(</span><a href='010---vm.cc.html#L128'>match</a><span class="Delimiter">(</span>a<span class="Delimiter">));</span> +<span id="L136" class="LineNr">136 </span> <span class="Normal">uint32_t</span> result_index = a-start<span class="Delimiter">;</span> +<span id="L137" class="LineNr">137 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L125'>_data</a><span class="Delimiter">.</span>size<span class="Delimiter">()</span> <= result_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L138" class="LineNr">138 </span> <span class="Normal">const</span> <span class="Normal">int</span> align = <span class="Constant">0x1000</span><span class="Delimiter">;</span> +<span id="L139" class="LineNr">139 </span> <span class="Normal">uint32_t</span> result_size = result_index + <span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// size needed for result_index to be valid</span> +<span id="L140" class="LineNr">140 </span> <span class="Normal">uint32_t</span> new_size = <a href='010---vm.cc.html#L116'>align_upwards</a><span class="Delimiter">(</span>result_size<span class="Delimiter">,</span> align<span class="Delimiter">);</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment">// grow at least 2x to maintain some amortized complexity guarantees</span> +<span id="L142" class="LineNr">142 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_size < <a href='010---vm.cc.html#L125'>_data</a><span class="Delimiter">.</span>size<span class="Delimiter">()</span> * <span class="Constant">2</span><span class="Delimiter">)</span> +<span id="L143" class="LineNr">143 </span> new_size = <a href='010---vm.cc.html#L125'>_data</a><span class="Delimiter">.</span>size<span class="Delimiter">()</span> * <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L144" class="LineNr">144 </span> <span class="Comment">// never grow past the stated limit</span> +<span id="L145" class="LineNr">145 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_size > end-start<span class="Delimiter">)</span> +<span id="L146" class="LineNr">146 </span> new_size = end-start<span class="Delimiter">;</span> +<span id="L147" class="LineNr">147 </span> <a href='010---vm.cc.html#L125'>_data</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span>new_size<span class="Delimiter">);</span> +<span id="L148" class="LineNr">148 </span> <span class="Delimiter">}</span> +<span id="L149" class="LineNr">149 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L125'>_data</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>result_index<span class="Delimiter">);</span> +<span id="L150" class="LineNr">150 </span> <span class="Delimiter">}</span> +<span id="L151" class="LineNr">151 </span> <span class="Normal">void</span> <a href='010---vm.cc.html#L151'>grow_until</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L152" class="LineNr">152 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>new_end_address < end<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment">// Ugly: vma knows about the global Memory list of vmas</span> +<span id="L154" class="LineNr">154 </span> <span class="Normal">void</span> <a href='010---vm.cc.html#L161'>sanity_check</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> start<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> end<span class="Delimiter">);</span> +<span id="L155" class="LineNr">155 </span> <a href='010---vm.cc.html#L161'>sanity_check</a><span class="Delimiter">(</span>start<span class="Delimiter">,</span> new_end_address<span class="Delimiter">);</span> +<span id="L156" class="LineNr">156 </span> end = new_end_address<span class="Delimiter">;</span> +<span id="L157" class="LineNr">157 </span> <span class="Delimiter">}</span> +<span id="L158" class="LineNr">158 </span> <span class="Comment">// End vma Methods</span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">};</span> +<span id="L160" class="LineNr">160 </span><span class="Delimiter">:(code)</span> +<span id="L161" class="LineNr">161 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L161'>sanity_check</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> start<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> end<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L162" class="LineNr">162 </span> <span class="Normal">bool</span> dup_found =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L163" class="LineNr">163 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L164" class="LineNr">164 </span> <span class="Normal">const</span> vma& curr = <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L165" class="LineNr">165 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start == start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L166" class="LineNr">166 </span> assert<span class="Delimiter">(</span>!dup_found<span class="Delimiter">);</span> +<span id="L167" class="LineNr">167 </span> dup_found =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L168" class="LineNr">168 </span> <span class="Delimiter">}</span> +<span id="L169" class="LineNr">169 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start > start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L170" class="LineNr">170 </span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start > end<span class="Delimiter">);</span> +<span id="L171" class="LineNr">171 </span> <span class="Delimiter">}</span> +<span id="L172" class="LineNr">172 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start < start<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L173" class="LineNr">173 </span> assert<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>end < start<span class="Delimiter">);</span> +<span id="L174" class="LineNr">174 </span> <span class="Delimiter">}</span> +<span id="L175" class="LineNr">175 </span> <span class="Delimiter">}</span> +<span id="L176" class="LineNr">176 </span><span class="Delimiter">}</span> +<span id="L177" class="LineNr">177 </span> +<span id="L178" class="LineNr">178 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L179" class="LineNr">179 </span><span class="Comment">// RAM is made of VMAs.</span> +<span id="L180" class="LineNr">180 </span>vector<vma> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">;</span> +<span id="L181" class="LineNr">181 </span><span class="Delimiter">:(code)</span> +<span id="L182" class="LineNr">182 </span><span class="Comment">// The first 3 VMAs are special. When loading ELF binaries in later layers,</span> +<span id="L183" class="LineNr">183 </span><span class="Comment">// we'll assume that the first VMA is for code, the second is for data</span> +<span id="L184" class="LineNr">184 </span><span class="Comment">// (including the heap), and the third for the stack.</span> +<span id="L185" class="LineNr">185 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L185'>grow_code_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L186" class="LineNr">186 </span> assert<span class="Delimiter">(</span>!<span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>empty<span class="Delimiter">());</span> +<span id="L187" class="LineNr">187 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span><a href='010---vm.cc.html#L151'>grow_until</a><span class="Delimiter">(</span>new_end_address<span class="Delimiter">);</span> +<span id="L188" class="LineNr">188 </span><span class="Delimiter">}</span> +<span id="L189" class="LineNr">189 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L189'>grow_data_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> new_end_address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L190" class="LineNr">190 </span> assert<span class="Delimiter">(</span><a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">)</span> > <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span><a href='010---vm.cc.html#L151'>grow_until</a><span class="Delimiter">(</span>new_end_address<span class="Delimiter">);</span> +<span id="L192" class="LineNr">192 </span><span class="Delimiter">}</span> +<span id="L193" class="LineNr">193 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L194" class="LineNr">194 </span><span class="Normal">uint32_t</span> <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> = <span class="Constant">0</span><span class="Delimiter">;</span> <span class="Comment">// when the program executes past this address in tests we'll stop the test</span> +<span id="L195" class="LineNr">195 </span><span class="Comment">// The stack grows downward. Can't increase its size for now.</span> +<span id="L196" class="LineNr">196 </span><span class="Delimiter">:(before "End Reset")</span> +<span id="L197" class="LineNr">197 </span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span id="L198" class="LineNr">198 </span><span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L199" class="LineNr">199 </span><span class="Delimiter">:(code)</span> +<span id="L200" class="LineNr">200 </span><span class="Comment">// These helpers depend on Mem being laid out contiguously (so you can't use a</span> +<span id="L201" class="LineNr">201 </span><span class="Comment">// map, etc.) and on the host also being little-endian.</span> +<span id="L202" class="LineNr">202 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L202'>read_mem_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L203" class="LineNr">203 </span> <span class="Normal">uint8_t</span>* handle = <a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> <span class="Comment">// error messages get printed here</span> +<span id="L204" class="LineNr">204 </span> <span class="Identifier">return</span> handle ? *handle : <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">}</span> +<span id="L206" class="LineNr">206 </span><span class="Normal">inline</span> <span class="Normal">int8_t</span> <a href='010---vm.cc.html#L206'>read_mem_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L207" class="LineNr">207 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int8_t</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L202'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L208" class="LineNr">208 </span><span class="Delimiter">}</span> +<span id="L209" class="LineNr">209 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L210" class="LineNr">210 </span> <span class="Normal">uint32_t</span>* handle = <a href='010---vm.cc.html#L233'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> <span class="Comment">// error messages get printed here</span> +<span id="L211" class="LineNr">211 </span> <span class="Identifier">return</span> handle ? *handle : <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L212" class="LineNr">212 </span><span class="Delimiter">}</span> +<span id="L213" class="LineNr">213 </span><span class="Normal">inline</span> <span class="Normal">int32_t</span> <a href='010---vm.cc.html#L213'>read_mem_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L214" class="LineNr">214 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L215" class="LineNr">215 </span><span class="Delimiter">}</span> +<span id="L216" class="LineNr">216 </span> +<span id="L217" class="LineNr">217 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span>* <a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L218" class="LineNr">218 </span> <span class="Normal">uint8_t</span>* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L219" class="LineNr">219 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L220" class="LineNr">220 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010---vm.cc.html#L128'>match</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L221" class="LineNr">221 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> +<span id="L222" class="LineNr">222 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" is in two segments\n"</span> << end<span class="Delimiter">();</span> +<span id="L223" class="LineNr">223 </span> result = &<span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L224" class="LineNr">224 </span> <span class="Delimiter">}</span> +<span id="L225" class="LineNr">225 </span> <span class="Delimiter">}</span> +<span id="L226" class="LineNr">226 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> +<span id="L227" class="LineNr">227 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Tried to access uninitialized memory at address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L228" class="LineNr">228 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L229" class="LineNr">229 </span><span class="Delimiter">}</span> +<span id="L230" class="LineNr">230 </span><span class="Normal">inline</span> <span class="Normal">int8_t</span>* <a href='010---vm.cc.html#L230'>mem_addr_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L231" class="LineNr">231 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">int8_t</span>*><span class="Delimiter">(</span><a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L232" class="LineNr">232 </span><span class="Delimiter">}</span> +<span id="L233" class="LineNr">233 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span>* <a href='010---vm.cc.html#L233'>mem_addr_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L234" class="LineNr">234 </span> <span class="Normal">uint32_t</span>* result = <span class="Constant">NULL</span><span class="Delimiter">;</span> +<span id="L235" class="LineNr">235 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L236" class="LineNr">236 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010---vm.cc.html#L131'>match32</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L237" class="LineNr">237 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> +<span id="L238" class="LineNr">238 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" is in two segments\n"</span> << end<span class="Delimiter">();</span> +<span id="L239" class="LineNr">239 </span> result = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint32_t</span>*><span class="Delimiter">(</span>&<span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L240" class="LineNr">240 </span> <span class="Delimiter">}</span> +<span id="L241" class="LineNr">241 </span> <span class="Delimiter">}</span> +<span id="L242" class="LineNr">242 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result == <span class="Constant">NULL</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Tried to access uninitialized memory at address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L244" class="LineNr">244 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"The entire 4-byte <a href='011run.cc.html#L123'>word</a> should be initialized and lie in a single segment.\n"</span> << end<span class="Delimiter">();</span> +<span id="L245" class="LineNr">245 </span> <span class="Delimiter">}</span> +<span id="L246" class="LineNr">246 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L247" class="LineNr">247 </span><span class="Delimiter">}</span> +<span id="L248" class="LineNr">248 </span><span class="Normal">inline</span> <span class="Normal">int32_t</span>* <a href='010---vm.cc.html#L248'>mem_addr_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L249" class="LineNr">249 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">int32_t</span>*><span class="Delimiter">(</span><a href='010---vm.cc.html#L233'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L250" class="LineNr">250 </span><span class="Delimiter">}</span> +<span id="L251" class="LineNr">251 </span><span class="Comment">// helper for some syscalls. But read-only.</span> +<span id="L252" class="LineNr">252 </span><span class="Normal">inline</span> <span class="Normal">const</span> <span class="Normal">char</span>* <a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L253" class="LineNr">253 </span> <span class="Identifier">return</span> <span class="Normal">reinterpret_cast</span><<span class="Normal">const</span> <span class="Normal">char</span>*><span class="Delimiter">(</span><a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">));</span> +<span id="L254" class="LineNr">254 </span><span class="Delimiter">}</span> +<span id="L255" class="LineNr">255 </span><span class="Normal">inline</span> string <a href='010---vm.cc.html#L255'>mem_addr_string</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> size<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L256" class="LineNr">256 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L257" class="LineNr">257 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < size<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> +<span id="L258" class="LineNr">258 </span> out << <a href='010---vm.cc.html#L202'>read_mem_u8</a><span class="Delimiter">(</span>addr+i<span class="Delimiter">);</span> +<span id="L259" class="LineNr">259 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L260" class="LineNr">260 </span><span class="Delimiter">}</span> +<span id="L261" class="LineNr">261 </span> +<span id="L262" class="LineNr">262 </span> +<span id="L263" class="LineNr">263 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L263'>write_mem_u8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L264" class="LineNr">264 </span> <span class="Normal">uint8_t</span>* handle = <a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L265" class="LineNr">265 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L266" class="LineNr">266 </span><span class="Delimiter">}</span> +<span id="L267" class="LineNr">267 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L267'>write_mem_i8</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">int8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L268" class="LineNr">268 </span> <span class="Normal">int8_t</span>* handle = <a href='010---vm.cc.html#L230'>mem_addr_i8</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L269" class="LineNr">269 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L270" class="LineNr">270 </span><span class="Delimiter">}</span> +<span id="L271" class="LineNr">271 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L271'>write_mem_u32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L272" class="LineNr">272 </span> <span class="Normal">uint32_t</span>* handle = <a href='010---vm.cc.html#L233'>mem_addr_u32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L273" class="LineNr">273 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L274" class="LineNr">274 </span><span class="Delimiter">}</span> +<span id="L275" class="LineNr">275 </span><span class="Normal">inline</span> <span class="Normal">void</span> <a href='010---vm.cc.html#L275'>write_mem_i32</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">,</span> <span class="Normal">int32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L276" class="LineNr">276 </span> <span class="Normal">int32_t</span>* handle = <a href='010---vm.cc.html#L248'>mem_addr_i32</a><span class="Delimiter">(</span>addr<span class="Delimiter">);</span> +<span id="L277" class="LineNr">277 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>handle != <span class="Constant">NULL</span><span class="Delimiter">)</span> *handle = val<span class="Delimiter">;</span> +<span id="L278" class="LineNr">278 </span><span class="Delimiter">}</span> +<span id="L279" class="LineNr">279 </span> +<span id="L280" class="LineNr">280 </span><span class="Normal">inline</span> <span class="Normal">bool</span> <a href='010---vm.cc.html#L280'>already_allocated</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> addr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L281" class="LineNr">281 </span> <span class="Normal">bool</span> result =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L282" class="LineNr">282 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L283" class="LineNr">283 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span><a href='010---vm.cc.html#L128'>match</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L284" class="LineNr">284 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> +<span id="L285" class="LineNr">285 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" is in two segments\n"</span> << end<span class="Delimiter">();</span> +<span id="L286" class="LineNr">286 </span> result =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L287" class="LineNr">287 </span> <span class="Delimiter">}</span> +<span id="L288" class="LineNr">288 </span> <span class="Delimiter">}</span> +<span id="L289" class="LineNr">289 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L290" class="LineNr">290 </span><span class="Delimiter">}</span> +<span id="L291" class="LineNr">291 </span> +<span id="L292" class="LineNr">292 </span><span class="SalientComment">//:: core interpreter loop</span> +<span id="L293" class="LineNr">293 </span> +<span id="L294" class="LineNr">294 </span><span class="Delimiter">:(code)</span> +<span id="L295" class="LineNr">295 </span><span class="Comment">// skeleton of how x86 instructions are decoded</span> +<span id="L296" class="LineNr">296 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L296'>run_one_instruction</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L297" class="LineNr">297 </span> <span class="Normal">uint8_t</span> op=<span class="Constant">0</span><span class="Delimiter">,</span> op2=<span class="Constant">0</span><span class="Delimiter">,</span> op3=<span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L298" class="LineNr">298 </span> <span class="Comment">// Run One Instruction</span> +<span id="L299" class="LineNr">299 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"inst: 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L300" class="LineNr">300 </span> op = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> +<span id="L301" class="LineNr">301 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L188'>Dump_trace</a></span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L302" class="LineNr">302 </span> cerr << <span class="Constant">"opcode: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L303" class="LineNr">303 </span> cerr << <span class="Constant">"registers at start: "</span><span class="Delimiter">;</span> +<span id="L304" class="LineNr">304 </span> <a href='010---vm.cc.html#L368'>dump_registers</a><span class="Delimiter">();</span> +<span id="L305" class="LineNr">305 </span><span class="CommentedCode">//? dump_stack(); // for debugging; not defined until later layer</span> +<span id="L306" class="LineNr">306 </span> <span class="Delimiter">}</span> +<span id="L307" class="LineNr">307 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L308" class="LineNr">308 </span> <span class="Normal">case</span> <span class="Constant">0xf4</span>: <span class="Comment">// hlt</span> +<span id="L309" class="LineNr">309 </span> <a href='010---vm.cc.html#L29'>EIP</a> = <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span><span class="Delimiter">;</span> +<span id="L310" class="LineNr">310 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L311" class="LineNr">311 </span> <span class="Comment">// End Single-Byte Opcodes</span> +<span id="L312" class="LineNr">312 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: +<span id="L313" class="LineNr">313 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L314" class="LineNr">314 </span> <span class="Comment">// End Two-Byte Opcodes Starting With 0f</span> +<span id="L315" class="LineNr">315 </span> <span class="Normal">default</span>: +<span id="L316" class="LineNr">316 </span> cerr << <span class="Constant">"unrecognized second opcode after 0f: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L317" class="LineNr">317 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L318" class="LineNr">318 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L319" class="LineNr">319 </span> <span class="Delimiter">}</span> +<span id="L320" class="LineNr">320 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L321" class="LineNr">321 </span> <span class="Normal">case</span> <span class="Constant">0xf2</span>: +<span id="L322" class="LineNr">322 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L323" class="LineNr">323 </span> <span class="Comment">// End Two-Byte Opcodes Starting With f2</span> +<span id="L324" class="LineNr">324 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: +<span id="L325" class="LineNr">325 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op3 = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L326" class="LineNr">326 </span> <span class="Comment">// End Three-Byte Opcodes Starting With f2 0f</span> +<span id="L327" class="LineNr">327 </span> <span class="Normal">default</span>: +<span id="L328" class="LineNr">328 </span> cerr << <span class="Constant">"unrecognized third opcode after f2 0f: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op3<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L329" class="LineNr">329 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L331" class="LineNr">331 </span> <span class="Delimiter">}</span> +<span id="L332" class="LineNr">332 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L333" class="LineNr">333 </span> <span class="Normal">default</span>: +<span id="L334" class="LineNr">334 </span> cerr << <span class="Constant">"unrecognized second opcode after f2: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L335" class="LineNr">335 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L336" class="LineNr">336 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L337" class="LineNr">337 </span> <span class="Delimiter">}</span> +<span id="L338" class="LineNr">338 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L339" class="LineNr">339 </span> <span class="Normal">case</span> <span class="Constant">0xf3</span>: +<span id="L340" class="LineNr">340 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op2 = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L341" class="LineNr">341 </span> <span class="Comment">// End Two-Byte Opcodes Starting With f3</span> +<span id="L342" class="LineNr">342 </span> <span class="Normal">case</span> <span class="Constant">0x0f</span>: +<span id="L343" class="LineNr">343 </span> <span class="Normal">switch</span><span class="Delimiter">(</span>op3 = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">())</span> <span class="Delimiter">{</span> +<span id="L344" class="LineNr">344 </span> <span class="Comment">// End Three-Byte Opcodes Starting With f3 0f</span> +<span id="L345" class="LineNr">345 </span> <span class="Normal">default</span>: +<span id="L346" class="LineNr">346 </span> cerr << <span class="Constant">"unrecognized third opcode after f3 0f: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op3<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L347" class="LineNr">347 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L348" class="LineNr">348 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L349" class="LineNr">349 </span> <span class="Delimiter">}</span> +<span id="L350" class="LineNr">350 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L351" class="LineNr">351 </span> <span class="Normal">default</span>: +<span id="L352" class="LineNr">352 </span> cerr << <span class="Constant">"unrecognized second opcode after f3: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op2<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L353" class="LineNr">353 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L354" class="LineNr">354 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L355" class="LineNr">355 </span> <span class="Delimiter">}</span> +<span id="L356" class="LineNr">356 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L357" class="LineNr">357 </span> <span class="Normal">default</span>: +<span id="L358" class="LineNr">358 </span> cerr << <span class="Constant">"unrecognized opcode: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L359" class="LineNr">359 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L360" class="LineNr">360 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L361" class="LineNr">361 </span> <span class="Delimiter">}</span> +<span id="L362" class="LineNr">362 </span><span class="Delimiter">}</span> +<span id="L363" class="LineNr">363 </span> +<span id="L364" class="LineNr">364 </span><span class="Normal">inline</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L365" class="LineNr">365 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L202'>read_mem_u8</a><span class="Delimiter">(</span>EIP++<span class="Delimiter">);</span> +<span id="L366" class="LineNr">366 </span><span class="Delimiter">}</span> +<span id="L367" class="LineNr">367 </span> +<span id="L368" class="LineNr">368 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L368'>dump_registers</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L369" class="LineNr">369 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='010---vm.cc.html#L21'>NUM_INT_REGISTERS</a><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L370" class="LineNr">370 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> cerr << <span class="Constant">"; "</span><span class="Delimiter">;</span> +<span id="L371" class="LineNr">371 </span> cerr << <span class="Constant">" "</span> << i << <span class="Constant">": "</span> << std::hex << std::setw<span class="Delimiter">(</span><span class="Constant">8</span><span class="Delimiter">)</span> << std::setfill<span class="Delimiter">(</span><span class="Constant">'_'</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[i]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L372" class="LineNr">372 </span> <span class="Delimiter">}</span> +<span id="L373" class="LineNr">373 </span> cerr << <span class="Constant">" -- SF: "</span> << SF << <span class="Constant">"; ZF: "</span> << ZF << <span class="Constant">"; <a href='010---vm.cc.html#L81'>OF</a>: "</span> << <a href='010---vm.cc.html#L81'>OF</a> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L374" class="LineNr">374 </span><span class="Delimiter">}</span> +<span id="L375" class="LineNr">375 </span> +<span id="L376" class="LineNr">376 </span><span class="Comment">//: start tracking supported opcodes</span> +<span id="L377" class="LineNr">377 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L378" class="LineNr">378 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">;</span> +<span id="L379" class="LineNr">379 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">;</span> +<span id="L380" class="LineNr">380 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <span class="Special"><a href='010---vm.cc.html#L380'>Name_f3</a></span><span class="Delimiter">;</span> +<span id="L381" class="LineNr">381 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> string> <span class="Special"><a href='010---vm.cc.html#L381'>Name_f3_0f</a></span><span class="Delimiter">;</span> +<span id="L382" class="LineNr">382 </span><span class="Delimiter">:(before "End One-time Setup")</span> +<span id="L383" class="LineNr">383 </span><a href='010---vm.cc.html#L385'>init_op_names</a><span class="Delimiter">();</span> +<span id="L384" class="LineNr">384 </span><span class="Delimiter">:(code)</span> +<span id="L385" class="LineNr">385 </span><span class="Normal">void</span> <a href='010---vm.cc.html#L385'>init_op_names</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L386" class="LineNr">386 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"f4"</span><span class="Delimiter">,</span> <span class="Constant">"halt (hlt)"</span><span class="Delimiter">);</span> +<span id="L387" class="LineNr">387 </span> <span class="Comment">// End Initialize Op Names</span> +<span id="L388" class="LineNr">388 </span><span class="Delimiter">}</span> +<span id="L389" class="LineNr">389 </span> +<span id="L390" class="LineNr">390 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Special-cases(key)")</span> +<span id="L391" class="LineNr">391 </span><span class="Normal">if</span> <span class="Delimiter">(</span>key == <span class="Constant">"opcodes"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L392" class="LineNr">392 </span> cerr << <span class="Constant">"Opcodes currently supported by SubX:\n"</span><span class="Delimiter">;</span> +<span id="L393" class="LineNr">393 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L394" class="LineNr">394 </span> cerr << <span class="Constant">" "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L395" class="LineNr">395 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L396" class="LineNr">396 </span> cerr << <span class="Constant">" 0f "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L397" class="LineNr">397 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <span class="Special"><a href='010---vm.cc.html#L380'>Name_f3</a></span><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='010---vm.cc.html#L380'>Name_f3</a></span><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L398" class="LineNr">398 </span> cerr << <span class="Constant">" f3 "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L399" class="LineNr">399 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> string>::iterator p = <span class="Special"><a href='010---vm.cc.html#L381'>Name_f3_0f</a></span><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='010---vm.cc.html#L381'>Name_f3_0f</a></span><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> +<span id="L400" class="LineNr">400 </span> cerr << <span class="Constant">" f3 0f "</span> << p<span class="Delimiter">-></span>first << <span class="Constant">": "</span> << p<span class="Delimiter">-></span>second << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L401" class="LineNr">401 </span> cerr << <span class="Constant">"Run `subx help instructions` for details on <a href='011run.cc.html#L118'>words</a> like 'r32' and 'disp8'.\n"</span> +<span id="L402" class="LineNr">402 </span> <span class="Constant">"For complete details on these instructions, consult the IA-32 manual (volume 2).\n"</span> +<span id="L403" class="LineNr">403 </span> <span class="Constant">"There's various versions of it online, such as <a href="https://c9x.me/x86">https://c9x.me/x86</a>.\n"</span> +<span id="L404" class="LineNr">404 </span> <span class="Constant">"The mnemonics in brackets will help you locate each instruction.\n"</span><span class="Delimiter">;</span> +<span id="L405" class="LineNr">405 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L406" class="LineNr">406 </span><span class="Delimiter">}</span> +<span id="L407" class="LineNr">407 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> +<span id="L408" class="LineNr">408 </span>cerr << <span class="Constant">" opcodes\n"</span><span class="Delimiter">;</span> +<span id="L409" class="LineNr">409 </span> +<span id="L410" class="LineNr">410 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L411" class="LineNr">411 </span><span class="Comment">#include <iomanip></span> +<span id="L412" class="LineNr">412 </span><span class="Comment">#define HEXBYTE std::hex << std::setw(2) << std::setfill('0')</span> +<span id="L413" class="LineNr">413 </span><span class="Comment">#define HEXWORD std::hex << std::setw(8) << std::setfill('0')</span> +<span id="L414" class="LineNr">414 </span><span class="Comment">// ugly that iostream doesn't print uint8_t as an integer</span> +<span id="L415" class="LineNr">415 </span><span class="Comment">#define NUM(X) static_cast<int>(X)</span> +<span id="L416" class="LineNr">416 </span><span class="Comment">#include <stdint.h></span> </pre> </body> </html> diff --git a/html/subx/011run.cc.html b/html/subx/011run.cc.html index f1137805..c06a3b32 100644 --- a/html/subx/011run.cc.html +++ b/html/subx/011run.cc.html @@ -15,18 +15,18 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } +.cSpecial { color: #008000; } .traceContains { color: #008000; } -.PreProc { color: #800080; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } -.Special { color: #c00000; } -.Delimiter { color: #800080; } .SalientComment { color: #00ffff; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.cSpecial { color: #008000; } +.PreProc { color: #800080; } --> </style> @@ -67,39 +67,39 @@ if ('onhashchange' in window) { <span id="L4" class="LineNr"> 4 </span><span class="Comment">//: the VM. That comes later.)</span> <span id="L5" class="LineNr"> 5 </span> <span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> -<span id="L7" class="LineNr"> 7 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"syntax"</span><span class="Delimiter">,</span> -<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"SubX programs consist of <a href='011run.cc.html#L100'>segments</a>, each segment in turn consisting of lines.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L9" class="LineNr"> 9 </span> <span class="Constant">"Line-endings are significant; each <a href='011run.cc.html#L117'>line</a> should contain a single</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"instruction, macro or directive.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"Comments start with the '#' character. It should be at the start of a <a href='011run.cc.html#L123'>word</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"(start of <a href='011run.cc.html#L117'>line</a>, or following a space).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"Each segment starts with a header <a href='011run.cc.html#L117'>line</a>: a '==' delimiter followed by the name of</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"the segment.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"Currently SubX assumes the first segment encountered contains executable <a href='031check_operands.cc.html#L11'>code</a>, and</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"the second contains global variables. By convention we call them 'code' and 'data'</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"respectively.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"The first instruction executed in the resulting binary is always the first</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"instruction of the first segment.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"Segments with the same name get merged together. This rule helps keep functions and</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"their data close together in .subx files.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L26" class="LineNr"> 26 </span> <span class="Constant">"Later <a href='011run.cc.html#L100'>segments</a> with the same name get their <a href='003trace.cc.html#L74'>contents</a> *prepended* to earlier ones.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L27" class="LineNr"> 27 </span> <span class="Constant">"This rule helps each .subx file to <a href='001help.cc.html#L243'>put</a> forth a different entrypoint for the binary,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L28" class="LineNr"> 28 </span> <span class="Constant">"overriding previously loaded files.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L29" class="LineNr"> 29 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"Lines consist of a series of words. Words can contain arbitrary metadata</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L31" class="LineNr"> 31 </span> <span class="Constant">"after a '/', but they can never contain whitespace. Metadata has no effect</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L32" class="LineNr"> 32 </span> <span class="Constant">"at runtime, but can be handy when rewriting macros.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L33" class="LineNr"> 33 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L34" class="LineNr"> 34 </span> <span class="Constant">"Check out the examples in the examples/ directory.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L35" class="LineNr"> 35 </span> <span class="Constant">"Programming in machine <a href='031check_operands.cc.html#L11'>code</a> can be annoying, but let's see if we can make</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L36" class="LineNr"> 36 </span> <span class="Constant">"it nice enough to be able to write a compiler in it.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L7" class="LineNr"> 7 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"syntax"</span><span class="Delimiter">,</span> +<span id="L8" class="LineNr"> 8 </span> <span class="Constant">"SubX programs consist of <a href='011run.cc.html#L100'>segments</a>, each segment in turn consisting of lines.\n"</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Constant">"Line-endings are significant; each <a href='011run.cc.html#L117'>line</a> should contain a single\n"</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Constant">"instruction, macro or directive.\n"</span> +<span id="L11" class="LineNr"> 11 </span> <span class="Constant">"\n"</span> +<span id="L12" class="LineNr"> 12 </span> <span class="Constant">"Comments start with the '#' character. It should be at the start of a word\n"</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Constant">"(start of <a href='011run.cc.html#L117'>line</a>, or following a space).\n"</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Constant">"\n"</span> +<span id="L15" class="LineNr"> 15 </span> <span class="Constant">"Each segment starts with a header <a href='011run.cc.html#L117'>line</a>: a '==' delimiter followed by the name of\n"</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Constant">"the segment.\n"</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"\n"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"Currently SubX assumes the first segment encountered contains executable <a href='031check_operands.cc.html#L11'>code</a>, and\n"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"the second contains global variables. By convention we call them 'code' and 'data'\n"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"respectively.\n"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"The first instruction executed in the resulting binary is always the first\n"</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"instruction of the first segment.\n"</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"\n"</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"Segments with the same name get merged together. This rule helps keep functions and\n"</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"their data close together in .subx files.\n"</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Constant">"Later <a href='011run.cc.html#L100'>segments</a> with the same name get their <a href='003trace.cc.html#L74'>contents</a> *prepended* to earlier ones.\n"</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Constant">"This rule helps each .subx file to <a href='001help.cc.html#L243'>put</a> forth a different entrypoint for the binary,\n"</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Constant">"overriding previously loaded files.\n"</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Constant">"\n"</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Constant">"Lines consist of a series of words. Words can contain arbitrary metadata\n"</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Constant">"after a '/', but they can never contain whitespace. Metadata has no effect\n"</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Constant">"at runtime, but can be handy when rewriting macros.\n"</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Constant">"\n"</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Constant">"Check out the examples in the examples/ directory.\n"</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Constant">"Programming in machine <a href='031check_operands.cc.html#L11'>code</a> can be annoying, but let's see if we can make\n"</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Constant">"it nice enough to be able to write a compiler in it.\n"</span> <span id="L37" class="LineNr"> 37 </span><span class="Delimiter">);</span> <span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> -<span id="L39" class="LineNr"> 39 </span>cerr << <span class="Constant">" syntax</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L39" class="LineNr"> 39 </span>cerr << <span class="Constant">" syntax\n"</span><span class="Delimiter">;</span> <span id="L40" class="LineNr"> 40 </span> <span id="L41" class="LineNr"> 41 </span><span class="Delimiter">:(scenario add_imm32_to_eax)</span> <span id="L42" class="LineNr"> 42 </span><span class="Comment"># At the lowest level, SubX programs are a series of hex bytes, each</span> @@ -152,8 +152,8 @@ if ('onhashchange' in window) { <span id="L89" class="LineNr"> 89 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L90" class="LineNr"> 90 </span> <a href='011run.cc.html#L240'>load</a><span class="Delimiter">(</span>p<span class="Delimiter">);</span> <span id="L91" class="LineNr"> 91 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a> < <a href='010---vm.cc.html#L185'>End_of_program</a><span class="Delimiter">)</span> -<span id="L93" class="LineNr"> 93 </span> <a href='010---vm.cc.html#L287'>run_one_instruction</a><span class="Delimiter">();</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a> < <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span><span class="Delimiter">)</span> +<span id="L93" class="LineNr"> 93 </span> <a href='010---vm.cc.html#L296'>run_one_instruction</a><span class="Delimiter">();</span> <span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> <span id="L95" class="LineNr"> 95 </span> <span id="L96" class="LineNr"> 96 </span><span class="SalientComment">//:: core data structures</span> @@ -218,7 +218,7 @@ if ('onhashchange' in window) { <span id="L155" class="LineNr">155 </span> s<span class="Delimiter">.</span>start = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>segment_title<span class="Delimiter">);</span> <span id="L156" class="LineNr">156 </span> <a href='011run.cc.html#L201'>sanity_check_program_segment</a><span class="Delimiter">(</span>out<span class="Delimiter">,</span> s<span class="Delimiter">.</span>start<span class="Delimiter">);</span> <span id="L157" class="LineNr">157 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span id="L158" class="LineNr">158 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"new segment from 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << s<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> +<span id="L158" class="LineNr">158 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"new segment from 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << s<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> <span id="L159" class="LineNr">159 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>s<span class="Delimiter">);</span> <span id="L160" class="LineNr">160 </span> <span class="Delimiter">}</span> <span id="L161" class="LineNr">161 </span> <span class="Comment">// End Segment Parsing Special-cases(segment_title)</span> @@ -243,7 +243,7 @@ if ('onhashchange' in window) { <span id="L180" class="LineNr">180 </span><span class="Normal">void</span> <a href='011run.cc.html#L180'>flush</a><span class="Delimiter">(</span>program& p<span class="Delimiter">,</span> vector<line>& <a href='011run.cc.html#L109'>lines</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L181" class="LineNr">181 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L182" class="LineNr">182 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L183" class="LineNr">183 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"input does not start with a '==' section header</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L183" class="LineNr">183 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"input does not start with a '==' section header\n"</span> << end<span class="Delimiter">();</span> <span id="L184" class="LineNr">184 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L185" class="LineNr">185 </span> <span class="Delimiter">}</span> <span id="L186" class="LineNr">186 </span> <span class="Comment">// End flush(p, lines) Special-cases</span> @@ -289,12 +289,12 @@ if ('onhashchange' in window) { <span id="L226" class="LineNr">226 </span><span class="Delimiter">:(before "End Types")</span> <span id="L227" class="LineNr">227 </span><span class="Normal">typedef</span> <span class="Normal">void</span> <span class="Delimiter">(</span>*transform_fn<span class="Delimiter">)(</span>program&<span class="Delimiter">);</span> <span id="L228" class="LineNr">228 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L229" class="LineNr">229 </span>vector<transform_fn> <a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">;</span> +<span id="L229" class="LineNr">229 </span>vector<transform_fn> <span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">;</span> <span id="L230" class="LineNr">230 </span> <span id="L231" class="LineNr">231 </span><span class="Normal">void</span> <a href='011run.cc.html#L231'>transform</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L232" class="LineNr">232 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"begin"</span> << end<span class="Delimiter">();</span> -<span id="L233" class="LineNr">233 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> -<span id="L234" class="LineNr">234 </span> <span class="Delimiter">(</span>*Transform<span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>p<span class="Delimiter">);</span> +<span id="L233" class="LineNr">233 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> t = <span class="Constant">0</span><span class="Delimiter">;</span> t < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">);</span> ++t<span class="Delimiter">)</span> +<span id="L234" class="LineNr">234 </span> <span class="Delimiter">(</span>*<span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>t<span class="Delimiter">))(</span>p<span class="Delimiter">);</span> <span id="L235" class="LineNr">235 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"done"</span> << end<span class="Delimiter">();</span> <span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> <span id="L237" class="LineNr">237 </span> @@ -303,7 +303,7 @@ if ('onhashchange' in window) { <span id="L240" class="LineNr">240 </span><span class="Normal">void</span> <a href='011run.cc.html#L240'>load</a><span class="Delimiter">(</span><span class="Normal">const</span> program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L241" class="LineNr">241 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"begin"</span> << end<span class="Delimiter">();</span> <span id="L242" class="LineNr">242 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"no <a href='031check_operands.cc.html#L11'>code</a> to <a href='011run.cc.html#L83'>run</a></span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"no <a href='031check_operands.cc.html#L11'>code</a> to run\n"</span> << end<span class="Delimiter">();</span> <span id="L244" class="LineNr">244 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L245" class="LineNr">245 </span> <span class="Delimiter">}</span> <span id="L246" class="LineNr">246 </span> <span class="Comment">// Ensure segments are disjoint.</span> @@ -312,8 +312,8 @@ if ('onhashchange' in window) { <span id="L249" class="LineNr">249 </span> <span class="Normal">const</span> segment& seg = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span id="L250" class="LineNr">250 </span> <span class="Normal">uint32_t</span> addr = seg<span class="Delimiter">.</span>start<span class="Delimiter">;</span> <span id="L251" class="LineNr">251 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!already_allocated<span class="Delimiter">(</span>addr<span class="Delimiter">))</span> -<span id="L252" class="LineNr">252 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>seg<span class="Delimiter">.</span>start<span class="Delimiter">));</span> -<span id="L253" class="LineNr">253 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"loading segment "</span> << i << <span class="Constant">" from "</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> +<span id="L252" class="LineNr">252 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>seg<span class="Delimiter">.</span>start<span class="Delimiter">));</span> +<span id="L253" class="LineNr">253 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"loading segment "</span> << i << <span class="Constant">" from "</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> <span id="L254" class="LineNr">254 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>seg<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L255" class="LineNr">255 </span> <span class="Normal">const</span> line& l = seg<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> <span id="L256" class="LineNr">256 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> k = <span class="Constant">0</span><span class="Delimiter">;</span> k < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++k<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -321,13 +321,13 @@ if ('onhashchange' in window) { <span id="L258" class="LineNr">258 </span> <span class="Normal">uint8_t</span> val = <a href='011run.cc.html#L273'>hex_byte</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">);</span> <span id="L259" class="LineNr">259 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L260" class="LineNr">260 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>addr<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L261" class="LineNr">261 </span> <a href='010---vm.cc.html#L254'>write_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">,</span> val<span class="Delimiter">);</span> +<span id="L261" class="LineNr">261 </span> <a href='010---vm.cc.html#L263'>write_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">,</span> val<span class="Delimiter">);</span> <span id="L262" class="LineNr">262 </span> overlap<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>addr<span class="Delimiter">);</span> -<span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" -> "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L193'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> +<span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" -> "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L202'>read_mem_u8</a><span class="Delimiter">(</span>addr<span class="Delimiter">))</span> << end<span class="Delimiter">();</span> <span id="L264" class="LineNr">264 </span> ++addr<span class="Delimiter">;</span> <span id="L265" class="LineNr">265 </span> <span class="Delimiter">}</span> <span id="L266" class="LineNr">266 </span> <span class="Delimiter">}</span> -<span id="L267" class="LineNr">267 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <span class="Constant">0</span><span class="Delimiter">)</span> <a href='010---vm.cc.html#L185'>End_of_program</a> = addr<span class="Delimiter">;</span> +<span id="L267" class="LineNr">267 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> = addr<span class="Delimiter">;</span> <span id="L268" class="LineNr">268 </span> <span class="Delimiter">}</span> <span id="L269" class="LineNr">269 </span> <a href='010---vm.cc.html#L29'>EIP</a> = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>start<span class="Delimiter">;</span> <span id="L270" class="LineNr">270 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"done"</span> << end<span class="Delimiter">();</span> @@ -338,11 +338,11 @@ if ('onhashchange' in window) { <span id="L275" class="LineNr">275 </span> <span class="Normal">int</span> result = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L276" class="LineNr">276 </span> in >> std::hex >> result<span class="Delimiter">;</span> <span id="L277" class="LineNr">277 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!in || !in<span class="Delimiter">.</span>eof<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L278" class="LineNr">278 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L278" class="LineNr">278 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte\n"</span> << end<span class="Delimiter">();</span> <span id="L279" class="LineNr">279 </span> <span class="Identifier">return</span> <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> <span id="L280" class="LineNr">280 </span> <span class="Delimiter">}</span> <span id="L281" class="LineNr">281 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result > <span class="Constant">0xff</span> || result < -<span class="Constant">0x8f</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L282" class="LineNr">282 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L282" class="LineNr">282 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"token '"</span> << s << <span class="Constant">"' is not a hex byte\n"</span> << end<span class="Delimiter">();</span> <span id="L283" class="LineNr">283 </span> <span class="Identifier">return</span> <span class="cSpecial">'\0'</span><span class="Delimiter">;</span> <span id="L284" class="LineNr">284 </span> <span class="Delimiter">}</span> <span id="L285" class="LineNr">285 </span> <span class="Identifier">return</span> <span class="Normal">static_cast</span><<span class="Normal">uint8_t</span>><span class="Delimiter">(</span>result<span class="Delimiter">);</span> @@ -390,24 +390,24 @@ if ('onhashchange' in window) { <span id="L327" class="LineNr">327 </span><span class="SalientComment">//:: run</span> <span id="L328" class="LineNr">328 </span> <span id="L329" class="LineNr">329 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L330" class="LineNr">330 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">"add imm32 to <a href='010---vm.cc.html#L13'>EAX</a> (add)"</span><span class="Delimiter">);</span> +<span id="L330" class="LineNr">330 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">"add imm32 to <a href='010---vm.cc.html#L13'>EAX</a> (add)"</span><span class="Delimiter">);</span> <span id="L331" class="LineNr">331 </span> <span id="L332" class="LineNr">332 </span><span class="Comment">//: our first opcode</span> <span id="L333" class="LineNr">333 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L334" class="LineNr">334 </span><span class="Normal">case</span> <span class="Constant">0x05</span>: <span class="Delimiter">{</span> <span class="Comment">// add imm32 to EAX</span> <span id="L335" class="LineNr">335 </span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L336" class="LineNr">336 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << <span class="Constant">" to <a href='010---vm.cc.html#L23'>reg</a> EAX"</span> << end<span class="Delimiter">();</span> -<span id="L337" class="LineNr">337 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> +<span id="L336" class="LineNr">336 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << <span class="Constant">" to <a href='010---vm.cc.html#L23'>reg</a> EAX"</span> << end<span class="Delimiter">();</span> +<span id="L337" class="LineNr">337 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> <span id="L338" class="LineNr">338 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L339" class="LineNr">339 </span><span class="Delimiter">}</span> <span id="L340" class="LineNr">340 </span> <span id="L341" class="LineNr">341 </span><span class="Delimiter">:(code)</span> <span id="L342" class="LineNr">342 </span><span class="Comment">// read a 32-bit int in little-endian order from the instruction stream</span> <span id="L343" class="LineNr">343 </span><span class="Normal">int32_t</span> <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L344" class="LineNr">344 </span> <span class="Normal">int32_t</span> result = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> -<span id="L345" class="LineNr">345 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">8</span><span class="Delimiter">);</span> -<span id="L346" class="LineNr">346 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">16</span><span class="Delimiter">);</span> -<span id="L347" class="LineNr">347 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">24</span><span class="Delimiter">);</span> +<span id="L344" class="LineNr">344 </span> <span class="Normal">int32_t</span> result = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> +<span id="L345" class="LineNr">345 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span><<<span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L346" class="LineNr">346 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span><<<span class="Constant">16</span><span class="Delimiter">);</span> +<span id="L347" class="LineNr">347 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">()</span><<<span class="Constant">24</span><span class="Delimiter">);</span> <span id="L348" class="LineNr">348 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span id="L349" class="LineNr">349 </span><span class="Delimiter">}</span> <span id="L350" class="LineNr">350 </span> diff --git a/html/subx/012elf.cc.html b/html/subx/012elf.cc.html index 565f3d44..06a6ed4c 100644 --- a/html/subx/012elf.cc.html +++ b/html/subx/012elf.cc.html @@ -18,6 +18,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -69,9 +70,9 @@ if ('onhashchange' in window) { <span id="L10" class="LineNr"> 10 </span> <a href='000organization.cc.html#L148'>reset</a><span class="Delimiter">();</span> <span id="L11" class="LineNr"> 11 </span> cerr << std::hex<span class="Delimiter">;</span> <span id="L12" class="LineNr"> 12 </span> <a href='012elf.cc.html#L20'>load_elf</a><span class="Delimiter">(</span>argv[<span class="Constant">2</span>]<span class="Delimiter">,</span> argc<span class="Delimiter">,</span> argv<span class="Delimiter">);</span> -<span id="L13" class="LineNr"> 13 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a> < <a href='010---vm.cc.html#L185'>End_of_program</a><span class="Delimiter">)</span> <span class="Comment">// weak final-gasp termination check</span> -<span id="L14" class="LineNr"> 14 </span> <a href='010---vm.cc.html#L287'>run_one_instruction</a><span class="Delimiter">();</span> -<span id="L15" class="LineNr"> 15 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"executed past end of the world: "</span> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">" vs "</span> << <a href='010---vm.cc.html#L185'>End_of_program</a> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L13" class="LineNr"> 13 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a> < <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span><span class="Delimiter">)</span> <span class="Comment">// weak final-gasp termination check</span> +<span id="L14" class="LineNr"> 14 </span> <a href='010---vm.cc.html#L296'>run_one_instruction</a><span class="Delimiter">();</span> +<span id="L15" class="LineNr"> 15 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"executed past end of the world: "</span> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">" vs "</span> << <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span id="L16" class="LineNr"> 16 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">}</span> <span id="L18" class="LineNr"> 18 </span> @@ -92,23 +93,23 @@ if ('onhashchange' in window) { <span id="L33" class="LineNr"> 33 </span><span class="Normal">void</span> <a href='012elf.cc.html#L33'>load_elf_contents</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* elf_contents<span class="Delimiter">,</span> <span class="Normal">size_t</span> size<span class="Delimiter">,</span> <span class="Normal">int</span> argc<span class="Delimiter">,</span> <span class="Normal">char</span>* argv[]<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L34" class="LineNr"> 34 </span> <span class="Normal">uint8_t</span> magic[<span class="Constant">5</span>] = <span class="Delimiter">{</span><span class="Constant">0</span><span class="Delimiter">};</span> <span id="L35" class="LineNr"> 35 </span> memcpy<span class="Delimiter">(</span>magic<span class="Delimiter">,</span> elf_contents<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> -<span id="L36" class="LineNr"> 36 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>memcmp<span class="Delimiter">(</span>magic<span class="Delimiter">,</span> <span class="Constant">"</span><span class="cSpecial">\177</span><span class="Constant">ELF"</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> -<span id="L37" class="LineNr"> 37 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid ELF file; starts with </span><span class="cSpecial">\"</span><span class="Constant">"</span> << magic << <span class="Constant">'"'</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>memcmp<span class="Delimiter">(</span>magic<span class="Delimiter">,</span> <span class="Constant">"\177ELF"</span><span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">)</span> != <span class="Constant">0</span><span class="Delimiter">)</span> +<span id="L37" class="LineNr"> 37 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid ELF file; starts with \"" << magic << '"</span>' << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> <span id="L38" class="LineNr"> 38 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>elf_contents[<span class="Constant">4</span>] != <span class="Constant">1</span><span class="Delimiter">)</span> -<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Only 32-bit ELF files (4-byte words; virtual addresses up to 4GB) supported.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> +<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Only 32-bit ELF files (4-byte words; virtual addresses up to 4GB) supported.\n"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> <span id="L40" class="LineNr"> 40 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>elf_contents[<span class="Constant">5</span>] != <span class="Constant">1</span><span class="Delimiter">)</span> -<span id="L41" class="LineNr"> 41 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Only little-endian ELF files supported.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> +<span id="L41" class="LineNr"> 41 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Only little-endian ELF files supported.\n"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> <span id="L42" class="LineNr"> 42 </span> <span class="Comment">// unused: remaining 10 bytes of e_ident</span> <span id="L43" class="LineNr"> 43 </span> <span class="Normal">uint32_t</span> e_machine_type = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">16</span>]<span class="Delimiter">);</span> <span id="L44" class="LineNr"> 44 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_machine_type != <span class="Constant">0x00030002</span><span class="Delimiter">)</span> -<span id="L45" class="LineNr"> 45 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"ELF type/machine 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << e_machine_type << <span class="Constant">" isn't i386 executable</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> +<span id="L45" class="LineNr"> 45 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"ELF type/machine 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << e_machine_type << <span class="Constant">" isn't i386 executable\n"</span> << die<span class="Delimiter">();</span> <span id="L46" class="LineNr"> 46 </span> <span class="Comment">// unused: e_version. We only support version 1, and later versions will be backwards compatible.</span> <span id="L47" class="LineNr"> 47 </span> <span class="Normal">uint32_t</span> e_entry = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">24</span>]<span class="Delimiter">);</span> <span id="L48" class="LineNr"> 48 </span> <span class="Normal">uint32_t</span> e_phoff = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">28</span>]<span class="Delimiter">);</span> <span id="L49" class="LineNr"> 49 </span> <span class="Comment">// unused: e_shoff</span> <span id="L50" class="LineNr"> 50 </span> <span class="Comment">// unused: e_flags</span> <span id="L51" class="LineNr"> 51 </span> <span class="Normal">uint32_t</span> e_ehsize = <a href='012elf.cc.html#L154'>u16_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">40</span>]<span class="Delimiter">);</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_ehsize < <span class="Constant">52</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid binary; ELF header too small</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_ehsize < <span class="Constant">52</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid binary; ELF header too small\n"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> <span id="L53" class="LineNr"> 53 </span> <span class="Normal">uint32_t</span> e_phentsize = <a href='012elf.cc.html#L154'>u16_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">42</span>]<span class="Delimiter">);</span> <span id="L54" class="LineNr"> 54 </span> <span class="Normal">uint32_t</span> e_phnum = <a href='012elf.cc.html#L154'>u16_in</a><span class="Delimiter">(</span>&elf_contents[<span class="Constant">44</span>]<span class="Delimiter">);</span> <span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << e_phnum << <span class="Constant">" entries in the <a href='011run.cc.html#L99'>program</a> header, each "</span> << e_phentsize << <span class="Constant">" bytes long"</span> << end<span class="Delimiter">();</span> @@ -122,34 +123,34 @@ if ('onhashchange' in window) { <span id="L63" class="LineNr"> 63 </span> <span id="L64" class="LineNr"> 64 </span> <span class="Comment">// initialize code and stack</span> <span id="L65" class="LineNr"> 65 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='012elf.cc.html#L137'>STACK_SEGMENT</a><span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L66" class="LineNr"> 66 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='012elf.cc.html#L137'>STACK_SEGMENT</a><span class="Delimiter">));</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='012elf.cc.html#L137'>STACK_SEGMENT</a><span class="Delimiter">));</span> <span id="L67" class="LineNr"> 67 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='012elf.cc.html#L138'>AFTER_STACK</a><span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L68" class="LineNr"> 68 </span> Reg[ESP]<span class="Delimiter">.</span>u = <a href='012elf.cc.html#L138'>AFTER_STACK</a><span class="Delimiter">;</span> -<span id="L69" class="LineNr"> 69 </span> Reg[EBP]<span class="Delimiter">.</span>u = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u = <a href='012elf.cc.html#L138'>AFTER_STACK</a><span class="Delimiter">;</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBP]<span class="Delimiter">.</span>u = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L70" class="LineNr"> 70 </span> <a href='010---vm.cc.html#L29'>EIP</a> = e_entry<span class="Delimiter">;</span> <span id="L71" class="LineNr"> 71 </span> <span id="L72" class="LineNr"> 72 </span> <span class="Comment">// initialize args on stack</span> <span id="L73" class="LineNr"> 73 </span> <span class="Comment">// no envp for now</span> <span id="L74" class="LineNr"> 74 </span> <span class="Comment">// we wastefully use a separate page of memory for argv</span> -<span id="L75" class="LineNr"> 75 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='012elf.cc.html#L139'>ARGV_DATA_SEGMENT</a><span class="Delimiter">));</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='012elf.cc.html#L139'>ARGV_DATA_SEGMENT</a><span class="Delimiter">));</span> <span id="L76" class="LineNr"> 76 </span> <span class="Normal">uint32_t</span> argv_data = <a href='012elf.cc.html#L139'>ARGV_DATA_SEGMENT</a><span class="Delimiter">;</span> <span id="L77" class="LineNr"> 77 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = argc-<span class="Constant">1</span><span class="Delimiter">;</span> i >= <span class="Comment">/*</span><span class="Comment">skip 'subx_bin' and 'run'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">;</span> --i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L78" class="LineNr"> 78 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span>argv_data<span class="Delimiter">);</span> <span id="L79" class="LineNr"> 79 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j <= strlen<span class="Delimiter">(</span>argv[i]<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L80" class="LineNr"> 80 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>argv_data<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span class="Comment">// don't bother comparing ARGV and STACK</span> -<span id="L81" class="LineNr"> 81 </span> <a href='010---vm.cc.html#L254'>write_mem_u8</a><span class="Delimiter">(</span>argv_data<span class="Delimiter">,</span> argv[i][j]<span class="Delimiter">);</span> +<span id="L81" class="LineNr"> 81 </span> <a href='010---vm.cc.html#L263'>write_mem_u8</a><span class="Delimiter">(</span>argv_data<span class="Delimiter">,</span> argv[i][j]<span class="Delimiter">);</span> <span id="L82" class="LineNr"> 82 </span> argv_data += <span class="Normal">sizeof</span><span class="Delimiter">(</span><span class="Normal">char</span><span class="Delimiter">);</span> -<span id="L83" class="LineNr"> 83 </span> assert<span class="Delimiter">(</span>argv_data < <a href='012elf.cc.html#L139'>ARGV_DATA_SEGMENT</a> + <a href='010---vm.cc.html#L115'>INITIAL_SEGMENT_SIZE</a><span class="Delimiter">);</span> +<span id="L83" class="LineNr"> 83 </span> assert<span class="Delimiter">(</span>argv_data < <a href='012elf.cc.html#L139'>ARGV_DATA_SEGMENT</a> + <a href='010---vm.cc.html#L115'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> <span id="L84" class="LineNr"> 84 </span> <span class="Delimiter">}</span> <span id="L85" class="LineNr"> 85 </span> <span class="Delimiter">}</span> <span id="L86" class="LineNr"> 86 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span>argc-<span class="Comment">/*</span><span class="Comment">skip 'subx_bin' and 'run'</span><span class="Comment">*/</span><span class="Constant">2</span><span class="Delimiter">);</span> <span id="L87" class="LineNr"> 87 </span><span class="Delimiter">}</span> <span id="L88" class="LineNr"> 88 </span> <span id="L89" class="LineNr"> 89 </span><span class="Normal">void</span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L90" class="LineNr"> 90 </span> Reg[ESP]<span class="Delimiter">.</span>u -= <span class="Constant">4</span><span class="Delimiter">;</span> -<span id="L91" class="LineNr"> 91 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrementing <a href='010---vm.cc.html#L17'>ESP</a> to 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L92" class="LineNr"> 92 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pushing value 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << val << end<span class="Delimiter">();</span> -<span id="L93" class="LineNr"> 93 </span> <a href='010---vm.cc.html#L262'>write_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> val<span class="Delimiter">);</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u -= <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L91" class="LineNr"> 91 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrementing <a href='010---vm.cc.html#L17'>ESP</a> to 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L92" class="LineNr"> 92 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pushing value 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << val << end<span class="Delimiter">();</span> +<span id="L93" class="LineNr"> 93 </span> <a href='010---vm.cc.html#L271'>write_mem_u32</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> val<span class="Delimiter">);</span> <span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> <span id="L95" class="LineNr"> 95 </span> <span id="L96" class="LineNr"> 96 </span><span class="Normal">void</span> <a href='012elf.cc.html#L96'>load_segment_from_program_header</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* elf_contents<span class="Delimiter">,</span> <span class="Normal">int</span> segment_index<span class="Delimiter">,</span> <span class="Normal">size_t</span> size<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> offset<span class="Delimiter">,</span> <span class="Normal">uint32_t</span> e_ehsize<span class="Delimiter">,</span> set<<span class="Normal">uint32_t</span>>& overlap<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -161,29 +162,29 @@ if ('onhashchange' in window) { <span id="L102" class="LineNr">102 </span> <span class="Delimiter">}</span> <span id="L103" class="LineNr">103 </span> <span class="Normal">uint32_t</span> p_offset = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">4</span>]<span class="Delimiter">);</span> <span id="L104" class="LineNr">104 </span> <span class="Normal">uint32_t</span> p_vaddr = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">8</span>]<span class="Delimiter">);</span> -<span id="L105" class="LineNr">105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_ehsize > p_vaddr<span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid binary; <a href='011run.cc.html#L99'>program</a> header overlaps ELF header</span><span class="cSpecial">\n</span><span class="Constant">"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> +<span id="L105" class="LineNr">105 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>e_ehsize > p_vaddr<span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid binary; <a href='011run.cc.html#L99'>program</a> header overlaps ELF header\n"</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> <span id="L106" class="LineNr">106 </span> <span class="Comment">// unused: p_paddr</span> <span id="L107" class="LineNr">107 </span> <span class="Normal">uint32_t</span> p_filesz = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">16</span>]<span class="Delimiter">);</span> <span id="L108" class="LineNr">108 </span> <span class="Normal">uint32_t</span> p_memsz = <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span>&elf_contents[offset + <span class="Constant">20</span>]<span class="Delimiter">);</span> <span id="L109" class="LineNr">109 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_filesz != p_memsz<span class="Delimiter">)</span> -<span id="L110" class="LineNr">110 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Can't yet handle segments where p_filesz != p_memsz (see <a href="http://refspecs.linuxbase.org/elf/elf.pdf">http://refspecs.linuxbase.org/elf/elf.pdf</a>)</span><span class="cSpecial">\n</span><span class="Constant">"</span> << die<span class="Delimiter">();</span> +<span id="L110" class="LineNr">110 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Can't yet handle segments where p_filesz != p_memsz (see <a href="http://refspecs.linuxbase.org/elf/elf.pdf">http://refspecs.linuxbase.org/elf/elf.pdf</a>)\n"</span> << die<span class="Delimiter">();</span> <span id="L111" class="LineNr">111 </span> <span id="L112" class="LineNr">112 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_offset + p_filesz > size<span class="Delimiter">)</span> <span id="L113" class="LineNr">113 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Invalid binary; segment at offset "</span> << offset << <span class="Constant">" is too large: wants to end at "</span> << p_offset+p_filesz << <span class="Constant">" but the file ends at "</span> << size << <span class="cSpecial">'\n'</span> << <a href='012elf.cc.html#L168'>die</a><span class="Delimiter">();</span> -<span id="L114" class="LineNr">114 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_memsz >= <a href='010---vm.cc.html#L115'>INITIAL_SEGMENT_SIZE</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L115" class="LineNr">115 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Code segment too small for SubX; for now please manually increase INITIAL_SEGMENT_SIZE.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L114" class="LineNr">114 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_memsz >= <a href='010---vm.cc.html#L115'>SEGMENT_ALIGNMENT</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L115" class="LineNr">115 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Code segment too small for SubX; for now please manually increase SEGMENT_ALIGNMENT.\n"</span> << end<span class="Delimiter">();</span> <span id="L116" class="LineNr">116 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L117" class="LineNr">117 </span> <span class="Delimiter">}</span> <span id="L118" class="LineNr">118 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"load"</span><span class="Delimiter">)</span> << <span class="Constant">"blitting file offsets ("</span> << p_offset << <span class="Constant">", "</span> << <span class="Delimiter">(</span>p_offset+p_filesz<span class="Delimiter">)</span> << <span class="Constant">") to addresses ("</span> << p_vaddr << <span class="Constant">", "</span> << <span class="Delimiter">(</span>p_vaddr+p_memsz<span class="Delimiter">)</span> << <span class="Constant">')'</span> << end<span class="Delimiter">();</span> <span id="L119" class="LineNr">119 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>size > p_memsz<span class="Delimiter">)</span> size = p_memsz<span class="Delimiter">;</span> -<span id="L120" class="LineNr">120 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>p_vaddr<span class="Delimiter">));</span> +<span id="L120" class="LineNr">120 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span>p_vaddr<span class="Delimiter">));</span> <span id="L121" class="LineNr">121 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < p_filesz<span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L122" class="LineNr">122 </span> assert<span class="Delimiter">(</span>overlap<span class="Delimiter">.</span>find<span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">)</span> == overlap<span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L123" class="LineNr">123 </span> <a href='010---vm.cc.html#L254'>write_mem_u8</a><span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">,</span> elf_contents[p_offset+i]<span class="Delimiter">);</span> +<span id="L123" class="LineNr">123 </span> <a href='010---vm.cc.html#L263'>write_mem_u8</a><span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">,</span> elf_contents[p_offset+i]<span class="Delimiter">);</span> <span id="L124" class="LineNr">124 </span> overlap<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>p_vaddr+i<span class="Delimiter">);</span> <span id="L125" class="LineNr">125 </span> <span class="Delimiter">}</span> -<span id="L126" class="LineNr">126 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>segment_index == <span class="Constant">0</span> && <a href='010---vm.cc.html#L185'>End_of_program</a> < p_vaddr+p_memsz<span class="Delimiter">)</span> -<span id="L127" class="LineNr">127 </span> <a href='010---vm.cc.html#L185'>End_of_program</a> = p_vaddr+p_memsz<span class="Delimiter">;</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>segment_index == <span class="Constant">0</span> && <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> < p_vaddr+p_memsz<span class="Delimiter">)</span> +<span id="L127" class="LineNr">127 </span> <span class="Special"><a href='010---vm.cc.html#L194'>End_of_program</a></span> = p_vaddr+p_memsz<span class="Delimiter">;</span> <span id="L128" class="LineNr">128 </span><span class="Delimiter">}</span> <span id="L129" class="LineNr">129 </span> <span id="L130" class="LineNr">130 </span><span class="Delimiter">:(before "End Includes")</span> @@ -194,16 +195,16 @@ if ('onhashchange' in window) { <span id="L135" class="LineNr">135 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='012elf.cc.html#L135'>CODE_SEGMENT</a> = <span class="Constant">0x09000000</span><span class="Delimiter">;</span> <span id="L136" class="LineNr">136 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='012elf.cc.html#L136'>DATA_SEGMENT</a> = <span class="Constant">0x0a000000</span><span class="Delimiter">;</span> <span id="L137" class="LineNr">137 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='012elf.cc.html#L137'>STACK_SEGMENT</a> = <span class="Constant">0x0b000000</span><span class="Delimiter">;</span> -<span id="L138" class="LineNr">138 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='012elf.cc.html#L138'>AFTER_STACK</a> = <span class="Constant">0x0b000ffc</span><span class="Delimiter">;</span> <span class="Comment">// forget final word because of the off-by-one with INITIAL_SEGMENT_SIZE;</span> +<span id="L138" class="LineNr">138 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='012elf.cc.html#L138'>AFTER_STACK</a> = <span class="Constant">0x0b000ffc</span><span class="Delimiter">;</span> <span class="Comment">// forget final word because of the off-by-one with SEGMENT_ALIGNMENT;</span> <span id="L139" class="LineNr">139 </span><span class="Normal">const</span> <span class="Normal">int</span> <a href='012elf.cc.html#L139'>ARGV_DATA_SEGMENT</a> = <span class="Constant">0x0c000000</span><span class="Delimiter">;</span> <span id="L140" class="LineNr">140 </span><span class="Delimiter">:(code)</span> <span id="L141" class="LineNr">141 </span><span class="Normal">void</span> <a href='012elf.cc.html#L141'>dump_stack</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L142" class="LineNr">142 </span> cerr << <span class="Constant">"stack:</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L143" class="LineNr">143 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> a = AFTER_STACK-<span class="Constant">4</span><span class="Delimiter">;</span> a > Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> a -= <span class="Constant">4</span><span class="Delimiter">)</span> -<span id="L144" class="LineNr">144 </span> cerr << <span class="Constant">" 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << a << <span class="Constant">" => 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>a<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L145" class="LineNr">145 </span> cerr << <span class="Constant">" 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << <span class="Constant">" => 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << <span class="Constant">" <=== <a href='010---vm.cc.html#L17'>ESP</a></span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L146" class="LineNr">146 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> a = Reg[ESP]<span class="Delimiter">.</span>u-<span class="Constant">4</span><span class="Delimiter">;</span> a > Reg[ESP]<span class="Delimiter">.</span>u-<span class="Constant">40</span><span class="Delimiter">;</span> a -= <span class="Constant">4</span><span class="Delimiter">)</span> -<span id="L147" class="LineNr">147 </span> cerr << <span class="Constant">" 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << a << <span class="Constant">" => 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>a<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L142" class="LineNr">142 </span> cerr << <span class="Constant">"stack:\n"</span><span class="Delimiter">;</span> +<span id="L143" class="LineNr">143 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> a = AFTER_STACK-<span class="Constant">4</span><span class="Delimiter">;</span> a > <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> a -= <span class="Constant">4</span><span class="Delimiter">)</span> +<span id="L144" class="LineNr">144 </span> cerr << <span class="Constant">" 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << a << <span class="Constant">" => 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span>a<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span> cerr << <span class="Constant">" 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u << <span class="Constant">" => 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << <span class="Constant">" <=== ESP\n"</span><span class="Delimiter">;</span> +<span id="L146" class="LineNr">146 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">uint32_t</span> a = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u-<span class="Constant">4</span><span class="Delimiter">;</span> a > <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u-<span class="Constant">40</span><span class="Delimiter">;</span> a -= <span class="Constant">4</span><span class="Delimiter">)</span> +<span id="L147" class="LineNr">147 </span> cerr << <span class="Constant">" 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << a << <span class="Constant">" => 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span>a<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L148" class="LineNr">148 </span><span class="Delimiter">}</span> <span id="L149" class="LineNr">149 </span> <span id="L150" class="LineNr">150 </span><span class="Normal">inline</span> <span class="Normal">uint32_t</span> <a href='012elf.cc.html#L150'>u32_in</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span>* p<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -227,7 +228,7 @@ if ('onhashchange' in window) { <span id="L168" class="LineNr">168 </span><span class="Normal">struct</span> <a href='012elf.cc.html#L168'>die</a> <span class="Delimiter">{};</span> <span id="L169" class="LineNr">169 </span><span class="Delimiter">:(code)</span> <span id="L170" class="LineNr">170 </span>ostream& <span class="Normal">operator</span><<<span class="Delimiter">(</span>ostream& <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">,</span> <a href='012elf.cc.html#L168'>die</a> <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L171" class="LineNr">171 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">)</span> <a href='003trace.cc.html#L174'>Trace_stream</a><span class="Delimiter">-></span><a href='003trace.cc.html#L147'>newline</a><span class="Delimiter">();</span> +<span id="L171" class="LineNr">171 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">)</span> <span class="Special"><a href='003trace.cc.html#L174'>Trace_stream</a></span><span class="Delimiter">-></span><a href='003trace.cc.html#L147'>newline</a><span class="Delimiter">();</span> <span id="L172" class="LineNr">172 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L173" class="LineNr">173 </span><span class="Delimiter">}</span> <span id="L174" class="LineNr">174 </span> diff --git a/html/subx/013direct_addressing.cc.html b/html/subx/013direct_addressing.cc.html index 606a4b21..504d7809 100644 --- a/html/subx/013direct_addressing.cc.html +++ b/html/subx/013direct_addressing.cc.html @@ -66,7 +66,7 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment">//: operating directly on a register</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"01"</span><span class="Delimiter">,</span> <span class="Constant">"add r32 to rm32 (add)"</span><span class="Delimiter">);</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"01"</span><span class="Delimiter">,</span> <span class="Constant">"add r32 to rm32 (add)"</span><span class="Delimiter">);</span> <span id="L5" class="LineNr"> 5 </span> <span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(scenario add_r32_to_r32)</span> <span id="L7" class="LineNr"> 7 </span><span class="Special">% Reg[EAX].i = 0x10;</span> @@ -81,11 +81,11 @@ if ('onhashchange' in window) { <span id="L16" class="LineNr"> 16 </span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L18" class="LineNr"> 18 </span><span class="Normal">case</span> <span class="Constant">0x01</span>: <span class="Delimiter">{</span> <span class="Comment">// add r32 to r/m32</span> -<span id="L19" class="LineNr"> 19 </span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L20" class="LineNr"> 20 </span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L21" class="LineNr"> 21 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" to r/m32"</span> << end<span class="Delimiter">();</span> <span id="L22" class="LineNr"> 22 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L23" class="LineNr"> 23 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> +<span id="L23" class="LineNr"> 23 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> <span id="L24" class="LineNr"> 24 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L25" class="LineNr"> 25 </span><span class="Delimiter">}</span> <span id="L26" class="LineNr"> 26 </span> @@ -100,9 +100,9 @@ if ('onhashchange' in window) { <span id="L35" class="LineNr"> 35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod == <span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L36" class="LineNr"> 36 </span> <span class="Comment">// mod 3 is just register direct addressing</span> <span id="L37" class="LineNr"> 37 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"r/m32 is "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L38" class="LineNr"> 38 </span> <span class="Identifier">return</span> &Reg[rm]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Identifier">return</span> &<span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rm]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> <span id="L39" class="LineNr"> 39 </span> <span class="Delimiter">}</span> -<span id="L40" class="LineNr"> 40 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L239'>mem_addr_i32</a><span class="Delimiter">(</span><a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L248'>mem_addr_i32</a><span class="Delimiter">(</span><a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> <span id="L41" class="LineNr"> 41 </span><span class="Delimiter">}</span> <span id="L42" class="LineNr"> 42 </span> <span id="L43" class="LineNr"> 43 </span><span class="Normal">uint32_t</span> <a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> modrm<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -113,11 +113,11 @@ if ('onhashchange' in window) { <span id="L48" class="LineNr"> 48 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>mod<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L49" class="LineNr"> 49 </span> <span class="Normal">case</span> <span class="Constant">3</span>: <span id="L50" class="LineNr"> 50 </span> <span class="Comment">// mod 3 is just register direct addressing</span> -<span id="L51" class="LineNr"> 51 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"unexpected direct addressing mode</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L51" class="LineNr"> 51 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"unexpected direct addressing mode\n"</span> << end<span class="Delimiter">();</span> <span id="L52" class="LineNr"> 52 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L53" class="LineNr"> 53 </span> <span class="Comment">// End Mod Special-cases(addr)</span> <span id="L54" class="LineNr"> 54 </span> <span class="Normal">default</span>: -<span id="L55" class="LineNr"> 55 </span> cerr << <span class="Constant">"unrecognized mod bits: "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>mod<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L55" class="LineNr"> 55 </span> cerr << <span class="Constant">"unrecognized mod bits: "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>mod<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L56" class="LineNr"> 56 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L57" class="LineNr"> 57 </span> <span class="Delimiter">}</span> <span id="L58" class="LineNr"> 58 </span> <span class="Comment">//: other mods are indirect, and they'll set addr appropriately</span> @@ -141,7 +141,7 @@ if ('onhashchange' in window) { <span id="L76" class="LineNr"> 76 </span><span class="SalientComment">//:: subtract</span> <span id="L77" class="LineNr"> 77 </span> <span id="L78" class="LineNr"> 78 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L79" class="LineNr"> 79 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"29"</span><span class="Delimiter">,</span> <span class="Constant">"subtract r32 from rm32 (sub)"</span><span class="Delimiter">);</span> +<span id="L79" class="LineNr"> 79 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"29"</span><span class="Delimiter">,</span> <span class="Constant">"subtract r32 from rm32 (sub)"</span><span class="Delimiter">);</span> <span id="L80" class="LineNr"> 80 </span> <span id="L81" class="LineNr"> 81 </span><span class="Delimiter">:(scenario subtract_r32_from_r32)</span> <span id="L82" class="LineNr"> 82 </span><span class="Special">% Reg[EAX].i = 10;</span> @@ -156,18 +156,18 @@ if ('onhashchange' in window) { <span id="L91" class="LineNr"> 91 </span> <span id="L92" class="LineNr"> 92 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L93" class="LineNr"> 93 </span><span class="Normal">case</span> <span class="Constant">0x29</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract r32 from r/m32</span> -<span id="L94" class="LineNr"> 94 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L95" class="LineNr"> 95 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L96" class="LineNr"> 96 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" from r/m32"</span> << end<span class="Delimiter">();</span> <span id="L97" class="LineNr"> 97 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L98" class="LineNr"> 98 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>-<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>-<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> <span id="L99" class="LineNr"> 99 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L100" class="LineNr">100 </span><span class="Delimiter">}</span> <span id="L101" class="LineNr">101 </span> <span id="L102" class="LineNr">102 </span><span class="SalientComment">//:: multiply</span> <span id="L103" class="LineNr">103 </span> <span id="L104" class="LineNr">104 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L105" class="LineNr">105 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"f7"</span><span class="Delimiter">,</span> <span class="Constant">"negate/multiply rm32 (with <a href='010---vm.cc.html#L13'>EAX</a> if necessary) depending on subop (neg/mul)"</span><span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"f7"</span><span class="Delimiter">,</span> <span class="Constant">"negate/multiply rm32 (with <a href='010---vm.cc.html#L13'>EAX</a> if necessary) depending on subop (neg/mul)"</span><span class="Delimiter">);</span> <span id="L106" class="LineNr">106 </span> <span id="L107" class="LineNr">107 </span><span class="Delimiter">:(scenario multiply_eax_by_r32)</span> <span id="L108" class="LineNr">108 </span><span class="Special">% Reg[EAX].i = 4;</span> @@ -183,23 +183,23 @@ if ('onhashchange' in window) { <span id="L118" class="LineNr">118 </span> <span id="L119" class="LineNr">119 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L120" class="LineNr">120 </span><span class="Normal">case</span> <span class="Constant">0xf7</span>: <span class="Delimiter">{</span> <span class="Comment">// xor r32 with r/m32</span> -<span id="L121" class="LineNr">121 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L121" class="LineNr">121 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L122" class="LineNr">122 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"operate on r/m32"</span> << end<span class="Delimiter">();</span> <span id="L123" class="LineNr">123 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L124" class="LineNr">124 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> <span id="L125" class="LineNr">125 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L126" class="LineNr">126 </span> <span class="Normal">case</span> <span class="Constant">4</span>: <span class="Delimiter">{</span> <span class="Comment">// mul unsigned EAX by r/m32</span> <span id="L127" class="LineNr">127 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: multiply <a href='010---vm.cc.html#L13'>EAX</a> by r/m32"</span> << end<span class="Delimiter">();</span> -<span id="L128" class="LineNr">128 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> result = Reg[EAX]<span class="Delimiter">.</span>u * <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> -<span id="L129" class="LineNr">129 </span> Reg[EAX]<span class="Delimiter">.</span>u = result & <span class="Constant">0xffffffff</span><span class="Delimiter">;</span> -<span id="L130" class="LineNr">130 </span> Reg[EDX]<span class="Delimiter">.</span>u = result >> <span class="Constant">32</span><span class="Delimiter">;</span> -<span id="L131" class="LineNr">131 </span> <a href='010---vm.cc.html#L81'>OF</a> = <span class="Delimiter">(</span>Reg[EDX]<span class="Delimiter">.</span>u != <span class="Constant">0</span><span class="Delimiter">);</span> -<span id="L132" class="LineNr">132 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[EAX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L128" class="LineNr">128 </span> <span class="Normal">const</span> <span class="Normal">uint64_t</span> result = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u * <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u = result & <span class="Constant">0xffffffff</span><span class="Delimiter">;</span> +<span id="L130" class="LineNr">130 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u = result >> <span class="Constant">32</span><span class="Delimiter">;</span> +<span id="L131" class="LineNr">131 </span> <a href='010---vm.cc.html#L81'>OF</a> = <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u != <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> <span id="L133" class="LineNr">133 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L134" class="LineNr">134 </span> <span class="Delimiter">}</span> <span id="L135" class="LineNr">135 </span> <span class="Comment">// End Op f7 Subops</span> <span id="L136" class="LineNr">136 </span> <span class="Normal">default</span>: -<span id="L137" class="LineNr">137 </span> cerr << <span class="Constant">"unrecognized sub-opcode after f7: "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L137" class="LineNr">137 </span> cerr << <span class="Constant">"unrecognized sub-opcode after f7: "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L138" class="LineNr">138 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L139" class="LineNr">139 </span> <span class="Delimiter">}</span> <span id="L140" class="LineNr">140 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -208,7 +208,7 @@ if ('onhashchange' in window) { <span id="L143" class="LineNr">143 </span><span class="Comment">//:</span> <span id="L144" class="LineNr">144 </span> <span id="L145" class="LineNr">145 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L146" class="LineNr">146 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"af"</span><span class="Delimiter">,</span> <span class="Constant">"multiply rm32 into r32 (imul)"</span><span class="Delimiter">);</span> +<span id="L146" class="LineNr">146 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"af"</span><span class="Delimiter">,</span> <span class="Constant">"multiply rm32 into r32 (imul)"</span><span class="Delimiter">);</span> <span id="L147" class="LineNr">147 </span> <span id="L148" class="LineNr">148 </span><span class="Delimiter">:(scenario multiply_r32_into_r32)</span> <span id="L149" class="LineNr">149 </span><span class="Special">% Reg[EAX].i = 4;</span> @@ -223,11 +223,11 @@ if ('onhashchange' in window) { <span id="L158" class="LineNr">158 </span> <span id="L159" class="LineNr">159 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> <span id="L160" class="LineNr">160 </span><span class="Normal">case</span> <span class="Constant">0xaf</span>: <span class="Delimiter">{</span> <span class="Comment">// multiply r32 into r/m32</span> -<span id="L161" class="LineNr">161 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L161" class="LineNr">161 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L162" class="LineNr">162 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L163" class="LineNr">163 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"multiply r/m32 into "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L164" class="LineNr">164 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L165" class="LineNr">165 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>*<span class="Delimiter">,</span> Reg[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> *arg1<span class="Delimiter">);</span> +<span id="L165" class="LineNr">165 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>*<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg2]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> *arg1<span class="Delimiter">);</span> <span id="L166" class="LineNr">166 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L167" class="LineNr">167 </span><span class="Delimiter">}</span> <span id="L168" class="LineNr">168 </span> @@ -256,7 +256,7 @@ if ('onhashchange' in window) { <span id="L191" class="LineNr">191 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L192" class="LineNr">192 </span> <span class="Delimiter">}</span> <span id="L193" class="LineNr">193 </span> *arg1 = -<span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> -<span id="L194" class="LineNr">194 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L194" class="LineNr">194 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> <span id="L195" class="LineNr">195 </span> SF = <span class="Delimiter">(</span>*arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> <span id="L196" class="LineNr">196 </span> ZF = <span class="Delimiter">(</span>*arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L197" class="LineNr">197 </span> <a href='010---vm.cc.html#L81'>OF</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> @@ -277,7 +277,7 @@ if ('onhashchange' in window) { <span id="L212" class="LineNr">212 </span><span class="SalientComment">//:: and</span> <span id="L213" class="LineNr">213 </span> <span id="L214" class="LineNr">214 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L215" class="LineNr">215 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"21"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise AND of r32 with rm32 (and)"</span><span class="Delimiter">);</span> +<span id="L215" class="LineNr">215 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"21"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise AND of r32 with rm32 (and)"</span><span class="Delimiter">);</span> <span id="L216" class="LineNr">216 </span> <span id="L217" class="LineNr">217 </span><span class="Delimiter">:(scenario and_r32_with_r32)</span> <span id="L218" class="LineNr">218 </span><span class="Special">% Reg[EAX].i = 0x0a0b0c0d;</span> @@ -292,18 +292,18 @@ if ('onhashchange' in window) { <span id="L227" class="LineNr">227 </span> <span id="L228" class="LineNr">228 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L229" class="LineNr">229 </span><span class="Normal">case</span> <span class="Constant">0x21</span>: <span class="Delimiter">{</span> <span class="Comment">// and r32 with r/m32</span> -<span id="L230" class="LineNr">230 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L230" class="LineNr">230 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L231" class="LineNr">231 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L232" class="LineNr">232 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> <span id="L233" class="LineNr">233 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L234" class="LineNr">234 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>&<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L234" class="LineNr">234 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>&<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L235" class="LineNr">235 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> <span id="L237" class="LineNr">237 </span> <span id="L238" class="LineNr">238 </span><span class="SalientComment">//:: or</span> <span id="L239" class="LineNr">239 </span> <span id="L240" class="LineNr">240 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L241" class="LineNr">241 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"09"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise OR of r32 with rm32 (or)"</span><span class="Delimiter">);</span> +<span id="L241" class="LineNr">241 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"09"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise OR of r32 with rm32 (or)"</span><span class="Delimiter">);</span> <span id="L242" class="LineNr">242 </span> <span id="L243" class="LineNr">243 </span><span class="Delimiter">:(scenario or_r32_with_r32)</span> <span id="L244" class="LineNr">244 </span><span class="Special">% Reg[EAX].i = 0x0a0b0c0d;</span> @@ -318,18 +318,18 @@ if ('onhashchange' in window) { <span id="L253" class="LineNr">253 </span> <span id="L254" class="LineNr">254 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L255" class="LineNr">255 </span><span class="Normal">case</span> <span class="Constant">0x09</span>: <span class="Delimiter">{</span> <span class="Comment">// or r32 with r/m32</span> -<span id="L256" class="LineNr">256 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L256" class="LineNr">256 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L257" class="LineNr">257 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L258" class="LineNr">258 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> <span id="L259" class="LineNr">259 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L260" class="LineNr">260 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L260" class="LineNr">260 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L261" class="LineNr">261 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L262" class="LineNr">262 </span><span class="Delimiter">}</span> <span id="L263" class="LineNr">263 </span> <span id="L264" class="LineNr">264 </span><span class="SalientComment">//:: xor</span> <span id="L265" class="LineNr">265 </span> <span id="L266" class="LineNr">266 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L267" class="LineNr">267 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"31"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise XOR of r32 with rm32 (xor)"</span><span class="Delimiter">);</span> +<span id="L267" class="LineNr">267 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"31"</span><span class="Delimiter">,</span> <span class="Constant">"rm32 = bitwise XOR of r32 with rm32 (xor)"</span><span class="Delimiter">);</span> <span id="L268" class="LineNr">268 </span> <span id="L269" class="LineNr">269 </span><span class="Delimiter">:(scenario xor_r32_with_r32)</span> <span id="L270" class="LineNr">270 </span><span class="Special">% Reg[EAX].i = 0x0a0b0c0d;</span> @@ -344,11 +344,11 @@ if ('onhashchange' in window) { <span id="L279" class="LineNr">279 </span> <span id="L280" class="LineNr">280 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L281" class="LineNr">281 </span><span class="Normal">case</span> <span class="Constant">0x31</span>: <span class="Delimiter">{</span> <span class="Comment">// xor r32 with r/m32</span> -<span id="L282" class="LineNr">282 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L282" class="LineNr">282 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L283" class="LineNr">283 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L284" class="LineNr">284 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> <span id="L285" class="LineNr">285 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L286" class="LineNr">286 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>^<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> Reg[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L286" class="LineNr">286 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>^<span class="Delimiter">,</span> *arg1<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg2]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L287" class="LineNr">287 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L288" class="LineNr">288 </span><span class="Delimiter">}</span> <span id="L289" class="LineNr">289 </span> @@ -369,7 +369,7 @@ if ('onhashchange' in window) { <span id="L304" class="LineNr">304 </span><span class="Normal">case</span> <span class="Constant">2</span>: <span class="Delimiter">{</span> <span class="Comment">// not r/m32</span> <span id="L305" class="LineNr">305 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subop: not"</span> << end<span class="Delimiter">();</span> <span id="L306" class="LineNr">306 </span> *arg1 = ~<span class="Delimiter">(</span>*arg1<span class="Delimiter">);</span> -<span id="L307" class="LineNr">307 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> +<span id="L307" class="LineNr">307 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *arg1 << end<span class="Delimiter">();</span> <span id="L308" class="LineNr">308 </span> SF = <span class="Delimiter">(</span>*arg1 >> <span class="Constant">31</span><span class="Delimiter">);</span> <span id="L309" class="LineNr">309 </span> ZF = <span class="Delimiter">(</span>*arg1 == <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L310" class="LineNr">310 </span> <a href='010---vm.cc.html#L81'>OF</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> @@ -379,7 +379,7 @@ if ('onhashchange' in window) { <span id="L314" class="LineNr">314 </span><span class="SalientComment">//:: compare (cmp)</span> <span id="L315" class="LineNr">315 </span> <span id="L316" class="LineNr">316 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L317" class="LineNr">317 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"39"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if rm32 < r32 (cmp)"</span><span class="Delimiter">);</span> +<span id="L317" class="LineNr">317 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"39"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if rm32 < r32 (cmp)"</span><span class="Delimiter">);</span> <span id="L318" class="LineNr">318 </span> <span id="L319" class="LineNr">319 </span><span class="Delimiter">:(scenario compare_r32_with_r32_greater)</span> <span id="L320" class="LineNr">320 </span><span class="Special">% Reg[EAX].i = 0x0a0b0c0d;</span> @@ -394,11 +394,11 @@ if ('onhashchange' in window) { <span id="L329" class="LineNr">329 </span> <span id="L330" class="LineNr">330 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L331" class="LineNr">331 </span><span class="Normal">case</span> <span class="Constant">0x39</span>: <span class="Delimiter">{</span> <span class="Comment">// set SF if r/m32 < r32</span> -<span id="L332" class="LineNr">332 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L332" class="LineNr">332 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L333" class="LineNr">333 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L334" class="LineNr">334 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> <span id="L335" class="LineNr">335 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L336" class="LineNr">336 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = Reg[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L336" class="LineNr">336 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> <span id="L337" class="LineNr">337 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> tmp1 = *arg1 - arg2<span class="Delimiter">;</span> <span id="L338" class="LineNr">338 </span> SF = <span class="Delimiter">(</span>tmp1 < <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L339" class="LineNr">339 </span> ZF = <span class="Delimiter">(</span>tmp1 == <span class="Constant">0</span><span class="Delimiter">);</span> @@ -433,7 +433,7 @@ if ('onhashchange' in window) { <span id="L368" class="LineNr">368 </span><span class="SalientComment">//:: copy (mov)</span> <span id="L369" class="LineNr">369 </span> <span id="L370" class="LineNr">370 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L371" class="LineNr">371 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"89"</span><span class="Delimiter">,</span> <span class="Constant">"copy r32 to rm32 (mov)"</span><span class="Delimiter">);</span> +<span id="L371" class="LineNr">371 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"89"</span><span class="Delimiter">,</span> <span class="Constant">"copy r32 to rm32 (mov)"</span><span class="Delimiter">);</span> <span id="L372" class="LineNr">372 </span> <span id="L373" class="LineNr">373 </span><span class="Delimiter">:(scenario copy_r32_to_r32)</span> <span id="L374" class="LineNr">374 </span><span class="Special">% Reg[EBX].i = 0xaf;</span> @@ -447,19 +447,19 @@ if ('onhashchange' in window) { <span id="L382" class="LineNr">382 </span> <span id="L383" class="LineNr">383 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L384" class="LineNr">384 </span><span class="Normal">case</span> <span class="Constant">0x89</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r32 to r/m32</span> -<span id="L385" class="LineNr">385 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L385" class="LineNr">385 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L386" class="LineNr">386 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rsrc = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L387" class="LineNr">387 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rsrc<span class="Delimiter">)</span> << <span class="Constant">" to r/m32"</span> << end<span class="Delimiter">();</span> <span id="L388" class="LineNr">388 </span> <span class="Normal">int32_t</span>* dest = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L389" class="LineNr">389 </span> *dest = Reg[rsrc]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> -<span id="L390" class="LineNr">390 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *dest << end<span class="Delimiter">();</span> +<span id="L389" class="LineNr">389 </span> *dest = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rsrc]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L390" class="LineNr">390 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *dest << end<span class="Delimiter">();</span> <span id="L391" class="LineNr">391 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L392" class="LineNr">392 </span><span class="Delimiter">}</span> <span id="L393" class="LineNr">393 </span> <span id="L394" class="LineNr">394 </span><span class="SalientComment">//:: xchg</span> <span id="L395" class="LineNr">395 </span> <span id="L396" class="LineNr">396 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L397" class="LineNr">397 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">"swap the <a href='003trace.cc.html#L74'>contents</a> of r32 and rm32 (xchg)"</span><span class="Delimiter">);</span> +<span id="L397" class="LineNr">397 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">"swap the <a href='003trace.cc.html#L74'>contents</a> of r32 and rm32 (xchg)"</span><span class="Delimiter">);</span> <span id="L398" class="LineNr">398 </span> <span id="L399" class="LineNr">399 </span><span class="Delimiter">:(scenario xchg_r32_with_r32)</span> <span id="L400" class="LineNr">400 </span><span class="Special">% Reg[EBX].i = 0xaf;</span> @@ -475,29 +475,29 @@ if ('onhashchange' in window) { <span id="L410" class="LineNr">410 </span> <span id="L411" class="LineNr">411 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L412" class="LineNr">412 </span><span class="Normal">case</span> <span class="Constant">0x87</span>: <span class="Delimiter">{</span> <span class="Comment">// exchange r32 with r/m32</span> -<span id="L413" class="LineNr">413 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L413" class="LineNr">413 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L414" class="LineNr">414 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg2 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L415" class="LineNr">415 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"exchange "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << <span class="Constant">" with r/m32"</span> << end<span class="Delimiter">();</span> <span id="L416" class="LineNr">416 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L417" class="LineNr">417 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> tmp = *arg1<span class="Delimiter">;</span> -<span id="L418" class="LineNr">418 </span> *arg1 = Reg[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> -<span id="L419" class="LineNr">419 </span> Reg[reg2]<span class="Delimiter">.</span>i = tmp<span class="Delimiter">;</span> -<span id="L420" class="LineNr">420 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *arg1 << <span class="Constant">" in r/m32"</span> << end<span class="Delimiter">();</span> -<span id="L421" class="LineNr">421 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[reg2]<span class="Delimiter">.</span>i << <span class="Constant">" in "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L418" class="LineNr">418 </span> *arg1 = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg2]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L419" class="LineNr">419 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg2]<span class="Delimiter">.</span>i = tmp<span class="Delimiter">;</span> +<span id="L420" class="LineNr">420 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *arg1 << <span class="Constant">" in r/m32"</span> << end<span class="Delimiter">();</span> +<span id="L421" class="LineNr">421 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg2]<span class="Delimiter">.</span>i << <span class="Constant">" in "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>reg2<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L422" class="LineNr">422 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L423" class="LineNr">423 </span><span class="Delimiter">}</span> <span id="L424" class="LineNr">424 </span> <span id="L425" class="LineNr">425 </span><span class="SalientComment">//:: increment</span> <span id="L426" class="LineNr">426 </span> <span id="L427" class="LineNr">427 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L428" class="LineNr">428 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"40"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L13'>EAX</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L429" class="LineNr">429 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"41"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L14'>ECX</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L430" class="LineNr">430 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"42"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L15'>EDX</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L431" class="LineNr">431 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"43"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L16'>EBX</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L432" class="LineNr">432 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"44"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L17'>ESP</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L433" class="LineNr">433 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"45"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L18'>EBP</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L434" class="LineNr">434 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"46"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L19'>ESI</a> (inc)"</span><span class="Delimiter">);</span> -<span id="L435" class="LineNr">435 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"47"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L20'>EDI</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L428" class="LineNr">428 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"40"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L13'>EAX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L429" class="LineNr">429 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"41"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L14'>ECX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L430" class="LineNr">430 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"42"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L15'>EDX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L431" class="LineNr">431 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"43"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L16'>EBX</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L432" class="LineNr">432 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"44"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L17'>ESP</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L433" class="LineNr">433 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"45"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L18'>EBP</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L434" class="LineNr">434 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"46"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L19'>ESI</a> (inc)"</span><span class="Delimiter">);</span> +<span id="L435" class="LineNr">435 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"47"</span><span class="Delimiter">,</span> <span class="Constant">"increment <a href='010---vm.cc.html#L20'>EDI</a> (inc)"</span><span class="Delimiter">);</span> <span id="L436" class="LineNr">436 </span> <span id="L437" class="LineNr">437 </span><span class="Delimiter">:(scenario increment_r32)</span> <span id="L438" class="LineNr">438 </span><span class="Special">% Reg[ECX].u = 0x1f;</span> @@ -518,13 +518,13 @@ if ('onhashchange' in window) { <span id="L453" class="LineNr">453 </span><span class="Normal">case</span> <span class="Constant">0x47</span>: <span class="Delimiter">{</span> <span class="Comment">// increment r32</span> <span id="L454" class="LineNr">454 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L23'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L455" class="LineNr">455 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"increment "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L456" class="LineNr">456 </span> ++Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L457" class="LineNr">457 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[reg]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L456" class="LineNr">456 </span> ++<span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L457" class="LineNr">457 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> <span id="L458" class="LineNr">458 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L459" class="LineNr">459 </span><span class="Delimiter">}</span> <span id="L460" class="LineNr">460 </span> <span id="L461" class="LineNr">461 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L462" class="LineNr">462 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"ff"</span><span class="Delimiter">,</span> <span class="Constant">"increment/decrement/jump/push/call rm32 based on subop (inc/dec/jmp/push/call)"</span><span class="Delimiter">);</span> +<span id="L462" class="LineNr">462 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"ff"</span><span class="Delimiter">,</span> <span class="Constant">"increment/decrement/jump/push/call rm32 based on subop (inc/dec/jmp/push/call)"</span><span class="Delimiter">);</span> <span id="L463" class="LineNr">463 </span> <span id="L464" class="LineNr">464 </span><span class="Delimiter">:(scenario increment_rm32)</span> <span id="L465" class="LineNr">465 </span><span class="Special">% Reg[EAX].u = 0x20;</span> @@ -538,18 +538,18 @@ if ('onhashchange' in window) { <span id="L473" class="LineNr">473 </span> <span id="L474" class="LineNr">474 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L475" class="LineNr">475 </span><span class="Normal">case</span> <span class="Constant">0xff</span>: <span class="Delimiter">{</span> -<span id="L476" class="LineNr">476 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L476" class="LineNr">476 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L477" class="LineNr">477 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> <span id="L478" class="LineNr">478 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L479" class="LineNr">479 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Delimiter">{</span> <span class="Comment">// increment r/m32</span> <span id="L480" class="LineNr">480 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"increment r/m32"</span> << end<span class="Delimiter">();</span> <span id="L481" class="LineNr">481 </span> <span class="Normal">int32_t</span>* <a href='001help.cc.html#L15'>arg</a> = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L482" class="LineNr">482 </span> ++*arg<span class="Delimiter">;</span> -<span id="L483" class="LineNr">483 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *arg << end<span class="Delimiter">();</span> +<span id="L483" class="LineNr">483 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *arg << end<span class="Delimiter">();</span> <span id="L484" class="LineNr">484 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L485" class="LineNr">485 </span> <span class="Delimiter">}</span> <span id="L486" class="LineNr">486 </span> <span class="Normal">default</span>: -<span id="L487" class="LineNr">487 </span> cerr << <span class="Constant">"unrecognized subop for ff: "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L487" class="LineNr">487 </span> cerr << <span class="Constant">"unrecognized subop for ff: "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L488" class="LineNr">488 </span> <a href='003trace.cc.html#L207'>DUMP</a><span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> <span id="L489" class="LineNr">489 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L490" class="LineNr">490 </span> <span class="Comment">// End Op ff Subops</span> @@ -560,14 +560,14 @@ if ('onhashchange' in window) { <span id="L495" class="LineNr">495 </span><span class="SalientComment">//:: decrement</span> <span id="L496" class="LineNr">496 </span> <span id="L497" class="LineNr">497 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L498" class="LineNr">498 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"48"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L13'>EAX</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L499" class="LineNr">499 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"49"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L14'>ECX</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L500" class="LineNr">500 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4a"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L15'>EDX</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L501" class="LineNr">501 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4b"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L16'>EBX</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L502" class="LineNr">502 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4c"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L17'>ESP</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L503" class="LineNr">503 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4d"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L18'>EBP</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L504" class="LineNr">504 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4e"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L19'>ESI</a> (dec)"</span><span class="Delimiter">);</span> -<span id="L505" class="LineNr">505 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"4f"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L20'>EDI</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L498" class="LineNr">498 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"48"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L13'>EAX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L499" class="LineNr">499 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"49"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L14'>ECX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L500" class="LineNr">500 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"4a"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L15'>EDX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L501" class="LineNr">501 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"4b"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L16'>EBX</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L502" class="LineNr">502 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"4c"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L17'>ESP</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L503" class="LineNr">503 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"4d"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L18'>EBP</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L504" class="LineNr">504 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"4e"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L19'>ESI</a> (dec)"</span><span class="Delimiter">);</span> +<span id="L505" class="LineNr">505 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"4f"</span><span class="Delimiter">,</span> <span class="Constant">"decrement <a href='010---vm.cc.html#L20'>EDI</a> (dec)"</span><span class="Delimiter">);</span> <span id="L506" class="LineNr">506 </span> <span id="L507" class="LineNr">507 </span><span class="Delimiter">:(scenario decrement_r32)</span> <span id="L508" class="LineNr">508 </span><span class="Special">% Reg[ECX].u = 0x1f;</span> @@ -588,8 +588,8 @@ if ('onhashchange' in window) { <span id="L523" class="LineNr">523 </span><span class="Normal">case</span> <span class="Constant">0x4f</span>: <span class="Delimiter">{</span> <span class="Comment">// decrement r32</span> <span id="L524" class="LineNr">524 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L23'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L525" class="LineNr">525 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrement "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L526" class="LineNr">526 </span> --Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L527" class="LineNr">527 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[reg]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L526" class="LineNr">526 </span> --<span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L527" class="LineNr">527 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> <span id="L528" class="LineNr">528 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L529" class="LineNr">529 </span><span class="Delimiter">}</span> <span id="L530" class="LineNr">530 </span> @@ -608,21 +608,21 @@ if ('onhashchange' in window) { <span id="L543" class="LineNr">543 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"decrement r/m32"</span> << end<span class="Delimiter">();</span> <span id="L544" class="LineNr">544 </span> <span class="Normal">int32_t</span>* <a href='001help.cc.html#L15'>arg</a> = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L545" class="LineNr">545 </span> --*arg<span class="Delimiter">;</span> -<span id="L546" class="LineNr">546 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *arg << end<span class="Delimiter">();</span> +<span id="L546" class="LineNr">546 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing value 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *arg << end<span class="Delimiter">();</span> <span id="L547" class="LineNr">547 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L548" class="LineNr">548 </span><span class="Delimiter">}</span> <span id="L549" class="LineNr">549 </span> <span id="L550" class="LineNr">550 </span><span class="SalientComment">//:: push</span> <span id="L551" class="LineNr">551 </span> <span id="L552" class="LineNr">552 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L553" class="LineNr">553 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"50"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L13'>EAX</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L554" class="LineNr">554 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L14'>ECX</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L555" class="LineNr">555 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L15'>EDX</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L556" class="LineNr">556 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L16'>EBX</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L557" class="LineNr">557 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"54"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L17'>ESP</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L558" class="LineNr">558 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"55"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L18'>EBP</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L559" class="LineNr">559 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"56"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L19'>ESI</a> to stack (push)"</span><span class="Delimiter">);</span> -<span id="L560" class="LineNr">560 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"57"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L20'>EDI</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L553" class="LineNr">553 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"50"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L13'>EAX</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L554" class="LineNr">554 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L14'>ECX</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L555" class="LineNr">555 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L15'>EDX</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L556" class="LineNr">556 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L16'>EBX</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L557" class="LineNr">557 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"54"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L17'>ESP</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L558" class="LineNr">558 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"55"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L18'>EBP</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L559" class="LineNr">559 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"56"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L19'>ESI</a> to stack (push)"</span><span class="Delimiter">);</span> +<span id="L560" class="LineNr">560 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"57"</span><span class="Delimiter">,</span> <span class="Constant">"push <a href='010---vm.cc.html#L20'>EDI</a> to stack (push)"</span><span class="Delimiter">);</span> <span id="L561" class="LineNr">561 </span> <span id="L562" class="LineNr">562 </span><span class="Delimiter">:(scenario push_r32)</span> <span id="L563" class="LineNr">563 </span><span class="Special">% Reg[ESP].u = 0x64;</span> @@ -646,26 +646,26 @@ if ('onhashchange' in window) { <span id="L581" class="LineNr">581 </span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L23'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L582" class="LineNr">582 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L583" class="LineNr">583 </span><span class="CommentedCode">//? cerr << "push: " << NUM(reg) << ": " << Reg[reg].u << " => " << Reg[ESP].u << '\n';</span> -<span id="L584" class="LineNr">584 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span>Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L584" class="LineNr">584 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L585" class="LineNr">585 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L586" class="LineNr">586 </span><span class="Delimiter">}</span> <span id="L587" class="LineNr">587 </span> <span id="L588" class="LineNr">588 </span><span class="SalientComment">//:: pop</span> <span id="L589" class="LineNr">589 </span> <span id="L590" class="LineNr">590 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L591" class="LineNr">591 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L13'>EAX</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L592" class="LineNr">592 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L14'>ECX</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L593" class="LineNr">593 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5a"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L15'>EDX</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L594" class="LineNr">594 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5b"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L16'>EBX</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L595" class="LineNr">595 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L17'>ESP</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L596" class="LineNr">596 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L18'>EBP</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L597" class="LineNr">597 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L19'>ESI</a> (pop)"</span><span class="Delimiter">);</span> -<span id="L598" class="LineNr">598 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L20'>EDI</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L591" class="LineNr">591 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L13'>EAX</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L592" class="LineNr">592 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L14'>ECX</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L593" class="LineNr">593 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"5a"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L15'>EDX</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L594" class="LineNr">594 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"5b"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L16'>EBX</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L595" class="LineNr">595 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L17'>ESP</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L596" class="LineNr">596 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L18'>EBP</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L597" class="LineNr">597 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L19'>ESI</a> (pop)"</span><span class="Delimiter">);</span> +<span id="L598" class="LineNr">598 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to <a href='010---vm.cc.html#L20'>EDI</a> (pop)"</span><span class="Delimiter">);</span> <span id="L599" class="LineNr">599 </span> <span id="L600" class="LineNr">600 </span><span class="Delimiter">:(scenario pop_r32)</span> -<span id="L601" class="LineNr">601 </span><span class="Special">% Reg[ESP].u = 0x2000;</span> -<span id="L602" class="LineNr">602 </span><span class="Special">% Mem.push_back(vma(0x2000)); // manually allocate memory</span> -<span id="L603" class="LineNr">603 </span><span class="Special">% write_mem_i32(0x2000, 0x0000000a); // ..before this write</span> +<span id="L601" class="LineNr">601 </span><span class="Special">% Reg[ESP].u = 0x02000000;</span> +<span id="L602" class="LineNr">602 </span><span class="Special">% Mem.push_back(vma(0x02000000)); // manually allocate memory</span> +<span id="L603" class="LineNr">603 </span><span class="Special">% write_mem_i32(0x02000000, 0x0000000a); // ..before this write</span> <span id="L604" class="LineNr">604 </span>== <span class="Constant">0x1</span> <span class="Comment"># code segment</span> <span id="L605" class="LineNr">605 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> <span id="L606" class="LineNr">606 </span> 5b <span class="Comment"># pop stack to EBX</span> @@ -673,7 +673,7 @@ if ('onhashchange' in window) { <span id="L608" class="LineNr">608 </span>0a <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># 0x0a</span> <span id="L609" class="LineNr">609 </span><span class="traceContains">+run: <a href='013direct_addressing.cc.html#L630'>pop</a> into <a href='010---vm.cc.html#L16'>EBX</a></span> <span id="L610" class="LineNr">610 </span><span class="traceContains">+run: popping value 0x0000000a</span> -<span id="L611" class="LineNr">611 </span><span class="traceContains">+run: incrementing <a href='010---vm.cc.html#L17'>ESP</a> to 0x00002004</span> +<span id="L611" class="LineNr">611 </span><span class="traceContains">+run: incrementing <a href='010---vm.cc.html#L17'>ESP</a> to 0x02000004</span> <span id="L612" class="LineNr">612 </span> <span id="L613" class="LineNr">613 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L614" class="LineNr">614 </span><span class="Normal">case</span> <span class="Constant">0x58</span>: @@ -687,16 +687,16 @@ if ('onhashchange' in window) { <span id="L622" class="LineNr">622 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='010---vm.cc.html#L23'>reg</a> = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L623" class="LineNr">623 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"pop into "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L624" class="LineNr">624 </span><span class="CommentedCode">//? cerr << "pop from " << Reg[ESP].u << '\n';</span> -<span id="L625" class="LineNr">625 </span> Reg[reg]<span class="Delimiter">.</span>u = <a href='013direct_addressing.cc.html#L630'>pop</a><span class="Delimiter">();</span> +<span id="L625" class="LineNr">625 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u = <a href='013direct_addressing.cc.html#L630'>pop</a><span class="Delimiter">();</span> <span id="L626" class="LineNr">626 </span><span class="CommentedCode">//? cerr << "=> " << NUM(reg) << ": " << Reg[reg].u << '\n';</span> <span id="L627" class="LineNr">627 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L628" class="LineNr">628 </span><span class="Delimiter">}</span> <span id="L629" class="LineNr">629 </span><span class="Delimiter">:(code)</span> <span id="L630" class="LineNr">630 </span><span class="Normal">uint32_t</span> <a href='013direct_addressing.cc.html#L630'>pop</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L631" class="LineNr">631 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> result = <a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> -<span id="L632" class="LineNr">632 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"popping value 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << result << end<span class="Delimiter">();</span> -<span id="L633" class="LineNr">633 </span> Reg[ESP]<span class="Delimiter">.</span>u += <span class="Constant">4</span><span class="Delimiter">;</span> -<span id="L634" class="LineNr">634 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"incrementing <a href='010---vm.cc.html#L17'>ESP</a> to 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L631" class="LineNr">631 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> result = <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L632" class="LineNr">632 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"popping value 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << result << end<span class="Delimiter">();</span> +<span id="L633" class="LineNr">633 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u += <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L634" class="LineNr">634 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"incrementing <a href='010---vm.cc.html#L17'>ESP</a> to 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> <span id="L635" class="LineNr">635 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span id="L636" class="LineNr">636 </span><span class="Delimiter">}</span> </pre> diff --git a/html/subx/014indirect_addressing.cc.html b/html/subx/014indirect_addressing.cc.html index 483baa73..4b0eb7fc 100644 --- a/html/subx/014indirect_addressing.cc.html +++ b/html/subx/014indirect_addressing.cc.html @@ -82,8 +82,8 @@ if ('onhashchange' in window) { <span id="L18" class="LineNr"> 18 </span><span class="Normal">case</span> <span class="Constant">0</span>: <span class="Comment">// indirect addressing</span> <span id="L19" class="LineNr"> 19 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L20" class="LineNr"> 20 </span> <span class="Normal">default</span>: <span class="Comment">// address in register</span> -<span id="L21" class="LineNr"> 21 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[rm]<span class="Delimiter">.</span>u << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> -<span id="L22" class="LineNr"> 22 </span> addr = Reg[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L21" class="LineNr"> 21 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rm]<span class="Delimiter">.</span>u << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L22" class="LineNr"> 22 </span> addr = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> <span id="L23" class="LineNr"> 23 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L24" class="LineNr"> 24 </span> <span class="Comment">// End Mod 0 Special-cases(addr)</span> <span id="L25" class="LineNr"> 25 </span> <span class="Delimiter">}</span> @@ -92,7 +92,7 @@ if ('onhashchange' in window) { <span id="L28" class="LineNr"> 28 </span><span class="Comment">//:</span> <span id="L29" class="LineNr"> 29 </span> <span id="L30" class="LineNr"> 30 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L31" class="LineNr"> 31 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"03"</span><span class="Delimiter">,</span> <span class="Constant">"add rm32 to r32 (add)"</span><span class="Delimiter">);</span> +<span id="L31" class="LineNr"> 31 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"03"</span><span class="Delimiter">,</span> <span class="Constant">"add rm32 to r32 (add)"</span><span class="Delimiter">);</span> <span id="L32" class="LineNr"> 32 </span> <span id="L33" class="LineNr"> 33 </span><span class="Delimiter">:(scenario add_mem_at_r32_to_r32)</span> <span id="L34" class="LineNr"> 34 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -109,11 +109,11 @@ if ('onhashchange' in window) { <span id="L45" class="LineNr"> 45 </span> <span id="L46" class="LineNr"> 46 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L47" class="LineNr"> 47 </span><span class="Normal">case</span> <span class="Constant">0x03</span>: <span class="Delimiter">{</span> <span class="Comment">// add r/m32 to r32</span> -<span id="L48" class="LineNr"> 48 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L49" class="LineNr"> 49 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L50" class="LineNr"> 50 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"add r/m32 to "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L51" class="LineNr"> 51 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L52" class="LineNr"> 52 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> Reg[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> +<span id="L52" class="LineNr"> 52 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>+<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> <span id="L53" class="LineNr"> 53 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L54" class="LineNr"> 54 </span><span class="Delimiter">}</span> <span id="L55" class="LineNr"> 55 </span> @@ -135,7 +135,7 @@ if ('onhashchange' in window) { <span id="L71" class="LineNr"> 71 </span><span class="Comment">//:</span> <span id="L72" class="LineNr"> 72 </span> <span id="L73" class="LineNr"> 73 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L74" class="LineNr"> 74 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"2b"</span><span class="Delimiter">,</span> <span class="Constant">"subtract rm32 from r32 (sub)"</span><span class="Delimiter">);</span> +<span id="L74" class="LineNr"> 74 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"2b"</span><span class="Delimiter">,</span> <span class="Constant">"subtract rm32 from r32 (sub)"</span><span class="Delimiter">);</span> <span id="L75" class="LineNr"> 75 </span> <span id="L76" class="LineNr"> 76 </span><span class="Delimiter">:(scenario subtract_mem_at_r32_from_r32)</span> <span id="L77" class="LineNr"> 77 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -152,11 +152,11 @@ if ('onhashchange' in window) { <span id="L88" class="LineNr"> 88 </span> <span id="L89" class="LineNr"> 89 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L90" class="LineNr"> 90 </span><span class="Normal">case</span> <span class="Constant">0x2b</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract r/m32 from r32</span> -<span id="L91" class="LineNr"> 91 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L92" class="LineNr"> 92 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L93" class="LineNr"> 93 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract r/m32 from "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L94" class="LineNr"> 94 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L95" class="LineNr"> 95 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>-<span class="Delimiter">,</span> Reg[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> +<span id="L95" class="LineNr"> 95 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>-<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg1]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> <span id="L96" class="LineNr"> 96 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L97" class="LineNr"> 97 </span><span class="Delimiter">}</span> <span id="L98" class="LineNr"> 98 </span> @@ -178,7 +178,7 @@ if ('onhashchange' in window) { <span id="L114" class="LineNr">114 </span><span class="Comment">//:</span> <span id="L115" class="LineNr">115 </span> <span id="L116" class="LineNr">116 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L117" class="LineNr">117 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"23"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise AND of r32 with rm32 (and)"</span><span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"23"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise AND of r32 with rm32 (and)"</span><span class="Delimiter">);</span> <span id="L118" class="LineNr">118 </span> <span id="L119" class="LineNr">119 </span><span class="Delimiter">:(scenario and_mem_at_r32_with_r32)</span> <span id="L120" class="LineNr">120 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -195,11 +195,11 @@ if ('onhashchange' in window) { <span id="L131" class="LineNr">131 </span> <span id="L132" class="LineNr">132 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L133" class="LineNr">133 </span><span class="Normal">case</span> <span class="Constant">0x23</span>: <span class="Delimiter">{</span> <span class="Comment">// and r/m32 with r32</span> -<span id="L134" class="LineNr">134 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L135" class="LineNr">135 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L136" class="LineNr">136 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and r/m32 with "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L137" class="LineNr">137 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L138" class="LineNr">138 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>&<span class="Delimiter">,</span> Reg[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> +<span id="L138" class="LineNr">138 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>&<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> <span id="L139" class="LineNr">139 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L140" class="LineNr">140 </span><span class="Delimiter">}</span> <span id="L141" class="LineNr">141 </span> @@ -221,7 +221,7 @@ if ('onhashchange' in window) { <span id="L157" class="LineNr">157 </span><span class="Comment">//:</span> <span id="L158" class="LineNr">158 </span> <span id="L159" class="LineNr">159 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L160" class="LineNr">160 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"0b"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise OR of r32 with rm32 (or)"</span><span class="Delimiter">);</span> +<span id="L160" class="LineNr">160 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"0b"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise OR of r32 with rm32 (or)"</span><span class="Delimiter">);</span> <span id="L161" class="LineNr">161 </span> <span id="L162" class="LineNr">162 </span><span class="Delimiter">:(scenario or_mem_at_r32_with_r32)</span> <span id="L163" class="LineNr">163 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -238,11 +238,11 @@ if ('onhashchange' in window) { <span id="L174" class="LineNr">174 </span> <span id="L175" class="LineNr">175 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L176" class="LineNr">176 </span><span class="Normal">case</span> <span class="Constant">0x0b</span>: <span class="Delimiter">{</span> <span class="Comment">// or r/m32 with r32</span> -<span id="L177" class="LineNr">177 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L177" class="LineNr">177 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L178" class="LineNr">178 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L179" class="LineNr">179 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or r/m32 with "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L180" class="LineNr">180 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L181" class="LineNr">181 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> Reg[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> +<span id="L181" class="LineNr">181 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> <span id="L182" class="LineNr">182 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L183" class="LineNr">183 </span><span class="Delimiter">}</span> <span id="L184" class="LineNr">184 </span> @@ -264,7 +264,7 @@ if ('onhashchange' in window) { <span id="L200" class="LineNr">200 </span><span class="Comment">//:</span> <span id="L201" class="LineNr">201 </span> <span id="L202" class="LineNr">202 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L203" class="LineNr">203 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"33"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise XOR of r32 with rm32 (xor)"</span><span class="Delimiter">);</span> +<span id="L203" class="LineNr">203 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"33"</span><span class="Delimiter">,</span> <span class="Constant">"r32 = bitwise XOR of r32 with rm32 (xor)"</span><span class="Delimiter">);</span> <span id="L204" class="LineNr">204 </span> <span id="L205" class="LineNr">205 </span><span class="Delimiter">:(scenario xor_mem_at_r32_with_r32)</span> <span id="L206" class="LineNr">206 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -281,11 +281,11 @@ if ('onhashchange' in window) { <span id="L217" class="LineNr">217 </span> <span id="L218" class="LineNr">218 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L219" class="LineNr">219 </span><span class="Normal">case</span> <span class="Constant">0x33</span>: <span class="Delimiter">{</span> <span class="Comment">// xor r/m32 with r32</span> -<span id="L220" class="LineNr">220 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L220" class="LineNr">220 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L221" class="LineNr">221 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L222" class="LineNr">222 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor r/m32 with "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L223" class="LineNr">223 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L224" class="LineNr">224 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> Reg[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> +<span id="L224" class="LineNr">224 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg1]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> *arg2<span class="Delimiter">);</span> <span id="L225" class="LineNr">225 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L226" class="LineNr">226 </span><span class="Delimiter">}</span> <span id="L227" class="LineNr">227 </span> @@ -348,7 +348,7 @@ if ('onhashchange' in window) { <span id="L284" class="LineNr">284 </span><span class="Comment">//:</span> <span id="L285" class="LineNr">285 </span> <span id="L286" class="LineNr">286 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L287" class="LineNr">287 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"3b"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if r32 < rm32 (cmp)"</span><span class="Delimiter">);</span> +<span id="L287" class="LineNr">287 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"3b"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if r32 < rm32 (cmp)"</span><span class="Delimiter">);</span> <span id="L288" class="LineNr">288 </span> <span id="L289" class="LineNr">289 </span><span class="Delimiter">:(scenario compare_r32_with_mem_at_r32_greater)</span> <span id="L290" class="LineNr">290 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -365,10 +365,10 @@ if ('onhashchange' in window) { <span id="L301" class="LineNr">301 </span> <span id="L302" class="LineNr">302 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L303" class="LineNr">303 </span><span class="Normal">case</span> <span class="Constant">0x3b</span>: <span class="Delimiter">{</span> <span class="Comment">// set SF if r32 < r/m32</span> -<span id="L304" class="LineNr">304 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L304" class="LineNr">304 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L305" class="LineNr">305 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> reg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L306" class="LineNr">306 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare r/m32 with "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>reg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L307" class="LineNr">307 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg1 = Reg[reg1]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L307" class="LineNr">307 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg1 = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg1]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> <span id="L308" class="LineNr">308 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L309" class="LineNr">309 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> tmp1 = arg1 - *arg2<span class="Delimiter">;</span> <span id="L310" class="LineNr">310 </span> SF = <span class="Delimiter">(</span>tmp1 < <span class="Constant">0</span><span class="Delimiter">);</span> @@ -421,7 +421,7 @@ if ('onhashchange' in window) { <span id="L357" class="LineNr">357 </span><span class="Comment">//:</span> <span id="L358" class="LineNr">358 </span> <span id="L359" class="LineNr">359 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L360" class="LineNr">360 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8b"</span><span class="Delimiter">,</span> <span class="Constant">"copy rm32 to r32 (mov)"</span><span class="Delimiter">);</span> +<span id="L360" class="LineNr">360 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"8b"</span><span class="Delimiter">,</span> <span class="Constant">"copy rm32 to r32 (mov)"</span><span class="Delimiter">);</span> <span id="L361" class="LineNr">361 </span> <span id="L362" class="LineNr">362 </span><span class="Delimiter">:(scenario copy_mem_at_r32_to_r32)</span> <span id="L363" class="LineNr">363 </span><span class="Special">% Reg[EAX].i = 0x2000;</span> @@ -437,12 +437,12 @@ if ('onhashchange' in window) { <span id="L373" class="LineNr">373 </span> <span id="L374" class="LineNr">374 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L375" class="LineNr">375 </span><span class="Normal">case</span> <span class="Constant">0x8b</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r32 to r/m32</span> -<span id="L376" class="LineNr">376 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L376" class="LineNr">376 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L377" class="LineNr">377 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L378" class="LineNr">378 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy r/m32 to "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L379" class="LineNr">379 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* src = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> -<span id="L380" class="LineNr">380 </span> Reg[rdest]<span class="Delimiter">.</span>i = *src<span class="Delimiter">;</span> -<span id="L381" class="LineNr">381 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << *src << end<span class="Delimiter">();</span> +<span id="L380" class="LineNr">380 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rdest]<span class="Delimiter">.</span>i = *src<span class="Delimiter">;</span> +<span id="L381" class="LineNr">381 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << *src << end<span class="Delimiter">();</span> <span id="L382" class="LineNr">382 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L383" class="LineNr">383 </span><span class="Delimiter">}</span> <span id="L384" class="LineNr">384 </span> @@ -470,7 +470,7 @@ if ('onhashchange' in window) { <span id="L406" class="LineNr">406 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump to r/m32"</span> << end<span class="Delimiter">();</span> <span id="L407" class="LineNr">407 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* arg2 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L408" class="LineNr">408 </span> <a href='010---vm.cc.html#L29'>EIP</a> = *arg2<span class="Delimiter">;</span> -<span id="L409" class="LineNr">409 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L409" class="LineNr">409 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> <span id="L410" class="LineNr">410 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L411" class="LineNr">411 </span><span class="Delimiter">}</span> <span id="L412" class="LineNr">412 </span> @@ -501,7 +501,7 @@ if ('onhashchange' in window) { <span id="L437" class="LineNr">437 </span><span class="SalientComment">//:: pop</span> <span id="L438" class="LineNr">438 </span> <span id="L439" class="LineNr">439 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L440" class="LineNr">440 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to rm32 (pop)"</span><span class="Delimiter">);</span> +<span id="L440" class="LineNr">440 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">"pop top of stack to rm32 (pop)"</span><span class="Delimiter">);</span> <span id="L441" class="LineNr">441 </span> <span id="L442" class="LineNr">442 </span><span class="Delimiter">:(scenario pop_mem_at_r32)</span> <span id="L443" class="LineNr">443 </span><span class="Special">% Reg[EAX].i = 0x60;</span> @@ -519,7 +519,7 @@ if ('onhashchange' in window) { <span id="L455" class="LineNr">455 </span> <span id="L456" class="LineNr">456 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L457" class="LineNr">457 </span><span class="Normal">case</span> <span class="Constant">0x8f</span>: <span class="Delimiter">{</span> <span class="Comment">// pop stack into r/m32</span> -<span id="L458" class="LineNr">458 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L458" class="LineNr">458 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L459" class="LineNr">459 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L460" class="LineNr">460 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L461" class="LineNr">461 </span> <span class="Normal">case</span> <span class="Constant">0</span>: <span class="Delimiter">{</span> @@ -549,7 +549,7 @@ if ('onhashchange' in window) { <span id="L485" class="LineNr">485 </span><span class="Delimiter">:(before "End Mod 0 Special-cases(addr)")</span> <span id="L486" class="LineNr">486 </span><span class="Normal">case</span> <span class="Constant">5</span>: <span class="Comment">// exception: mod 0b00 rm 0b101 => incoming disp32</span> <span id="L487" class="LineNr">487 </span> addr = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L488" class="LineNr">488 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" (disp32)"</span> << end<span class="Delimiter">();</span> +<span id="L488" class="LineNr">488 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" (disp32)"</span> << end<span class="Delimiter">();</span> <span id="L489" class="LineNr">489 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L490" class="LineNr">490 </span> <span id="L491" class="LineNr">491 </span><span class="Comment">//:</span> @@ -572,14 +572,14 @@ if ('onhashchange' in window) { <span id="L508" class="LineNr">508 </span><span class="Normal">case</span> <span class="Constant">1</span>: <span class="Comment">// indirect + disp8 addressing</span> <span id="L509" class="LineNr">509 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L510" class="LineNr">510 </span> <span class="Normal">default</span>: -<span id="L511" class="LineNr">511 </span> addr = Reg[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L512" class="LineNr">512 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L511" class="LineNr">511 </span> addr = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L512" class="LineNr">512 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> <span id="L513" class="LineNr">513 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L514" class="LineNr">514 </span> <span class="Comment">// End Mod 1 Special-cases(addr)</span> <span id="L515" class="LineNr">515 </span> <span class="Delimiter">}</span> <span id="L516" class="LineNr">516 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>addr > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L517" class="LineNr">517 </span> addr += <span class="Normal">static_cast</span><<span class="Normal">int8_t</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> -<span id="L518" class="LineNr">518 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" (after adding disp8)"</span> << end<span class="Delimiter">();</span> +<span id="L517" class="LineNr">517 </span> addr += <span class="Normal">static_cast</span><<span class="Normal">int8_t</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> +<span id="L518" class="LineNr">518 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" (after adding disp8)"</span> << end<span class="Delimiter">();</span> <span id="L519" class="LineNr">519 </span> <span class="Delimiter">}</span> <span id="L520" class="LineNr">520 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L521" class="LineNr">521 </span> @@ -617,14 +617,14 @@ if ('onhashchange' in window) { <span id="L553" class="LineNr">553 </span><span class="Normal">case</span> <span class="Constant">2</span>: <span class="Comment">// indirect + disp32 addressing</span> <span id="L554" class="LineNr">554 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L555" class="LineNr">555 </span> <span class="Normal">default</span>: -<span id="L556" class="LineNr">556 </span> addr = Reg[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L557" class="LineNr">557 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L556" class="LineNr">556 </span> addr = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rm]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L557" class="LineNr">557 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rm<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> <span id="L558" class="LineNr">558 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L559" class="LineNr">559 </span> <span class="Comment">// End Mod 2 Special-cases(addr)</span> <span id="L560" class="LineNr">560 </span> <span class="Delimiter">}</span> <span id="L561" class="LineNr">561 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>addr > <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L562" class="LineNr">562 </span> addr += <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L563" class="LineNr">563 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" (after adding disp32)"</span> << end<span class="Delimiter">();</span> +<span id="L563" class="LineNr">563 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" (after adding disp32)"</span> << end<span class="Delimiter">();</span> <span id="L564" class="LineNr">564 </span> <span class="Delimiter">}</span> <span id="L565" class="LineNr">565 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L566" class="LineNr">566 </span> @@ -645,7 +645,7 @@ if ('onhashchange' in window) { <span id="L581" class="LineNr">581 </span><span class="SalientComment">//:: copy address (lea)</span> <span id="L582" class="LineNr">582 </span> <span id="L583" class="LineNr">583 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L584" class="LineNr">584 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">"copy address in rm32 into r32 (lea)"</span><span class="Delimiter">);</span> +<span id="L584" class="LineNr">584 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">"copy address in rm32 into r32 (lea)"</span><span class="Delimiter">);</span> <span id="L585" class="LineNr">585 </span> <span id="L586" class="LineNr">586 </span><span class="Delimiter">:(scenario copy_address)</span> <span id="L587" class="LineNr">587 </span><span class="Special">% Reg[EAX].u = 0x2000;</span> @@ -658,10 +658,10 @@ if ('onhashchange' in window) { <span id="L594" class="LineNr">594 </span> <span id="L595" class="LineNr">595 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L596" class="LineNr">596 </span><span class="Normal">case</span> <span class="Constant">0x8d</span>: <span class="Delimiter">{</span> <span class="Comment">// copy address of m32 to r32</span> -<span id="L597" class="LineNr">597 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L597" class="LineNr">597 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L598" class="LineNr">598 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> arg1 = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L599" class="LineNr">599 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy address into "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>arg1<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L600" class="LineNr">600 </span> Reg[arg1]<span class="Delimiter">.</span>u = <a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> +<span id="L600" class="LineNr">600 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[arg1]<span class="Delimiter">.</span>u = <a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L601" class="LineNr">601 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L602" class="LineNr">602 </span><span class="Delimiter">}</span> </pre> diff --git a/html/subx/015immediate_addressing.cc.html b/html/subx/015immediate_addressing.cc.html index 9d1d1870..d2d6a059 100644 --- a/html/subx/015immediate_addressing.cc.html +++ b/html/subx/015immediate_addressing.cc.html @@ -65,7 +65,7 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment">//: instructions that (immediately) contain an argument to act with</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"81"</span><span class="Delimiter">,</span> <span class="Constant">"combine rm32 with imm32 based on subop (add/sub/and/or/xor/cmp)"</span><span class="Delimiter">);</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"81"</span><span class="Delimiter">,</span> <span class="Constant">"combine rm32 with imm32 based on subop (add/sub/and/or/xor/cmp)"</span><span class="Delimiter">);</span> <span id="L5" class="LineNr"> 5 </span> <span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(scenario add_imm32_to_r32)</span> <span id="L7" class="LineNr"> 7 </span><span class="Special">% Reg[EBX].i = 1;</span> @@ -82,10 +82,10 @@ if ('onhashchange' in window) { <span id="L18" class="LineNr"> 18 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L19" class="LineNr"> 19 </span><span class="Normal">case</span> <span class="Constant">0x81</span>: <span class="Delimiter">{</span> <span class="Comment">// combine imm32 with r/m32</span> <span id="L20" class="LineNr"> 20 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"combine imm32 with r/m32"</span> << end<span class="Delimiter">();</span> -<span id="L21" class="LineNr"> 21 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L22" class="LineNr"> 22 </span> <span class="Normal">int32_t</span>* arg1 = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L23" class="LineNr"> 23 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L24" class="LineNr"> 24 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm32 is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << end<span class="Delimiter">();</span> +<span id="L24" class="LineNr"> 24 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm32 is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << end<span class="Delimiter">();</span> <span id="L25" class="LineNr"> 25 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> subop = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span class="Comment">// middle 3 'reg opcode' bits</span> <span id="L26" class="LineNr"> 26 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>subop<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L27" class="LineNr"> 27 </span> <span class="Normal">case</span> <span class="Constant">0</span>: @@ -94,7 +94,7 @@ if ('onhashchange' in window) { <span id="L30" class="LineNr"> 30 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L31" class="LineNr"> 31 </span> <span class="Comment">// End Op 81 Subops</span> <span id="L32" class="LineNr"> 32 </span> <span class="Normal">default</span>: -<span id="L33" class="LineNr"> 33 </span> cerr << <span class="Constant">"unrecognized sub-opcode after 81: "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L33" class="LineNr"> 33 </span> cerr << <span class="Constant">"unrecognized sub-opcode after 81: "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>subop<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L34" class="LineNr"> 34 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L35" class="LineNr"> 35 </span> <span class="Delimiter">}</span> <span id="L36" class="LineNr"> 36 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -119,7 +119,7 @@ if ('onhashchange' in window) { <span id="L55" class="LineNr"> 55 </span><span class="SalientComment">//:: subtract</span> <span id="L56" class="LineNr"> 56 </span> <span id="L57" class="LineNr"> 57 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L58" class="LineNr"> 58 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">"subtract imm32 from <a href='010---vm.cc.html#L13'>EAX</a> (sub)"</span><span class="Delimiter">);</span> +<span id="L58" class="LineNr"> 58 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">"subtract imm32 from <a href='010---vm.cc.html#L13'>EAX</a> (sub)"</span><span class="Delimiter">);</span> <span id="L59" class="LineNr"> 59 </span> <span id="L60" class="LineNr"> 60 </span><span class="Delimiter">:(scenario subtract_imm32_from_eax)</span> <span id="L61" class="LineNr"> 61 </span><span class="Special">% Reg[EAX].i = 0x0d0c0baa;</span> @@ -132,8 +132,8 @@ if ('onhashchange' in window) { <span id="L68" class="LineNr"> 68 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L69" class="LineNr"> 69 </span><span class="Normal">case</span> <span class="Constant">0x2d</span>: <span class="Delimiter">{</span> <span class="Comment">// subtract imm32 from EAX</span> <span id="L70" class="LineNr"> 70 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L71" class="LineNr"> 71 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << <span class="Constant">" from EAX"</span> << end<span class="Delimiter">();</span> -<span id="L72" class="LineNr"> 72 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>-<span class="Delimiter">,</span> Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> +<span id="L71" class="LineNr"> 71 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"subtract imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << <span class="Constant">" from EAX"</span> << end<span class="Delimiter">();</span> +<span id="L72" class="LineNr"> 72 </span> <a href='010---vm.cc.html#L91'>BINARY_ARITHMETIC_OP</a><span class="Delimiter">(</span>-<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> <span id="L73" class="LineNr"> 73 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L74" class="LineNr"> 74 </span><span class="Delimiter">}</span> <span id="L75" class="LineNr"> 75 </span> @@ -177,7 +177,7 @@ if ('onhashchange' in window) { <span id="L113" class="LineNr">113 </span><span class="SalientComment">//:: and</span> <span id="L114" class="LineNr">114 </span> <span id="L115" class="LineNr">115 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L116" class="LineNr">116 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"25"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise AND of imm32 with <a href='010---vm.cc.html#L13'>EAX</a> (and)"</span><span class="Delimiter">);</span> +<span id="L116" class="LineNr">116 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"25"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise AND of imm32 with <a href='010---vm.cc.html#L13'>EAX</a> (and)"</span><span class="Delimiter">);</span> <span id="L117" class="LineNr">117 </span> <span id="L118" class="LineNr">118 </span><span class="Delimiter">:(scenario and_imm32_with_eax)</span> <span id="L119" class="LineNr">119 </span><span class="Special">% Reg[EAX].i = 0xff;</span> @@ -190,8 +190,8 @@ if ('onhashchange' in window) { <span id="L126" class="LineNr">126 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L127" class="LineNr">127 </span><span class="Normal">case</span> <span class="Constant">0x25</span>: <span class="Delimiter">{</span> <span class="Comment">// and imm32 with EAX</span> <span id="L128" class="LineNr">128 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L129" class="LineNr">129 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> -<span id="L130" class="LineNr">130 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>&<span class="Delimiter">,</span> Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"and imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> +<span id="L130" class="LineNr">130 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>&<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> <span id="L131" class="LineNr">131 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L132" class="LineNr">132 </span><span class="Delimiter">}</span> <span id="L133" class="LineNr">133 </span> @@ -235,7 +235,7 @@ if ('onhashchange' in window) { <span id="L171" class="LineNr">171 </span><span class="SalientComment">//:: or</span> <span id="L172" class="LineNr">172 </span> <span id="L173" class="LineNr">173 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L174" class="LineNr">174 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"0d"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise OR of imm32 with <a href='010---vm.cc.html#L13'>EAX</a> (or)"</span><span class="Delimiter">);</span> +<span id="L174" class="LineNr">174 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"0d"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise OR of imm32 with <a href='010---vm.cc.html#L13'>EAX</a> (or)"</span><span class="Delimiter">);</span> <span id="L175" class="LineNr">175 </span> <span id="L176" class="LineNr">176 </span><span class="Delimiter">:(scenario or_imm32_with_eax)</span> <span id="L177" class="LineNr">177 </span><span class="Special">% Reg[EAX].i = 0xd0c0b0a0;</span> @@ -248,8 +248,8 @@ if ('onhashchange' in window) { <span id="L184" class="LineNr">184 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L185" class="LineNr">185 </span><span class="Normal">case</span> <span class="Constant">0x0d</span>: <span class="Delimiter">{</span> <span class="Comment">// or imm32 with EAX</span> <span id="L186" class="LineNr">186 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L187" class="LineNr">187 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> -<span id="L188" class="LineNr">188 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> +<span id="L187" class="LineNr">187 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"or imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> +<span id="L188" class="LineNr">188 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>|<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> <span id="L189" class="LineNr">189 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L190" class="LineNr">190 </span><span class="Delimiter">}</span> <span id="L191" class="LineNr">191 </span> @@ -291,7 +291,7 @@ if ('onhashchange' in window) { <span id="L227" class="LineNr">227 </span><span class="SalientComment">//:: xor</span> <span id="L228" class="LineNr">228 </span> <span id="L229" class="LineNr">229 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L230" class="LineNr">230 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"35"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise XOR of imm32 with <a href='010---vm.cc.html#L13'>EAX</a> (xor)"</span><span class="Delimiter">);</span> +<span id="L230" class="LineNr">230 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"35"</span><span class="Delimiter">,</span> <span class="Constant">"EAX = bitwise XOR of imm32 with <a href='010---vm.cc.html#L13'>EAX</a> (xor)"</span><span class="Delimiter">);</span> <span id="L231" class="LineNr">231 </span> <span id="L232" class="LineNr">232 </span><span class="Delimiter">:(scenario xor_imm32_with_eax)</span> <span id="L233" class="LineNr">233 </span><span class="Special">% Reg[EAX].i = 0xddccb0a0;</span> @@ -304,8 +304,8 @@ if ('onhashchange' in window) { <span id="L240" class="LineNr">240 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L241" class="LineNr">241 </span><span class="Normal">case</span> <span class="Constant">0x35</span>: <span class="Delimiter">{</span> <span class="Comment">// xor imm32 with EAX</span> <span id="L242" class="LineNr">242 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> -<span id="L244" class="LineNr">244 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>^<span class="Delimiter">,</span> Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> +<span id="L243" class="LineNr">243 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"xor imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << <span class="Constant">" with EAX"</span> << end<span class="Delimiter">();</span> +<span id="L244" class="LineNr">244 </span> <a href='010---vm.cc.html#L103'>BINARY_BITWISE_OP</a><span class="Delimiter">(</span>^<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">,</span> arg2<span class="Delimiter">);</span> <span id="L245" class="LineNr">245 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L246" class="LineNr">246 </span><span class="Delimiter">}</span> <span id="L247" class="LineNr">247 </span> @@ -347,7 +347,7 @@ if ('onhashchange' in window) { <span id="L283" class="LineNr">283 </span><span class="SalientComment">//:: compare (cmp)</span> <span id="L284" class="LineNr">284 </span> <span id="L285" class="LineNr">285 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L286" class="LineNr">286 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"3d"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if <a href='010---vm.cc.html#L13'>EAX</a> < imm32 (cmp)"</span><span class="Delimiter">);</span> +<span id="L286" class="LineNr">286 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"3d"</span><span class="Delimiter">,</span> <span class="Constant">"compare: set SF if <a href='010---vm.cc.html#L13'>EAX</a> < imm32 (cmp)"</span><span class="Delimiter">);</span> <span id="L287" class="LineNr">287 </span> <span id="L288" class="LineNr">288 </span><span class="Delimiter">:(scenario compare_imm32_with_eax_greater)</span> <span id="L289" class="LineNr">289 </span><span class="Special">% Reg[EAX].i = 0x0d0c0b0a;</span> @@ -359,9 +359,9 @@ if ('onhashchange' in window) { <span id="L295" class="LineNr">295 </span> <span id="L296" class="LineNr">296 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L297" class="LineNr">297 </span><span class="Normal">case</span> <span class="Constant">0x3d</span>: <span class="Delimiter">{</span> <span class="Comment">// compare EAX with imm32</span> -<span id="L298" class="LineNr">298 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg1 = Reg[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> +<span id="L298" class="LineNr">298 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg1 = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i<span class="Delimiter">;</span> <span id="L299" class="LineNr">299 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> arg2 = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L300" class="LineNr">300 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare <a href='010---vm.cc.html#L13'>EAX</a> and imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << arg2 << end<span class="Delimiter">();</span> +<span id="L300" class="LineNr">300 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"compare <a href='010---vm.cc.html#L13'>EAX</a> and imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << arg2 << end<span class="Delimiter">();</span> <span id="L301" class="LineNr">301 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> tmp1 = arg1 - arg2<span class="Delimiter">;</span> <span id="L302" class="LineNr">302 </span> SF = <span class="Delimiter">(</span>tmp1 < <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L303" class="LineNr">303 </span> ZF = <span class="Delimiter">(</span>tmp1 == <span class="Constant">0</span><span class="Delimiter">);</span> @@ -477,14 +477,14 @@ if ('onhashchange' in window) { <span id="L413" class="LineNr">413 </span><span class="SalientComment">//:: copy (mov)</span> <span id="L414" class="LineNr">414 </span> <span id="L415" class="LineNr">415 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L416" class="LineNr">416 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"b8"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L13'>EAX</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L417" class="LineNr">417 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"b9"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L14'>ECX</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L418" class="LineNr">418 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L15'>EDX</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L419" class="LineNr">419 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bb"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L16'>EBX</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L420" class="LineNr">420 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bc"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L17'>ESP</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L421" class="LineNr">421 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bd"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L18'>EBP</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L422" class="LineNr">422 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"be"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L19'>ESI</a> (mov)"</span><span class="Delimiter">);</span> -<span id="L423" class="LineNr">423 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"bf"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L20'>EDI</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L416" class="LineNr">416 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"b8"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L13'>EAX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L417" class="LineNr">417 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"b9"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L14'>ECX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L418" class="LineNr">418 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L15'>EDX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L419" class="LineNr">419 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"bb"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L16'>EBX</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L420" class="LineNr">420 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"bc"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L17'>ESP</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L421" class="LineNr">421 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"bd"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L18'>EBP</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L422" class="LineNr">422 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"be"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L19'>ESI</a> (mov)"</span><span class="Delimiter">);</span> +<span id="L423" class="LineNr">423 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"bf"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to <a href='010---vm.cc.html#L20'>EDI</a> (mov)"</span><span class="Delimiter">);</span> <span id="L424" class="LineNr">424 </span> <span id="L425" class="LineNr">425 </span><span class="Delimiter">:(scenario copy_imm32_to_r32)</span> <span id="L426" class="LineNr">426 </span>== <span class="Constant">0x1</span> @@ -503,15 +503,15 @@ if ('onhashchange' in window) { <span id="L439" class="LineNr">439 </span><span class="Normal">case</span> <span class="Constant">0xbf</span>: <span class="Delimiter">{</span> <span class="Comment">// copy imm32 to r32</span> <span id="L440" class="LineNr">440 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = op & <span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L441" class="LineNr">441 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> src = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L442" class="LineNr">442 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << src << <span class="Constant">" to "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L443" class="LineNr">443 </span> Reg[rdest]<span class="Delimiter">.</span>i = src<span class="Delimiter">;</span> +<span id="L442" class="LineNr">442 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << src << <span class="Constant">" to "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L443" class="LineNr">443 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rdest]<span class="Delimiter">.</span>i = src<span class="Delimiter">;</span> <span id="L444" class="LineNr">444 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L445" class="LineNr">445 </span><span class="Delimiter">}</span> <span id="L446" class="LineNr">446 </span> <span id="L447" class="LineNr">447 </span><span class="Comment">//:</span> <span id="L448" class="LineNr">448 </span> <span id="L449" class="LineNr">449 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L450" class="LineNr">450 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"c7"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to rm32 (mov)"</span><span class="Delimiter">);</span> +<span id="L450" class="LineNr">450 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"c7"</span><span class="Delimiter">,</span> <span class="Constant">"copy imm32 to rm32 (mov)"</span><span class="Delimiter">);</span> <span id="L451" class="LineNr">451 </span> <span id="L452" class="LineNr">452 </span><span class="Delimiter">:(scenario copy_imm32_to_mem_at_r32)</span> <span id="L453" class="LineNr">453 </span><span class="Special">% Reg[EBX].i = 0x60;</span> @@ -525,11 +525,11 @@ if ('onhashchange' in window) { <span id="L461" class="LineNr">461 </span> <span id="L462" class="LineNr">462 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L463" class="LineNr">463 </span><span class="Normal">case</span> <span class="Constant">0xc7</span>: <span class="Delimiter">{</span> <span class="Comment">// copy imm32 to r32</span> -<span id="L464" class="LineNr">464 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L464" class="LineNr">464 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L465" class="LineNr">465 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy imm32 to r/m32"</span> << end<span class="Delimiter">();</span> <span id="L466" class="LineNr">466 </span> <span class="Normal">int32_t</span>* dest = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L467" class="LineNr">467 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> src = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L468" class="LineNr">468 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm32 is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << src << end<span class="Delimiter">();</span> +<span id="L468" class="LineNr">468 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"imm32 is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << src << end<span class="Delimiter">();</span> <span id="L469" class="LineNr">469 </span> *dest = src<span class="Delimiter">;</span> <span id="L470" class="LineNr">470 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L471" class="LineNr">471 </span><span class="Delimiter">}</span> @@ -537,7 +537,7 @@ if ('onhashchange' in window) { <span id="L473" class="LineNr">473 </span><span class="SalientComment">//:: push</span> <span id="L474" class="LineNr">474 </span> <span id="L475" class="LineNr">475 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L476" class="LineNr">476 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"68"</span><span class="Delimiter">,</span> <span class="Constant">"push imm32 to stack (push)"</span><span class="Delimiter">);</span> +<span id="L476" class="LineNr">476 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"68"</span><span class="Delimiter">,</span> <span class="Constant">"push imm32 to stack (push)"</span><span class="Delimiter">);</span> <span id="L477" class="LineNr">477 </span> <span id="L478" class="LineNr">478 </span><span class="Delimiter">:(scenario push_imm32)</span> <span id="L479" class="LineNr">479 </span><span class="Special">% Reg[ESP].u = 0x14;</span> @@ -551,11 +551,11 @@ if ('onhashchange' in window) { <span id="L487" class="LineNr">487 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L488" class="LineNr">488 </span><span class="Normal">case</span> <span class="Constant">0x68</span>: <span class="Delimiter">{</span> <span id="L489" class="LineNr">489 </span> <span class="Normal">const</span> <span class="Normal">uint32_t</span> val = <span class="Normal">static_cast</span><<span class="Normal">uint32_t</span>><span class="Delimiter">(</span><a href='011run.cc.html#L343'>next32</a><span class="Delimiter">());</span> -<span id="L490" class="LineNr">490 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << val << end<span class="Delimiter">();</span> +<span id="L490" class="LineNr">490 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"push imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << val << end<span class="Delimiter">();</span> <span id="L491" class="LineNr">491 </span><span class="CommentedCode">//? cerr << "push: " << val << " => " << Reg[ESP].u << '\n';</span> <span id="L492" class="LineNr">492 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span>val<span class="Delimiter">);</span> -<span id="L493" class="LineNr">493 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ESP is now 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L494" class="LineNr">494 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"contents at <a href='010---vm.cc.html#L17'>ESP</a>: 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>Reg[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L493" class="LineNr">493 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"ESP is now 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L494" class="LineNr">494 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"contents at <a href='010---vm.cc.html#L17'>ESP</a>: 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ESP]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L495" class="LineNr">495 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L496" class="LineNr">496 </span><span class="Delimiter">}</span> </pre> diff --git a/html/subx/016index_addressing.cc.html b/html/subx/016index_addressing.cc.html index 6d7e3151..74d09f0d 100644 --- a/html/subx/016index_addressing.cc.html +++ b/html/subx/016index_addressing.cc.html @@ -83,27 +83,27 @@ if ('onhashchange' in window) { <span id="L21" class="LineNr"> 21 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L22" class="LineNr"> 22 </span><span class="Delimiter">:(code)</span> <span id="L23" class="LineNr"> 23 </span><span class="Normal">uint32_t</span> <a href='016index_addressing.cc.html#L23'>effective_address_from_sib</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> mod<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L24" class="LineNr"> 24 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> sib = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> sib = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L25" class="LineNr"> 25 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> base = sib&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L26" class="LineNr"> 26 </span> <span class="Normal">uint32_t</span> addr = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L27" class="LineNr"> 27 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>base != <a href='010---vm.cc.html#L18'>EBP</a> || mod != <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L28" class="LineNr"> 28 </span> addr = Reg[base]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L29" class="LineNr"> 29 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>base<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> addr = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[base]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" ("</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>base<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> <span id="L30" class="LineNr"> 30 </span> <span class="Delimiter">}</span> <span id="L31" class="LineNr"> 31 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> <span id="L32" class="LineNr"> 32 </span> <span class="Comment">// base == EBP && mod == 0</span> <span id="L33" class="LineNr"> 33 </span> addr = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> <span class="Comment">// ignore base</span> -<span id="L34" class="LineNr"> 34 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" (disp32)"</span> << end<span class="Delimiter">();</span> +<span id="L34" class="LineNr"> 34 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is initially 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" (disp32)"</span> << end<span class="Delimiter">();</span> <span id="L35" class="LineNr"> 35 </span> <span class="Delimiter">}</span> <span id="L36" class="LineNr"> 36 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> index = <span class="Delimiter">(</span>sib>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L37" class="LineNr"> 37 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>index == <a href='010---vm.cc.html#L17'>ESP</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L38" class="LineNr"> 38 </span> <span class="Comment">// ignore index and scale</span> -<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> +<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << end<span class="Delimiter">();</span> <span id="L40" class="LineNr"> 40 </span> <span class="Delimiter">}</span> <span id="L41" class="LineNr"> 41 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> <span id="L42" class="LineNr"> 42 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> scale = <span class="Delimiter">(</span><span class="Constant">1</span> << <span class="Delimiter">(</span>sib>><span class="Constant">6</span><span class="Delimiter">));</span> -<span id="L43" class="LineNr"> 43 </span> addr += Reg[index]<span class="Delimiter">.</span>i*scale<span class="Delimiter">;</span> <span class="Comment">// treat index register as signed. Maybe base as well? But we'll always ensure it's non-negative.</span> -<span id="L44" class="LineNr"> 44 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << addr << <span class="Constant">" (after adding "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>index<span class="Delimiter">)</span> << <span class="Constant">"*"</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>scale<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> +<span id="L43" class="LineNr"> 43 </span> addr += <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[index]<span class="Delimiter">.</span>i*scale<span class="Delimiter">;</span> <span class="Comment">// treat index register as signed. Maybe base as well? But we'll always ensure it's non-negative.</span> +<span id="L44" class="LineNr"> 44 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"effective address is 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << addr << <span class="Constant">" (after adding "</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>index<span class="Delimiter">)</span> << <span class="Constant">"*"</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>scale<span class="Delimiter">)</span> << <span class="Constant">")"</span> << end<span class="Delimiter">();</span> <span id="L45" class="LineNr"> 45 </span> <span class="Delimiter">}</span> <span id="L46" class="LineNr"> 46 </span> <span class="Identifier">return</span> addr<span class="Delimiter">;</span> <span id="L47" class="LineNr"> 47 </span><span class="Delimiter">}</span> diff --git a/html/subx/017jump_disp8.cc.html b/html/subx/017jump_disp8.cc.html index efe6fb15..358100f2 100644 --- a/html/subx/017jump_disp8.cc.html +++ b/html/subx/017jump_disp8.cc.html @@ -66,7 +66,7 @@ if ('onhashchange' in window) { <span id="L3" class="LineNr"> 3 </span><span class="SalientComment">//:: jump</span> <span id="L4" class="LineNr"> 4 </span> <span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"eb"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away (jmp)"</span><span class="Delimiter">);</span> +<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"eb"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away (jmp)"</span><span class="Delimiter">);</span> <span id="L7" class="LineNr"> 7 </span> <span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(scenario jump_rel8)</span> <span id="L9" class="LineNr"> 9 </span>== <span class="Constant">0x1</span> @@ -81,8 +81,8 @@ if ('onhashchange' in window) { <span id="L18" class="LineNr"> 18 </span> <span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L20" class="LineNr"> 20 </span><span class="Normal">case</span> <span class="Constant">0xeb</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8</span> -<span id="L21" class="LineNr"> 21 </span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> -<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> +<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L23" class="LineNr"> 23 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L24" class="LineNr"> 24 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L25" class="LineNr"> 25 </span><span class="Delimiter">}</span> @@ -90,7 +90,7 @@ if ('onhashchange' in window) { <span id="L27" class="LineNr"> 27 </span><span class="SalientComment">//:: jump if equal/zero</span> <span id="L28" class="LineNr"> 28 </span> <span id="L29" class="LineNr"> 29 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L30" class="LineNr"> 30 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"74"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if equal, if ZF is set (jcc/jz/je)"</span><span class="Delimiter">);</span> +<span id="L30" class="LineNr"> 30 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"74"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if equal, if ZF is set (jcc/jz/je)"</span><span class="Delimiter">);</span> <span id="L31" class="LineNr"> 31 </span> <span id="L32" class="LineNr"> 32 </span><span class="Delimiter">:(scenario je_rel8_success)</span> <span id="L33" class="LineNr"> 33 </span><span class="Special">% ZF = true;</span> @@ -106,9 +106,9 @@ if ('onhashchange' in window) { <span id="L43" class="LineNr"> 43 </span> <span id="L44" class="LineNr"> 44 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L45" class="LineNr"> 45 </span><span class="Normal">case</span> <span class="Constant">0x74</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8 if ZF</span> -<span id="L46" class="LineNr"> 46 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> <span id="L47" class="LineNr"> 47 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L48" class="LineNr"> 48 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L49" class="LineNr"> 49 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L50" class="LineNr"> 50 </span> <span class="Delimiter">}</span> <span id="L51" class="LineNr"> 51 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -129,7 +129,7 @@ if ('onhashchange' in window) { <span id="L66" class="LineNr"> 66 </span><span class="SalientComment">//:: jump if not equal/not zero</span> <span id="L67" class="LineNr"> 67 </span> <span id="L68" class="LineNr"> 68 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L69" class="LineNr"> 69 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"75"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if not equal, if ZF is not set (jcc/jnz/jne)"</span><span class="Delimiter">);</span> +<span id="L69" class="LineNr"> 69 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"75"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if not equal, if ZF is not set (jcc/jnz/jne)"</span><span class="Delimiter">);</span> <span id="L70" class="LineNr"> 70 </span> <span id="L71" class="LineNr"> 71 </span><span class="Delimiter">:(scenario jne_rel8_success)</span> <span id="L72" class="LineNr"> 72 </span><span class="Special">% ZF = false;</span> @@ -145,9 +145,9 @@ if ('onhashchange' in window) { <span id="L82" class="LineNr"> 82 </span> <span id="L83" class="LineNr"> 83 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L84" class="LineNr"> 84 </span><span class="Normal">case</span> <span class="Constant">0x75</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8 unless ZF</span> -<span id="L85" class="LineNr"> 85 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> <span id="L86" class="LineNr"> 86 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L87" class="LineNr"> 87 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L87" class="LineNr"> 87 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L88" class="LineNr"> 88 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L89" class="LineNr"> 89 </span> <span class="Delimiter">}</span> <span id="L90" class="LineNr"> 90 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -168,7 +168,7 @@ if ('onhashchange' in window) { <span id="L105" class="LineNr">105 </span><span class="SalientComment">//:: jump if greater</span> <span id="L106" class="LineNr">106 </span> <span id="L107" class="LineNr">107 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L108" class="LineNr">108 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7f"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater, if ZF is unset and SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jg/jnle)"</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"7f"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater, if ZF is unset and SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jg/jnle)"</span><span class="Delimiter">);</span> <span id="L109" class="LineNr">109 </span> <span id="L110" class="LineNr">110 </span><span class="Delimiter">:(scenario jg_rel8_success)</span> <span id="L111" class="LineNr">111 </span><span class="Special">% ZF = false;</span> @@ -186,9 +186,9 @@ if ('onhashchange' in window) { <span id="L123" class="LineNr">123 </span> <span id="L124" class="LineNr">124 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L125" class="LineNr">125 </span><span class="Normal">case</span> <span class="Constant">0x7f</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8 if !SF and !ZF</span> -<span id="L126" class="LineNr">126 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> <span id="L127" class="LineNr">127 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF && SF == <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L128" class="LineNr">128 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L128" class="LineNr">128 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L129" class="LineNr">129 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L130" class="LineNr">130 </span> <span class="Delimiter">}</span> <span id="L131" class="LineNr">131 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -211,7 +211,7 @@ if ('onhashchange' in window) { <span id="L148" class="LineNr">148 </span><span class="SalientComment">//:: jump if greater or equal</span> <span id="L149" class="LineNr">149 </span> <span id="L150" class="LineNr">150 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L151" class="LineNr">151 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7d"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater or equal, if SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jge/jnl)"</span><span class="Delimiter">);</span> +<span id="L151" class="LineNr">151 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"7d"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if greater or equal, if SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jge/jnl)"</span><span class="Delimiter">);</span> <span id="L152" class="LineNr">152 </span> <span id="L153" class="LineNr">153 </span><span class="Delimiter">:(scenario jge_rel8_success)</span> <span id="L154" class="LineNr">154 </span><span class="Special">% SF = false;</span> @@ -228,9 +228,9 @@ if ('onhashchange' in window) { <span id="L165" class="LineNr">165 </span> <span id="L166" class="LineNr">166 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L167" class="LineNr">167 </span><span class="Normal">case</span> <span class="Constant">0x7d</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8 if !SF</span> -<span id="L168" class="LineNr">168 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> +<span id="L168" class="LineNr">168 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> <span id="L169" class="LineNr">169 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF == <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L170" class="LineNr">170 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L170" class="LineNr">170 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L171" class="LineNr">171 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L172" class="LineNr">172 </span> <span class="Delimiter">}</span> <span id="L173" class="LineNr">173 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -252,7 +252,7 @@ if ('onhashchange' in window) { <span id="L189" class="LineNr">189 </span><span class="SalientComment">//:: jump if lesser</span> <span id="L190" class="LineNr">190 </span> <span id="L191" class="LineNr">191 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L192" class="LineNr">192 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7c"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser, if SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jl/jnge)"</span><span class="Delimiter">);</span> +<span id="L192" class="LineNr">192 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"7c"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser, if SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jl/jnge)"</span><span class="Delimiter">);</span> <span id="L193" class="LineNr">193 </span> <span id="L194" class="LineNr">194 </span><span class="Delimiter">:(scenario jl_rel8_success)</span> <span id="L195" class="LineNr">195 </span><span class="Special">% ZF = false;</span> @@ -270,9 +270,9 @@ if ('onhashchange' in window) { <span id="L207" class="LineNr">207 </span> <span id="L208" class="LineNr">208 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L209" class="LineNr">209 </span><span class="Normal">case</span> <span class="Constant">0x7c</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8 if SF and !ZF</span> -<span id="L210" class="LineNr">210 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> +<span id="L210" class="LineNr">210 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> <span id="L211" class="LineNr">211 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF != <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L212" class="LineNr">212 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L212" class="LineNr">212 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L213" class="LineNr">213 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L214" class="LineNr">214 </span> <span class="Delimiter">}</span> <span id="L215" class="LineNr">215 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> @@ -295,7 +295,7 @@ if ('onhashchange' in window) { <span id="L232" class="LineNr">232 </span><span class="SalientComment">//:: jump if lesser or equal</span> <span id="L233" class="LineNr">233 </span> <span id="L234" class="LineNr">234 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L235" class="LineNr">235 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"7e"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser or equal, if ZF is set or SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jle/jng)"</span><span class="Delimiter">);</span> +<span id="L235" class="LineNr">235 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"7e"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp8 bytes away if lesser or equal, if ZF is set or SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jle/jng)"</span><span class="Delimiter">);</span> <span id="L236" class="LineNr">236 </span> <span id="L237" class="LineNr">237 </span><span class="Delimiter">:(scenario jle_rel8_equal)</span> <span id="L238" class="LineNr">238 </span><span class="Special">% ZF = true;</span> @@ -327,9 +327,9 @@ if ('onhashchange' in window) { <span id="L264" class="LineNr">264 </span> <span id="L265" class="LineNr">265 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L266" class="LineNr">266 </span><span class="Normal">case</span> <span class="Constant">0x7e</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8 if SF or ZF</span> -<span id="L267" class="LineNr">267 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">());</span> +<span id="L267" class="LineNr">267 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <span class="Normal">static_cast</span><<span class="Normal">int</span>><span class="Delimiter">(</span><a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">());</span> <span id="L268" class="LineNr">268 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>ZF || SF != <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L269" class="LineNr">269 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L269" class="LineNr">269 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L270" class="LineNr">270 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> <span id="L271" class="LineNr">271 </span> <span class="Delimiter">}</span> <span id="L272" class="LineNr">272 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> diff --git a/html/subx/018jump_disp16.cc.html b/html/subx/018jump_disp16.cc.html deleted file mode 100644 index 8ed26307..00000000 --- a/html/subx/018jump_disp16.cc.html +++ /dev/null @@ -1,360 +0,0 @@ -<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> -<html> -<head> -<meta http-equiv="content-type" content="text/html; charset=UTF-8"> -<title>Mu - subx/018jump_disp16.cc</title> -<meta name="Generator" content="Vim/8.0"> -<meta name="plugin-version" content="vim7.4_v2"> -<meta name="syntax" content="cpp"> -<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> -<meta name="colorscheme" content="minimal"> -<style type="text/css"> -<!-- -pre { white-space: pre-wrap; font-family: monospace; color: #aaaaaa; background-color: #080808; } -body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } -a { color:#eeeeee; text-decoration: none; } -a:hover { text-decoration: underline; } -* { font-size: 12pt; font-size: 1em; } -.traceAbsent { color: #c00000; } -.traceContains { color: #008000; } -.PreProc { color: #800080; } -.LineNr { color: #444444; } -.Constant { color: #00a0a0; } -.Delimiter { color: #800080; } -.Special { color: #c00000; } -.Identifier { color: #c0a020; } -.Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } -.Comment { color: #9090ff; } -.Comment a { color:#0000ee; text-decoration:underline; } -.SalientComment { color: #00ffff; } ---> -</style> - -<script type='text/javascript'> -<!-- - -/* function to open any folds containing a jumped-to line before jumping to it */ -function JumpToLine() -{ - var lineNum; - lineNum = window.location.hash; - lineNum = lineNum.substr(1); /* strip off '#' */ - - if (lineNum.indexOf('L') == -1) { - lineNum = 'L'+lineNum; - } - lineElem = document.getElementById(lineNum); - /* Always jump to new location even if the line was hidden inside a fold, or - * we corrected the raw number to a line ID. - */ - if (lineElem) { - lineElem.scrollIntoView(true); - } - return true; -} -if ('onhashchange' in window) { - window.onhashchange = JumpToLine; -} - ---> -</script> -</head> -<body onload='JumpToLine();'> -<pre id='vimCodeElement'> -<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: jump to 16-bit offset</span> -<span id="L2" class="LineNr"> 2 </span> -<span id="L3" class="LineNr"> 3 </span><span class="SalientComment">//:: jump</span> -<span id="L4" class="LineNr"> 4 </span> -<span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"e9"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away (jmp)"</span><span class="Delimiter">);</span> -<span id="L7" class="LineNr"> 7 </span> -<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(scenario jump_rel16)</span> -<span id="L9" class="LineNr"> 9 </span>== <span class="Constant">0x1</span> -<span id="L10" class="LineNr"> 10 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L11" class="LineNr"> 11 </span> e9 <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L12" class="LineNr"> 12 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L13" class="LineNr"> 13 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L14" class="LineNr"> 14 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L15" class="LineNr"> 15 </span><span class="traceContains">+run: jump 5</span> -<span id="L16" class="LineNr"> 16 </span><span class="traceContains">+run: inst: 0x00000009</span> -<span id="L17" class="LineNr"> 17 </span><span class="traceAbsent">-run: inst: 0x00000003</span> -<span id="L18" class="LineNr"> 18 </span> -<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> -<span id="L20" class="LineNr"> 20 </span><span class="Normal">case</span> <span class="Constant">0xe9</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel8</span> -<span id="L21" class="LineNr"> 21 </span> <span class="Normal">const</span> <span class="Normal">int16_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> -<span id="L23" class="LineNr"> 23 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L24" class="LineNr"> 24 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">}</span> -<span id="L26" class="LineNr"> 26 </span><span class="Delimiter">:(code)</span> -<span id="L27" class="LineNr"> 27 </span><span class="Normal">int16_t</span> <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L28" class="LineNr"> 28 </span> <span class="Normal">int16_t</span> result = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> -<span id="L29" class="LineNr"> 29 </span> result |= <span class="Delimiter">(</span><a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">()</span><<<span class="Constant">8</span><span class="Delimiter">);</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L31" class="LineNr"> 31 </span><span class="Delimiter">}</span> -<span id="L32" class="LineNr"> 32 </span> -<span id="L33" class="LineNr"> 33 </span><span class="SalientComment">//:: jump if equal/zero</span> -<span id="L34" class="LineNr"> 34 </span> -<span id="L35" class="LineNr"> 35 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L36" class="LineNr"> 36 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"84"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away if equal, if ZF is set (jcc/jz/je)"</span><span class="Delimiter">);</span> -<span id="L37" class="LineNr"> 37 </span> -<span id="L38" class="LineNr"> 38 </span><span class="Delimiter">:(scenario je_rel16_success)</span> -<span id="L39" class="LineNr"> 39 </span><span class="Special">% ZF = true;</span> -<span id="L40" class="LineNr"> 40 </span>== <span class="Constant">0x1</span> -<span id="L41" class="LineNr"> 41 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L42" class="LineNr"> 42 </span> <span class="Constant">0f</span> <span class="Constant">84</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L43" class="LineNr"> 43 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L44" class="LineNr"> 44 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L45" class="LineNr"> 45 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L46" class="LineNr"> 46 </span><span class="traceContains">+run: jump 5</span> -<span id="L47" class="LineNr"> 47 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L48" class="LineNr"> 48 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L49" class="LineNr"> 49 </span> -<span id="L50" class="LineNr"> 50 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> -<span id="L51" class="LineNr"> 51 </span><span class="Normal">case</span> <span class="Constant">0x84</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel16 if ZF</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L55" class="LineNr"> 55 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Delimiter">}</span> -<span id="L57" class="LineNr"> 57 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L58" class="LineNr"> 58 </span><span class="Delimiter">}</span> -<span id="L59" class="LineNr"> 59 </span> -<span id="L60" class="LineNr"> 60 </span><span class="Delimiter">:(scenario je_rel16_fail)</span> -<span id="L61" class="LineNr"> 61 </span><span class="Special">% ZF = false;</span> -<span id="L62" class="LineNr"> 62 </span>== <span class="Constant">0x1</span> -<span id="L63" class="LineNr"> 63 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Constant">0f</span> <span class="Constant">84</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L65" class="LineNr"> 65 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L66" class="LineNr"> 66 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L67" class="LineNr"> 67 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L68" class="LineNr"> 68 </span><span class="traceContains">+run: inst: 0x00000005</span> -<span id="L69" class="LineNr"> 69 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L70" class="LineNr"> 70 </span><span class="traceAbsent">-run: jump 5</span> -<span id="L71" class="LineNr"> 71 </span> -<span id="L72" class="LineNr"> 72 </span><span class="SalientComment">//:: jump if not equal/not zero</span> -<span id="L73" class="LineNr"> 73 </span> -<span id="L74" class="LineNr"> 74 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L75" class="LineNr"> 75 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"85"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away if not equal, if ZF is not set (jcc/jnz/jne)"</span><span class="Delimiter">);</span> -<span id="L76" class="LineNr"> 76 </span> -<span id="L77" class="LineNr"> 77 </span><span class="Delimiter">:(scenario jne_rel16_success)</span> -<span id="L78" class="LineNr"> 78 </span><span class="Special">% ZF = false;</span> -<span id="L79" class="LineNr"> 79 </span>== <span class="Constant">0x1</span> -<span id="L80" class="LineNr"> 80 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Constant">0f</span> <span class="Constant">85</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L82" class="LineNr"> 82 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L83" class="LineNr"> 83 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L84" class="LineNr"> 84 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L85" class="LineNr"> 85 </span><span class="traceContains">+run: jump 5</span> -<span id="L86" class="LineNr"> 86 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L87" class="LineNr"> 87 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L88" class="LineNr"> 88 </span> -<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> -<span id="L90" class="LineNr"> 90 </span><span class="Normal">case</span> <span class="Constant">0x85</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel16 unless ZF</span> -<span id="L91" class="LineNr"> 91 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L93" class="LineNr"> 93 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L94" class="LineNr"> 94 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Delimiter">}</span> -<span id="L96" class="LineNr"> 96 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L97" class="LineNr"> 97 </span><span class="Delimiter">}</span> -<span id="L98" class="LineNr"> 98 </span> -<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">:(scenario jne_rel16_fail)</span> -<span id="L100" class="LineNr">100 </span><span class="Special">% ZF = true;</span> -<span id="L101" class="LineNr">101 </span>== <span class="Constant">0x1</span> -<span id="L102" class="LineNr">102 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L103" class="LineNr">103 </span> <span class="Constant">0f</span> <span class="Constant">85</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L104" class="LineNr">104 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L105" class="LineNr">105 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L106" class="LineNr">106 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L107" class="LineNr">107 </span><span class="traceContains">+run: inst: 0x00000005</span> -<span id="L108" class="LineNr">108 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L109" class="LineNr">109 </span><span class="traceAbsent">-run: jump 5</span> -<span id="L110" class="LineNr">110 </span> -<span id="L111" class="LineNr">111 </span><span class="SalientComment">//:: jump if greater</span> -<span id="L112" class="LineNr">112 </span> -<span id="L113" class="LineNr">113 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L114" class="LineNr">114 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away if greater, if ZF is unset and SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jg/jnle)"</span><span class="Delimiter">);</span> -<span id="L115" class="LineNr">115 </span> -<span id="L116" class="LineNr">116 </span><span class="Delimiter">:(scenario jg_rel16_success)</span> -<span id="L117" class="LineNr">117 </span><span class="Special">% ZF = false;</span> -<span id="L118" class="LineNr">118 </span><span class="Special">% SF = false;</span> -<span id="L119" class="LineNr">119 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L120" class="LineNr">120 </span>== <span class="Constant">0x1</span> -<span id="L121" class="LineNr">121 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L122" class="LineNr">122 </span> <span class="Constant">0f</span> <span class="Constant">8f</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L123" class="LineNr">123 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L124" class="LineNr">124 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L125" class="LineNr">125 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L126" class="LineNr">126 </span><span class="traceContains">+run: jump 5</span> -<span id="L127" class="LineNr">127 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L128" class="LineNr">128 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L129" class="LineNr">129 </span> -<span id="L130" class="LineNr">130 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> -<span id="L131" class="LineNr">131 </span><span class="Normal">case</span> <span class="Constant">0x8f</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel16 if !SF and !ZF</span> -<span id="L132" class="LineNr">132 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L133" class="LineNr">133 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF && SF == <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L134" class="LineNr">134 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L135" class="LineNr">135 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L136" class="LineNr">136 </span> <span class="Delimiter">}</span> -<span id="L137" class="LineNr">137 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L138" class="LineNr">138 </span><span class="Delimiter">}</span> -<span id="L139" class="LineNr">139 </span> -<span id="L140" class="LineNr">140 </span><span class="Delimiter">:(scenario jg_rel16_fail)</span> -<span id="L141" class="LineNr">141 </span><span class="Special">% ZF = false;</span> -<span id="L142" class="LineNr">142 </span><span class="Special">% SF = true;</span> -<span id="L143" class="LineNr">143 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L144" class="LineNr">144 </span>== <span class="Constant">0x1</span> -<span id="L145" class="LineNr">145 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L146" class="LineNr">146 </span> <span class="Constant">0f</span> <span class="Constant">8f</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L147" class="LineNr">147 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L148" class="LineNr">148 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L149" class="LineNr">149 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L150" class="LineNr">150 </span><span class="traceContains">+run: inst: 0x00000005</span> -<span id="L151" class="LineNr">151 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L152" class="LineNr">152 </span><span class="traceAbsent">-run: jump 5</span> -<span id="L153" class="LineNr">153 </span> -<span id="L154" class="LineNr">154 </span><span class="SalientComment">//:: jump if greater or equal</span> -<span id="L155" class="LineNr">155 </span> -<span id="L156" class="LineNr">156 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L157" class="LineNr">157 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away if greater or equal, if SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jge/jnl)"</span><span class="Delimiter">);</span> -<span id="L158" class="LineNr">158 </span> -<span id="L159" class="LineNr">159 </span><span class="Delimiter">:(scenario jge_rel16_success)</span> -<span id="L160" class="LineNr">160 </span><span class="Special">% SF = false;</span> -<span id="L161" class="LineNr">161 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L162" class="LineNr">162 </span>== <span class="Constant">0x1</span> -<span id="L163" class="LineNr">163 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L164" class="LineNr">164 </span> <span class="Constant">0f</span> 8d <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L165" class="LineNr">165 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L166" class="LineNr">166 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L167" class="LineNr">167 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L168" class="LineNr">168 </span><span class="traceContains">+run: jump 5</span> -<span id="L169" class="LineNr">169 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L170" class="LineNr">170 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L171" class="LineNr">171 </span> -<span id="L172" class="LineNr">172 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> -<span id="L173" class="LineNr">173 </span><span class="Normal">case</span> <span class="Constant">0x8d</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel16 if !SF</span> -<span id="L174" class="LineNr">174 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L175" class="LineNr">175 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF == <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L176" class="LineNr">176 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L177" class="LineNr">177 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L178" class="LineNr">178 </span> <span class="Delimiter">}</span> -<span id="L179" class="LineNr">179 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L180" class="LineNr">180 </span><span class="Delimiter">}</span> -<span id="L181" class="LineNr">181 </span> -<span id="L182" class="LineNr">182 </span><span class="Delimiter">:(scenario jge_rel16_fail)</span> -<span id="L183" class="LineNr">183 </span><span class="Special">% SF = true;</span> -<span id="L184" class="LineNr">184 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L185" class="LineNr">185 </span>== <span class="Constant">0x1</span> -<span id="L186" class="LineNr">186 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L187" class="LineNr">187 </span> <span class="Constant">0f</span> 8d <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L188" class="LineNr">188 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L189" class="LineNr">189 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L190" class="LineNr">190 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L191" class="LineNr">191 </span><span class="traceContains">+run: inst: 0x00000005</span> -<span id="L192" class="LineNr">192 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L193" class="LineNr">193 </span><span class="traceAbsent">-run: jump 5</span> -<span id="L194" class="LineNr">194 </span> -<span id="L195" class="LineNr">195 </span><span class="SalientComment">//:: jump if lesser</span> -<span id="L196" class="LineNr">196 </span> -<span id="L197" class="LineNr">197 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L198" class="LineNr">198 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8c"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away if lesser, if SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jl/jnge)"</span><span class="Delimiter">);</span> -<span id="L199" class="LineNr">199 </span> -<span id="L200" class="LineNr">200 </span><span class="Delimiter">:(scenario jl_rel16_success)</span> -<span id="L201" class="LineNr">201 </span><span class="Special">% ZF = false;</span> -<span id="L202" class="LineNr">202 </span><span class="Special">% SF = true;</span> -<span id="L203" class="LineNr">203 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L204" class="LineNr">204 </span>== <span class="Constant">0x1</span> -<span id="L205" class="LineNr">205 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L206" class="LineNr">206 </span> <span class="Constant">0f</span> 8c <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L207" class="LineNr">207 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L208" class="LineNr">208 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L209" class="LineNr">209 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L210" class="LineNr">210 </span><span class="traceContains">+run: jump 5</span> -<span id="L211" class="LineNr">211 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L212" class="LineNr">212 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L213" class="LineNr">213 </span> -<span id="L214" class="LineNr">214 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> -<span id="L215" class="LineNr">215 </span><span class="Normal">case</span> <span class="Constant">0x8c</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel16 if SF and !ZF</span> -<span id="L216" class="LineNr">216 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L217" class="LineNr">217 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF != <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L218" class="LineNr">218 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L219" class="LineNr">219 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L220" class="LineNr">220 </span> <span class="Delimiter">}</span> -<span id="L221" class="LineNr">221 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L222" class="LineNr">222 </span><span class="Delimiter">}</span> -<span id="L223" class="LineNr">223 </span> -<span id="L224" class="LineNr">224 </span><span class="Delimiter">:(scenario jl_rel16_fail)</span> -<span id="L225" class="LineNr">225 </span><span class="Special">% ZF = false;</span> -<span id="L226" class="LineNr">226 </span><span class="Special">% SF = false;</span> -<span id="L227" class="LineNr">227 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L228" class="LineNr">228 </span>== <span class="Constant">0x1</span> -<span id="L229" class="LineNr">229 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L230" class="LineNr">230 </span> <span class="Constant">0f</span> 8c <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L231" class="LineNr">231 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L232" class="LineNr">232 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L233" class="LineNr">233 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L234" class="LineNr">234 </span><span class="traceContains">+run: inst: 0x00000005</span> -<span id="L235" class="LineNr">235 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L236" class="LineNr">236 </span><span class="traceAbsent">-run: jump 5</span> -<span id="L237" class="LineNr">237 </span> -<span id="L238" class="LineNr">238 </span><span class="SalientComment">//:: jump if lesser or equal</span> -<span id="L239" class="LineNr">239 </span> -<span id="L240" class="LineNr">240 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L241" class="LineNr">241 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> <span class="Constant">"8e"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp16 bytes away if lesser or equal, if ZF is set or SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jle/jng)"</span><span class="Delimiter">);</span> -<span id="L242" class="LineNr">242 </span> -<span id="L243" class="LineNr">243 </span><span class="Delimiter">:(scenario jle_rel16_equal)</span> -<span id="L244" class="LineNr">244 </span><span class="Special">% ZF = true;</span> -<span id="L245" class="LineNr">245 </span><span class="Special">% SF = false;</span> -<span id="L246" class="LineNr">246 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L247" class="LineNr">247 </span>== <span class="Constant">0x1</span> -<span id="L248" class="LineNr">248 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L249" class="LineNr">249 </span> <span class="Constant">0f</span> 8e <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L250" class="LineNr">250 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L251" class="LineNr">251 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L252" class="LineNr">252 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L253" class="LineNr">253 </span><span class="traceContains">+run: jump 5</span> -<span id="L254" class="LineNr">254 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L255" class="LineNr">255 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L256" class="LineNr">256 </span> -<span id="L257" class="LineNr">257 </span><span class="Delimiter">:(scenario jle_rel16_lesser)</span> -<span id="L258" class="LineNr">258 </span><span class="Special">% ZF = false;</span> -<span id="L259" class="LineNr">259 </span><span class="Special">% SF = true;</span> -<span id="L260" class="LineNr">260 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L261" class="LineNr">261 </span>== <span class="Constant">0x1</span> -<span id="L262" class="LineNr">262 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L263" class="LineNr">263 </span> <span class="Constant">0f</span> 8e <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L264" class="LineNr">264 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L265" class="LineNr">265 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L266" class="LineNr">266 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L267" class="LineNr">267 </span><span class="traceContains">+run: jump 5</span> -<span id="L268" class="LineNr">268 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L269" class="LineNr">269 </span><span class="traceAbsent">-run: inst: 0x00000005</span> -<span id="L270" class="LineNr">270 </span> -<span id="L271" class="LineNr">271 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> -<span id="L272" class="LineNr">272 </span><span class="Normal">case</span> <span class="Constant">0x8e</span>: <span class="Delimiter">{</span> <span class="Comment">// jump rel16 if SF or ZF</span> -<span id="L273" class="LineNr">273 </span> <span class="Normal">const</span> <span class="Normal">int8_t</span> offset = <a href='018jump_disp16.cc.html#L27'>imm16</a><span class="Delimiter">();</span> -<span id="L274" class="LineNr">274 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>ZF || SF != <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L275" class="LineNr">275 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L276" class="LineNr">276 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L277" class="LineNr">277 </span> <span class="Delimiter">}</span> -<span id="L278" class="LineNr">278 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L279" class="LineNr">279 </span><span class="Delimiter">}</span> -<span id="L280" class="LineNr">280 </span> -<span id="L281" class="LineNr">281 </span><span class="Delimiter">:(scenario jle_rel16_greater)</span> -<span id="L282" class="LineNr">282 </span><span class="Special">% ZF = false;</span> -<span id="L283" class="LineNr">283 </span><span class="Special">% SF = false;</span> -<span id="L284" class="LineNr">284 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> -<span id="L285" class="LineNr">285 </span>== <span class="Constant">0x1</span> -<span id="L286" class="LineNr">286 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> -<span id="L287" class="LineNr">287 </span> <span class="Constant">0f</span> 8e <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> -<span id="L288" class="LineNr">288 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> -<span id="L289" class="LineNr">289 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> -<span id="L290" class="LineNr">290 </span><span class="traceContains">+run: inst: 0x00000001</span> -<span id="L291" class="LineNr">291 </span><span class="traceContains">+run: inst: 0x00000005</span> -<span id="L292" class="LineNr">292 </span><span class="traceContains">+run: inst: 0x0000000a</span> -<span id="L293" class="LineNr">293 </span><span class="traceAbsent">-run: jump 5</span> -</pre> -</body> -</html> -<!-- vim: set foldmethod=manual : --> diff --git a/html/subx/018jump_disp32.cc.html b/html/subx/018jump_disp32.cc.html new file mode 100644 index 00000000..3363fe0a --- /dev/null +++ b/html/subx/018jump_disp32.cc.html @@ -0,0 +1,354 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - subx/018jump_disp32.cc</title> +<meta name="Generator" content="Vim/8.0"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="cpp"> +<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { white-space: pre-wrap; font-family: monospace; color: #aaaaaa; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } +a { color:#eeeeee; text-decoration: none; } +a:hover { text-decoration: underline; } +* { font-size: 12pt; font-size: 1em; } +.traceAbsent { color: #c00000; } +.traceContains { color: #008000; } +.PreProc { color: #800080; } +.LineNr { color: #444444; } +.Constant { color: #00a0a0; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Identifier { color: #c0a020; } +.Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } +.Comment { color: #9090ff; } +.Comment a { color:#0000ee; text-decoration:underline; } +.SalientComment { color: #00ffff; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment">//: jump to 32-bit offset</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span><span class="SalientComment">//:: jump</span> +<span id="L4" class="LineNr"> 4 </span> +<span id="L5" class="LineNr"> 5 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L6" class="LineNr"> 6 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"e9"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away (jmp)"</span><span class="Delimiter">);</span> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(scenario jump_disp32)</span> +<span id="L9" class="LineNr"> 9 </span>== <span class="Constant">0x1</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L11" class="LineNr"> 11 </span> e9 <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L12" class="LineNr"> 12 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L13" class="LineNr"> 13 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L14" class="LineNr"> 14 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L15" class="LineNr"> 15 </span><span class="traceContains">+run: jump 5</span> +<span id="L16" class="LineNr"> 16 </span><span class="traceContains">+run: inst: 0x0000000b</span> +<span id="L17" class="LineNr"> 17 </span><span class="traceAbsent">-run: inst: 0x00000006</span> +<span id="L18" class="LineNr"> 18 </span> +<span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> +<span id="L20" class="LineNr"> 20 </span><span class="Normal">case</span> <span class="Constant">0xe9</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L22" class="LineNr"> 22 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << offset << end<span class="Delimiter">();</span> +<span id="L23" class="LineNr"> 23 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L25" class="LineNr"> 25 </span><span class="Delimiter">}</span> +<span id="L26" class="LineNr"> 26 </span> +<span id="L27" class="LineNr"> 27 </span><span class="SalientComment">//:: jump if equal/zero</span> +<span id="L28" class="LineNr"> 28 </span> +<span id="L29" class="LineNr"> 29 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L30" class="LineNr"> 30 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"84"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away if equal, if ZF is set (jcc/jz/je)"</span><span class="Delimiter">);</span> +<span id="L31" class="LineNr"> 31 </span> +<span id="L32" class="LineNr"> 32 </span><span class="Delimiter">:(scenario je_disp32_success)</span> +<span id="L33" class="LineNr"> 33 </span><span class="Special">% ZF = true;</span> +<span id="L34" class="LineNr"> 34 </span>== <span class="Constant">0x1</span> +<span id="L35" class="LineNr"> 35 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Constant">0f</span> <span class="Constant">84</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L37" class="LineNr"> 37 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L38" class="LineNr"> 38 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L39" class="LineNr"> 39 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L40" class="LineNr"> 40 </span><span class="traceContains">+run: jump 5</span> +<span id="L41" class="LineNr"> 41 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L42" class="LineNr"> 42 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L43" class="LineNr"> 43 </span> +<span id="L44" class="LineNr"> 44 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L45" class="LineNr"> 45 </span><span class="Normal">case</span> <span class="Constant">0x84</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if ZF</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L48" class="LineNr"> 48 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L49" class="LineNr"> 49 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Delimiter">}</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L52" class="LineNr"> 52 </span><span class="Delimiter">}</span> +<span id="L53" class="LineNr"> 53 </span> +<span id="L54" class="LineNr"> 54 </span><span class="Delimiter">:(scenario je_disp32_fail)</span> +<span id="L55" class="LineNr"> 55 </span><span class="Special">% ZF = false;</span> +<span id="L56" class="LineNr"> 56 </span>== <span class="Constant">0x1</span> +<span id="L57" class="LineNr"> 57 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Constant">0f</span> <span class="Constant">84</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L59" class="LineNr"> 59 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L60" class="LineNr"> 60 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L61" class="LineNr"> 61 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L62" class="LineNr"> 62 </span><span class="traceContains">+run: inst: 0x00000007</span> +<span id="L63" class="LineNr"> 63 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L64" class="LineNr"> 64 </span><span class="traceAbsent">-run: jump 5</span> +<span id="L65" class="LineNr"> 65 </span> +<span id="L66" class="LineNr"> 66 </span><span class="SalientComment">//:: jump if not equal/not zero</span> +<span id="L67" class="LineNr"> 67 </span> +<span id="L68" class="LineNr"> 68 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L69" class="LineNr"> 69 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"85"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away if not equal, if ZF is not set (jcc/jnz/jne)"</span><span class="Delimiter">);</span> +<span id="L70" class="LineNr"> 70 </span> +<span id="L71" class="LineNr"> 71 </span><span class="Delimiter">:(scenario jne_disp32_success)</span> +<span id="L72" class="LineNr"> 72 </span><span class="Special">% ZF = false;</span> +<span id="L73" class="LineNr"> 73 </span>== <span class="Constant">0x1</span> +<span id="L74" class="LineNr"> 74 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">0f</span> <span class="Constant">85</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L76" class="LineNr"> 76 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L77" class="LineNr"> 77 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L78" class="LineNr"> 78 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L79" class="LineNr"> 79 </span><span class="traceContains">+run: jump 5</span> +<span id="L80" class="LineNr"> 80 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L81" class="LineNr"> 81 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L82" class="LineNr"> 82 </span> +<span id="L83" class="LineNr"> 83 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L84" class="LineNr"> 84 </span><span class="Normal">case</span> <span class="Constant">0x85</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 unless ZF</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L87" class="LineNr"> 87 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L88" class="LineNr"> 88 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L91" class="LineNr"> 91 </span><span class="Delimiter">}</span> +<span id="L92" class="LineNr"> 92 </span> +<span id="L93" class="LineNr"> 93 </span><span class="Delimiter">:(scenario jne_disp32_fail)</span> +<span id="L94" class="LineNr"> 94 </span><span class="Special">% ZF = true;</span> +<span id="L95" class="LineNr"> 95 </span>== <span class="Constant">0x1</span> +<span id="L96" class="LineNr"> 96 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Constant">0f</span> <span class="Constant">85</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L98" class="LineNr"> 98 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L99" class="LineNr"> 99 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L100" class="LineNr">100 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L101" class="LineNr">101 </span><span class="traceContains">+run: inst: 0x00000007</span> +<span id="L102" class="LineNr">102 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L103" class="LineNr">103 </span><span class="traceAbsent">-run: jump 5</span> +<span id="L104" class="LineNr">104 </span> +<span id="L105" class="LineNr">105 </span><span class="SalientComment">//:: jump if greater</span> +<span id="L106" class="LineNr">106 </span> +<span id="L107" class="LineNr">107 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L108" class="LineNr">108 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away if greater, if ZF is unset and SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jg/jnle)"</span><span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> +<span id="L110" class="LineNr">110 </span><span class="Delimiter">:(scenario jg_disp32_success)</span> +<span id="L111" class="LineNr">111 </span><span class="Special">% ZF = false;</span> +<span id="L112" class="LineNr">112 </span><span class="Special">% SF = false;</span> +<span id="L113" class="LineNr">113 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L114" class="LineNr">114 </span>== <span class="Constant">0x1</span> +<span id="L115" class="LineNr">115 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L116" class="LineNr">116 </span> <span class="Constant">0f</span> <span class="Constant">8f</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L117" class="LineNr">117 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L118" class="LineNr">118 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L119" class="LineNr">119 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L120" class="LineNr">120 </span><span class="traceContains">+run: jump 5</span> +<span id="L121" class="LineNr">121 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L122" class="LineNr">122 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L123" class="LineNr">123 </span> +<span id="L124" class="LineNr">124 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L125" class="LineNr">125 </span><span class="Normal">case</span> <span class="Constant">0x8f</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !SF and !ZF</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L127" class="LineNr">127 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!ZF && SF == <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L128" class="LineNr">128 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L129" class="LineNr">129 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L130" class="LineNr">130 </span> <span class="Delimiter">}</span> +<span id="L131" class="LineNr">131 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L132" class="LineNr">132 </span><span class="Delimiter">}</span> +<span id="L133" class="LineNr">133 </span> +<span id="L134" class="LineNr">134 </span><span class="Delimiter">:(scenario jg_disp32_fail)</span> +<span id="L135" class="LineNr">135 </span><span class="Special">% ZF = false;</span> +<span id="L136" class="LineNr">136 </span><span class="Special">% SF = true;</span> +<span id="L137" class="LineNr">137 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L138" class="LineNr">138 </span>== <span class="Constant">0x1</span> +<span id="L139" class="LineNr">139 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L140" class="LineNr">140 </span> <span class="Constant">0f</span> <span class="Constant">8f</span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L141" class="LineNr">141 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L142" class="LineNr">142 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L143" class="LineNr">143 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L144" class="LineNr">144 </span><span class="traceContains">+run: inst: 0x00000007</span> +<span id="L145" class="LineNr">145 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L146" class="LineNr">146 </span><span class="traceAbsent">-run: jump 5</span> +<span id="L147" class="LineNr">147 </span> +<span id="L148" class="LineNr">148 </span><span class="SalientComment">//:: jump if greater or equal</span> +<span id="L149" class="LineNr">149 </span> +<span id="L150" class="LineNr">150 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L151" class="LineNr">151 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away if greater or equal, if SF == <a href='010---vm.cc.html#L81'>OF</a> (jcc/jge/jnl)"</span><span class="Delimiter">);</span> +<span id="L152" class="LineNr">152 </span> +<span id="L153" class="LineNr">153 </span><span class="Delimiter">:(scenario jge_disp32_success)</span> +<span id="L154" class="LineNr">154 </span><span class="Special">% SF = false;</span> +<span id="L155" class="LineNr">155 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L156" class="LineNr">156 </span>== <span class="Constant">0x1</span> +<span id="L157" class="LineNr">157 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L158" class="LineNr">158 </span> <span class="Constant">0f</span> 8d <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L159" class="LineNr">159 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L160" class="LineNr">160 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L161" class="LineNr">161 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L162" class="LineNr">162 </span><span class="traceContains">+run: jump 5</span> +<span id="L163" class="LineNr">163 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L164" class="LineNr">164 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L165" class="LineNr">165 </span> +<span id="L166" class="LineNr">166 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L167" class="LineNr">167 </span><span class="Normal">case</span> <span class="Constant">0x8d</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if !SF</span> +<span id="L168" class="LineNr">168 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L169" class="LineNr">169 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF == <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L170" class="LineNr">170 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L171" class="LineNr">171 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L172" class="LineNr">172 </span> <span class="Delimiter">}</span> +<span id="L173" class="LineNr">173 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L174" class="LineNr">174 </span><span class="Delimiter">}</span> +<span id="L175" class="LineNr">175 </span> +<span id="L176" class="LineNr">176 </span><span class="Delimiter">:(scenario jge_disp32_fail)</span> +<span id="L177" class="LineNr">177 </span><span class="Special">% SF = true;</span> +<span id="L178" class="LineNr">178 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L179" class="LineNr">179 </span>== <span class="Constant">0x1</span> +<span id="L180" class="LineNr">180 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L181" class="LineNr">181 </span> <span class="Constant">0f</span> 8d <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L182" class="LineNr">182 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L183" class="LineNr">183 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L184" class="LineNr">184 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L185" class="LineNr">185 </span><span class="traceContains">+run: inst: 0x00000007</span> +<span id="L186" class="LineNr">186 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L187" class="LineNr">187 </span><span class="traceAbsent">-run: jump 5</span> +<span id="L188" class="LineNr">188 </span> +<span id="L189" class="LineNr">189 </span><span class="SalientComment">//:: jump if lesser</span> +<span id="L190" class="LineNr">190 </span> +<span id="L191" class="LineNr">191 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L192" class="LineNr">192 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8c"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away if lesser, if SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jl/jnge)"</span><span class="Delimiter">);</span> +<span id="L193" class="LineNr">193 </span> +<span id="L194" class="LineNr">194 </span><span class="Delimiter">:(scenario jl_disp32_success)</span> +<span id="L195" class="LineNr">195 </span><span class="Special">% ZF = false;</span> +<span id="L196" class="LineNr">196 </span><span class="Special">% SF = true;</span> +<span id="L197" class="LineNr">197 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L198" class="LineNr">198 </span>== <span class="Constant">0x1</span> +<span id="L199" class="LineNr">199 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L200" class="LineNr">200 </span> <span class="Constant">0f</span> 8c <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L201" class="LineNr">201 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L202" class="LineNr">202 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L203" class="LineNr">203 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L204" class="LineNr">204 </span><span class="traceContains">+run: jump 5</span> +<span id="L205" class="LineNr">205 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L206" class="LineNr">206 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L207" class="LineNr">207 </span> +<span id="L208" class="LineNr">208 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L209" class="LineNr">209 </span><span class="Normal">case</span> <span class="Constant">0x8c</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if SF and !ZF</span> +<span id="L210" class="LineNr">210 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L211" class="LineNr">211 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>SF != <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L212" class="LineNr">212 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L213" class="LineNr">213 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L214" class="LineNr">214 </span> <span class="Delimiter">}</span> +<span id="L215" class="LineNr">215 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L216" class="LineNr">216 </span><span class="Delimiter">}</span> +<span id="L217" class="LineNr">217 </span> +<span id="L218" class="LineNr">218 </span><span class="Delimiter">:(scenario jl_disp32_fail)</span> +<span id="L219" class="LineNr">219 </span><span class="Special">% ZF = false;</span> +<span id="L220" class="LineNr">220 </span><span class="Special">% SF = false;</span> +<span id="L221" class="LineNr">221 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L222" class="LineNr">222 </span>== <span class="Constant">0x1</span> +<span id="L223" class="LineNr">223 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L224" class="LineNr">224 </span> <span class="Constant">0f</span> 8c <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L225" class="LineNr">225 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L226" class="LineNr">226 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L227" class="LineNr">227 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L228" class="LineNr">228 </span><span class="traceContains">+run: inst: 0x00000007</span> +<span id="L229" class="LineNr">229 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L230" class="LineNr">230 </span><span class="traceAbsent">-run: jump 5</span> +<span id="L231" class="LineNr">231 </span> +<span id="L232" class="LineNr">232 </span><span class="SalientComment">//:: jump if lesser or equal</span> +<span id="L233" class="LineNr">233 </span> +<span id="L234" class="LineNr">234 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> +<span id="L235" class="LineNr">235 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8e"</span><span class="Delimiter">,</span> <span class="Constant">"jump disp32 bytes away if lesser or equal, if ZF is set or SF != <a href='010---vm.cc.html#L81'>OF</a> (jcc/jle/jng)"</span><span class="Delimiter">);</span> +<span id="L236" class="LineNr">236 </span> +<span id="L237" class="LineNr">237 </span><span class="Delimiter">:(scenario jle_disp32_equal)</span> +<span id="L238" class="LineNr">238 </span><span class="Special">% ZF = true;</span> +<span id="L239" class="LineNr">239 </span><span class="Special">% SF = false;</span> +<span id="L240" class="LineNr">240 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L241" class="LineNr">241 </span>== <span class="Constant">0x1</span> +<span id="L242" class="LineNr">242 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L243" class="LineNr">243 </span> <span class="Constant">0f</span> 8e <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L244" class="LineNr">244 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L245" class="LineNr">245 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L246" class="LineNr">246 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L247" class="LineNr">247 </span><span class="traceContains">+run: jump 5</span> +<span id="L248" class="LineNr">248 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L249" class="LineNr">249 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L250" class="LineNr">250 </span> +<span id="L251" class="LineNr">251 </span><span class="Delimiter">:(scenario jle_disp32_lesser)</span> +<span id="L252" class="LineNr">252 </span><span class="Special">% ZF = false;</span> +<span id="L253" class="LineNr">253 </span><span class="Special">% SF = true;</span> +<span id="L254" class="LineNr">254 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L255" class="LineNr">255 </span>== <span class="Constant">0x1</span> +<span id="L256" class="LineNr">256 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L257" class="LineNr">257 </span> <span class="Constant">0f</span> 8e <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L258" class="LineNr">258 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L259" class="LineNr">259 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L260" class="LineNr">260 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L261" class="LineNr">261 </span><span class="traceContains">+run: jump 5</span> +<span id="L262" class="LineNr">262 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L263" class="LineNr">263 </span><span class="traceAbsent">-run: inst: 0x00000007</span> +<span id="L264" class="LineNr">264 </span> +<span id="L265" class="LineNr">265 </span><span class="Delimiter">:(before "End Two-Byte Opcodes Starting With 0f")</span> +<span id="L266" class="LineNr">266 </span><span class="Normal">case</span> <span class="Constant">0x8e</span>: <span class="Delimiter">{</span> <span class="Comment">// jump disp32 if SF or ZF</span> +<span id="L267" class="LineNr">267 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> +<span id="L268" class="LineNr">268 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>ZF || SF != <a href='010---vm.cc.html#L81'>OF</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L269" class="LineNr">269 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jump "</span> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>offset<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L270" class="LineNr">270 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> +<span id="L271" class="LineNr">271 </span> <span class="Delimiter">}</span> +<span id="L272" class="LineNr">272 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L273" class="LineNr">273 </span><span class="Delimiter">}</span> +<span id="L274" class="LineNr">274 </span> +<span id="L275" class="LineNr">275 </span><span class="Delimiter">:(scenario jle_disp32_greater)</span> +<span id="L276" class="LineNr">276 </span><span class="Special">% ZF = false;</span> +<span id="L277" class="LineNr">277 </span><span class="Special">% SF = false;</span> +<span id="L278" class="LineNr">278 </span><span class="Special">% <a href='010---vm.cc.html#L81'>OF</a> = false;</span> +<span id="L279" class="LineNr">279 </span>== <span class="Constant">0x1</span> +<span id="L280" class="LineNr">280 </span><span class="Comment"># op ModR/M SIB displacement immediate</span> +<span id="L281" class="LineNr">281 </span> <span class="Constant">0f</span> 8e <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="Comment"># skip 1 instruction</span> +<span id="L282" class="LineNr">282 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">1</span> +<span id="L283" class="LineNr">283 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">2</span> +<span id="L284" class="LineNr">284 </span><span class="traceContains">+run: inst: 0x00000001</span> +<span id="L285" class="LineNr">285 </span><span class="traceContains">+run: inst: 0x00000007</span> +<span id="L286" class="LineNr">286 </span><span class="traceContains">+run: inst: 0x0000000c</span> +<span id="L287" class="LineNr">287 </span><span class="traceAbsent">-run: jump 5</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/subx/019functions.cc.html b/html/subx/019functions.cc.html index 4f3a1db0..2cab5df7 100644 --- a/html/subx/019functions.cc.html +++ b/html/subx/019functions.cc.html @@ -64,7 +64,7 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="SalientComment">//:: call</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"e8"</span><span class="Delimiter">,</span> <span class="Constant">"call disp32 (call)"</span><span class="Delimiter">);</span> +<span id="L4" class="LineNr"> 4 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"e8"</span><span class="Delimiter">,</span> <span class="Constant">"call disp32 (call)"</span><span class="Delimiter">);</span> <span id="L5" class="LineNr"> 5 </span> <span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(scenario call_disp32)</span> <span id="L7" class="LineNr"> 7 </span><span class="Special">% Reg[ESP].u = 0x64;</span> @@ -80,11 +80,11 @@ if ('onhashchange' in window) { <span id="L17" class="LineNr">17 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L18" class="LineNr">18 </span><span class="Normal">case</span> <span class="Constant">0xe8</span>: <span class="Delimiter">{</span> <span class="Comment">// call disp32 relative to next EIP</span> <span id="L19" class="LineNr">19 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span> offset = <a href='011run.cc.html#L343'>next32</a><span class="Delimiter">();</span> -<span id="L20" class="LineNr">20 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"call imm32 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << offset << end<span class="Delimiter">();</span> +<span id="L20" class="LineNr">20 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"call imm32 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << offset << end<span class="Delimiter">();</span> <span id="L21" class="LineNr">21 </span><span class="CommentedCode">//? cerr << "push: EIP: " << EIP << " => " << Reg[ESP].u << '\n';</span> <span id="L22" class="LineNr">22 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a><span class="Delimiter">);</span> <span id="L23" class="LineNr">23 </span> <a href='010---vm.cc.html#L29'>EIP</a> += offset<span class="Delimiter">;</span> -<span id="L24" class="LineNr">24 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L24" class="LineNr">24 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> <span id="L25" class="LineNr">25 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L26" class="LineNr">26 </span><span class="Delimiter">}</span> <span id="L27" class="LineNr">27 </span> @@ -109,7 +109,7 @@ if ('onhashchange' in window) { <span id="L46" class="LineNr">46 </span> <span class="Normal">const</span> <span class="Normal">int32_t</span>* offset = <a href='013direct_addressing.cc.html#L31'>effective_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">);</span> <span id="L47" class="LineNr">47 </span> <a href='012elf.cc.html#L89'>push</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L29'>EIP</a><span class="Delimiter">);</span> <span id="L48" class="LineNr">48 </span> <a href='010---vm.cc.html#L29'>EIP</a> += *offset<span class="Delimiter">;</span> -<span id="L49" class="LineNr">49 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L49" class="LineNr">49 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> <span id="L50" class="LineNr">50 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L51" class="LineNr">51 </span><span class="Delimiter">}</span> <span id="L52" class="LineNr">52 </span> @@ -131,7 +131,7 @@ if ('onhashchange' in window) { <span id="L68" class="LineNr">68 </span><span class="SalientComment">//:: ret</span> <span id="L69" class="LineNr">69 </span> <span id="L70" class="LineNr">70 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L71" class="LineNr">71 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"c3"</span><span class="Delimiter">,</span> <span class="Constant">"return from most recent unfinished call (ret)"</span><span class="Delimiter">);</span> +<span id="L71" class="LineNr">71 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"c3"</span><span class="Delimiter">,</span> <span class="Constant">"return from most recent unfinished call (ret)"</span><span class="Delimiter">);</span> <span id="L72" class="LineNr">72 </span> <span id="L73" class="LineNr">73 </span><span class="Delimiter">:(scenario ret)</span> <span id="L74" class="LineNr">74 </span><span class="Special">% Reg[ESP].u = 0x2000;</span> @@ -148,7 +148,7 @@ if ('onhashchange' in window) { <span id="L85" class="LineNr">85 </span><span class="Normal">case</span> <span class="Constant">0xc3</span>: <span class="Delimiter">{</span> <span class="Comment">// return from a call</span> <span id="L86" class="LineNr">86 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"return"</span> << end<span class="Delimiter">();</span> <span id="L87" class="LineNr">87 </span> <a href='010---vm.cc.html#L29'>EIP</a> = <a href='013direct_addressing.cc.html#L630'>pop</a><span class="Delimiter">();</span> -<span id="L88" class="LineNr">88 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> +<span id="L88" class="LineNr">88 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"jumping to 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << end<span class="Delimiter">();</span> <span id="L89" class="LineNr">89 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L90" class="LineNr">90 </span><span class="Delimiter">}</span> </pre> diff --git a/html/subx/020syscalls.cc.html b/html/subx/020syscalls.cc.html index 7dba5960..efbd687c 100644 --- a/html/subx/020syscalls.cc.html +++ b/html/subx/020syscalls.cc.html @@ -19,6 +19,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -59,15 +60,15 @@ if ('onhashchange' in window) { <body onload='JumpToLine();'> <pre id='vimCodeElement'> <span id="L1" class="LineNr"> 1 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L2" class="LineNr"> 2 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"cd"</span><span class="Delimiter">,</span> <span class="Constant">"software interrupt (int)"</span><span class="Delimiter">);</span> +<span id="L2" class="LineNr"> 2 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"cd"</span><span class="Delimiter">,</span> <span class="Constant">"software interrupt (int)"</span><span class="Delimiter">);</span> <span id="L3" class="LineNr"> 3 </span> <span id="L4" class="LineNr"> 4 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L5" class="LineNr"> 5 </span><span class="Normal">case</span> <span class="Constant">0xcd</span>: <span class="Delimiter">{</span> <span class="Comment">// int imm8 (software interrupt)</span> <span id="L6" class="LineNr"> 6 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"syscall"</span> << end<span class="Delimiter">();</span> -<span id="L7" class="LineNr"> 7 </span> <span class="Normal">uint8_t</span> <a href='031check_operands.cc.html#L11'>code</a> = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L7" class="LineNr"> 7 </span> <span class="Normal">uint8_t</span> <a href='031check_operands.cc.html#L11'>code</a> = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L8" class="LineNr"> 8 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a> != <span class="Constant">0x80</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Unimplemented interrupt <a href='031check_operands.cc.html#L11'>code</a> "</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='031check_operands.cc.html#L11'>code</a> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">" Only `int 80h` supported for now.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L9" class="LineNr"> 9 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"Unimplemented interrupt <a href='031check_operands.cc.html#L11'>code</a> "</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='031check_operands.cc.html#L11'>code</a> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L10" class="LineNr"> 10 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">" Only `int 80h` supported for now.\n"</span> << end<span class="Delimiter">();</span> <span id="L11" class="LineNr"> 11 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L12" class="LineNr"> 12 </span> <span class="Delimiter">}</span> <span id="L13" class="LineNr"> 13 </span> <a href='020syscalls.cc.html#L18'>process_int80</a><span class="Delimiter">();</span> @@ -76,110 +77,109 @@ if ('onhashchange' in window) { <span id="L16" class="LineNr"> 16 </span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">:(code)</span> <span id="L18" class="LineNr"> 18 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L18'>process_int80</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L19" class="LineNr"> 19 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Normal">switch</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L20" class="LineNr"> 20 </span> <span class="Normal">case</span> <span class="Constant">1</span>: -<span id="L21" class="LineNr"> 21 </span> exit<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">exit <a href='031check_operands.cc.html#L11'>code</a></span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L21" class="LineNr"> 21 </span> exit<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">exit <a href='031check_operands.cc.html#L11'>code</a></span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> <span id="L22" class="LineNr"> 22 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L23" class="LineNr"> 23 </span> <span class="Normal">case</span> <span class="Constant">3</span>: -<span id="L24" class="LineNr"> 24 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"read: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L25" class="LineNr"> 25 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L246'>mem_addr_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L26" class="LineNr"> 26 </span> Reg[EAX]<span class="Delimiter">.</span>i = read<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span>Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> -<span id="L27" class="LineNr"> 27 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L28" class="LineNr"> 28 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L29" class="LineNr"> 29 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Normal">case</span> <span class="Constant">4</span>: -<span id="L31" class="LineNr"> 31 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"write: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L32" class="LineNr"> 32 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L246'>mem_addr_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L33" class="LineNr"> 33 </span> Reg[EAX]<span class="Delimiter">.</span>i = write<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span>Reg[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> -<span id="L34" class="LineNr"> 34 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L35" class="LineNr"> 35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L36" class="LineNr"> 36 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L37" class="LineNr"> 37 </span> <span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> -<span id="L38" class="LineNr"> 38 </span> <a href='020syscalls.cc.html#L94'>check_flags</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L14'>ECX</a><span class="Delimiter">);</span> -<span id="L39" class="LineNr"> 39 </span> <a href='020syscalls.cc.html#L106'>check_mode</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L15'>EDX</a><span class="Delimiter">);</span> -<span id="L40" class="LineNr"> 40 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"open: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << Reg[ECX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L41" class="LineNr"> 41 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L42" class="LineNr"> 42 </span> Reg[EAX]<span class="Delimiter">.</span>i = open<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">flags</span><span class="Comment">*/</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> -<span id="L43" class="LineNr"> 43 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L44" class="LineNr"> 44 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L45" class="LineNr"> 45 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L46" class="LineNr"> 46 </span> <span class="Delimiter">}</span> -<span id="L47" class="LineNr"> 47 </span> <span class="Normal">case</span> <span class="Constant">6</span>: -<span id="L48" class="LineNr"> 48 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"close: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L49" class="LineNr"> 49 </span> Reg[EAX]<span class="Delimiter">.</span>i = close<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> -<span id="L50" class="LineNr"> 50 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L51" class="LineNr"> 51 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Normal">case</span> <span class="Constant">8</span>: -<span id="L54" class="LineNr"> 54 </span> <a href='020syscalls.cc.html#L106'>check_mode</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L14'>ECX</a><span class="Delimiter">);</span> -<span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"creat: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L56" class="LineNr"> 56 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L57" class="LineNr"> 57 </span> Reg[EAX]<span class="Delimiter">.</span>i = creat<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> -<span id="L58" class="LineNr"> 58 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Normal">case</span> <span class="Constant">10</span>: -<span id="L62" class="LineNr"> 62 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"unlink: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L63" class="LineNr"> 63 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L64" class="LineNr"> 64 </span> Reg[EAX]<span class="Delimiter">.</span>i = unlink<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> -<span id="L65" class="LineNr"> 65 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Normal">case</span> <span class="Constant">38</span>: -<span id="L69" class="LineNr"> 69 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"rename: "</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" -> "</span> << Reg[ECX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L70" class="LineNr"> 70 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L71" class="LineNr"> 71 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << Reg[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L72" class="LineNr"> 72 </span> Reg[EAX]<span class="Delimiter">.</span>i = rename<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">old filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">new filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L243'>mem_addr_kernel_string</a><span class="Delimiter">(</span>Reg[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> -<span id="L73" class="LineNr"> 73 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> -<span id="L74" class="LineNr"> 74 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L75" class="LineNr"> 75 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Normal">case</span> <span class="Constant">45</span>: <span class="Comment">// brk: modify size of data segment</span> -<span id="L77" class="LineNr"> 77 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"grow data segment to "</span> << Reg[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L78" class="LineNr"> 78 </span> <a href='010---vm.cc.html#L180'>grow_data_segment</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">new end address</span><span class="Comment">*/</span>Reg[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> -<span id="L79" class="LineNr"> 79 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L80" class="LineNr"> 80 </span> <span class="Normal">case</span> <span class="Constant">90</span>: <span class="Comment">// mmap: allocate memory outside existing segment allocations</span> -<span id="L81" class="LineNr"> 81 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"mmap: allocate new segment"</span> << end<span class="Delimiter">();</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Comment">// Ignore most arguments for now: address hint, protection flags, sharing flags, fd, offset.</span> -<span id="L83" class="LineNr"> 83 </span> <span class="Comment">// We only support anonymous maps.</span> -<span id="L84" class="LineNr"> 84 </span> Reg[EAX]<span class="Delimiter">.</span>u = <a href='020syscalls.cc.html#L117'>new_segment</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">length</span><span class="Comment">*/</span><a href='010---vm.cc.html#L200'>read_mem_u32</a><span class="Delimiter">(</span>Reg[EBX]<span class="Delimiter">.</span>u+<span class="Constant">0x4</span><span class="Delimiter">));</span> -<span id="L85" class="LineNr"> 85 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << Reg[EAX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> -<span id="L86" class="LineNr"> 86 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L87" class="LineNr"> 87 </span> <span class="Normal">default</span>: -<span id="L88" class="LineNr"> 88 </span> <a href='003trace.cc.html#L210'>raise</a> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": unimplemented syscall "</span> << Reg[EAX]<span class="Delimiter">.</span>u << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> -<span id="L89" class="LineNr"> 89 </span> <span class="Delimiter">}</span> -<span id="L90" class="LineNr"> 90 </span><span class="Delimiter">}</span> -<span id="L91" class="LineNr"> 91 </span> -<span id="L92" class="LineNr"> 92 </span><span class="Comment">// SubX is oblivious to file permissions, directories, symbolic links, terminals, and much else besides.</span> -<span id="L93" class="LineNr"> 93 </span><span class="Comment">// Also ignoring any concurrency considerations for now.</span> -<span id="L94" class="LineNr"> 94 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L94'>check_flags</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Normal">uint32_t</span> flags = Reg[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> -<span id="L96" class="LineNr"> 96 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>flags != <span class="Delimiter">((</span>flags & O_RDONLY<span class="Delimiter">)</span> | <span class="Delimiter">(</span>flags & O_WRONLY<span class="Delimiter">)))</span> <span class="Delimiter">{</span> -<span id="L97" class="LineNr"> 97 </span> cerr << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": most POSIX flags to the open() syscall are not supported. Just O_RDONLY and O_WRONLY for now. Zero concurrent access support.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L98" class="LineNr"> 98 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L99" class="LineNr"> 99 </span> <span class="Delimiter">}</span> -<span id="L100" class="LineNr">100 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>flags & O_RDONLY<span class="Delimiter">)</span> && <span class="Delimiter">(</span>flags & O_WRONLY<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L101" class="LineNr">101 </span> cerr << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": can't open a file for both reading and writing at once. See <a href="http://man7.org/linux/man-pages/man2/open.2.html">http://man7.org/linux/man-pages/man2/open.2.html</a>.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L102" class="LineNr">102 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L103" class="LineNr">103 </span> <span class="Delimiter">}</span> -<span id="L104" class="LineNr">104 </span><span class="Delimiter">}</span> -<span id="L105" class="LineNr">105 </span> -<span id="L106" class="LineNr">106 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L106'>check_mode</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L107" class="LineNr">107 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>Reg[reg]<span class="Delimiter">.</span>u != <span class="PreProc">0</span><span class="Constant">600</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L108" class="LineNr">108 </span> cerr << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": SubX is oblivious to file permissions; register "</span> << <a href='010---vm.cc.html#L23'>reg</a> << <span class="Constant">" must be 0.</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> -<span id="L109" class="LineNr">109 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L110" class="LineNr">110 </span> <span class="Delimiter">}</span> -<span id="L111" class="LineNr">111 </span><span class="Delimiter">}</span> -<span id="L112" class="LineNr">112 </span> -<span id="L113" class="LineNr">113 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L114" class="LineNr">114 </span><span class="Normal">uint32_t</span> <a href='020syscalls.cc.html#L114'>Next_segment</a> = <span class="Constant">0xb0000000</span><span class="Delimiter">;</span> <span class="Comment">// 0xc0000000 and up is reserved for Linux kernel</span> -<span id="L115" class="LineNr">115 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='020syscalls.cc.html#L115'>SPACE_FOR_SEGMENT</a> = <span class="Constant">0x01000000</span><span class="Delimiter">;</span> -<span id="L116" class="LineNr">116 </span><span class="Delimiter">:(code)</span> -<span id="L117" class="LineNr">117 </span><span class="Normal">uint32_t</span> <a href='020syscalls.cc.html#L117'>new_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> length<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L118" class="LineNr">118 </span> <span class="Normal">uint32_t</span> result = <a href='020syscalls.cc.html#L114'>Next_segment</a><span class="Delimiter">;</span> -<span id="L119" class="LineNr">119 </span> <a href='010---vm.cc.html#L171'>Mem</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><a href='020syscalls.cc.html#L114'>Next_segment</a><span class="Delimiter">,</span> Next_segment+length<span class="Delimiter">));</span> -<span id="L120" class="LineNr">120 </span> <a href='020syscalls.cc.html#L114'>Next_segment</a> -= <a href='020syscalls.cc.html#L115'>SPACE_FOR_SEGMENT</a><span class="Delimiter">;</span> -<span id="L121" class="LineNr">121 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> -<span id="L122" class="LineNr">122 </span><span class="Delimiter">}</span> +<span id="L24" class="LineNr"> 24 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"read: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = read<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Normal">case</span> <span class="Constant">4</span>: +<span id="L30" class="LineNr"> 30 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"write: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L31" class="LineNr"> 31 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L255'>mem_addr_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = write<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">memory buffer</span><span class="Comment">*/</span><a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">size</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EDX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L33" class="LineNr"> 33 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Normal">case</span> <span class="Constant">5</span>: <span class="Delimiter">{</span> +<span id="L37" class="LineNr"> 37 </span> <a href='020syscalls.cc.html#L93'>check_flags</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L14'>ECX</a><span class="Delimiter">);</span> +<span id="L38" class="LineNr"> 38 </span> <a href='020syscalls.cc.html#L105'>check_mode</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L15'>EDX</a><span class="Delimiter">);</span> +<span id="L39" class="LineNr"> 39 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"open: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">' '</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L40" class="LineNr"> 40 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = open<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">flags</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> +<span id="L42" class="LineNr"> 42 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Delimiter">}</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Normal">case</span> <span class="Constant">6</span>: +<span id="L47" class="LineNr"> 47 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"close: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = close<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">file descriptor</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Normal">case</span> <span class="Constant">8</span>: +<span id="L53" class="LineNr"> 53 </span> <a href='020syscalls.cc.html#L105'>check_mode</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L14'>ECX</a><span class="Delimiter">);</span> +<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"creat: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L55" class="LineNr"> 55 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = creat<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">mode</span><span class="Comment">*/</span><span class="PreProc">0</span><span class="Constant">640</span><span class="Delimiter">);</span> +<span id="L57" class="LineNr"> 57 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Normal">case</span> <span class="Constant">10</span>: +<span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"unlink: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L62" class="LineNr"> 62 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = unlink<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> +<span id="L64" class="LineNr"> 64 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Normal">case</span> <span class="Constant">38</span>: +<span id="L68" class="LineNr"> 68 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"rename: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" -> "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L69" class="LineNr"> 69 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L70" class="LineNr"> 70 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u << <span class="Constant">" => "</span> << <a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i = rename<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">old filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">),</span> <span class="Comment">/*</span><span class="Comment">new filename</span><span class="Comment">*/</span><a href='010---vm.cc.html#L252'>mem_addr_kernel_string</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[ECX]<span class="Delimiter">.</span>u<span class="Delimiter">));</span> +<span id="L72" class="LineNr"> 72 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i << end<span class="Delimiter">();</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>i == -<span class="Constant">1</span><span class="Delimiter">)</span> <a href='003trace.cc.html#L210'>raise</a> << strerror<span class="Delimiter">(</span>errno<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Normal">case</span> <span class="Constant">45</span>: <span class="Comment">// brk: modify size of data segment</span> +<span id="L76" class="LineNr"> 76 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"grow data segment to "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L77" class="LineNr"> 77 </span> <a href='010---vm.cc.html#L189'>grow_data_segment</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">new end address</span><span class="Comment">*/</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u<span class="Delimiter">);</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Normal">case</span> <span class="Constant">90</span>: <span class="Comment">// mmap: allocate memory outside existing segment allocations</span> +<span id="L80" class="LineNr"> 80 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"mmap: allocate new segment"</span> << end<span class="Delimiter">();</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Comment">// Ignore most arguments for now: address hint, protection flags, sharing flags, fd, offset.</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Comment">// We only support anonymous maps.</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u = <a href='020syscalls.cc.html#L116'>new_segment</a><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">length</span><span class="Comment">*/</span><a href='010---vm.cc.html#L209'>read_mem_u32</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EBX]<span class="Delimiter">.</span>u+<span class="Constant">0x4</span><span class="Delimiter">));</span> +<span id="L84" class="LineNr"> 84 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">91</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"result: "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Normal">default</span>: +<span id="L87" class="LineNr"> 87 </span> <a href='003trace.cc.html#L210'>raise</a> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": unimplemented syscall "</span> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[EAX]<span class="Delimiter">.</span>u << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Delimiter">}</span> +<span id="L89" class="LineNr"> 89 </span><span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> +<span id="L91" class="LineNr"> 91 </span><span class="Comment">// SubX is oblivious to file permissions, directories, symbolic links, terminals, and much else besides.</span> +<span id="L92" class="LineNr"> 92 </span><span class="Comment">// Also ignoring any concurrency considerations for now.</span> +<span id="L93" class="LineNr"> 93 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L93'>check_flags</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Normal">uint32_t</span> flags = <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u<span class="Delimiter">;</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>flags != <span class="Delimiter">((</span>flags & O_RDONLY<span class="Delimiter">)</span> | <span class="Delimiter">(</span>flags & O_WRONLY<span class="Delimiter">)))</span> <span class="Delimiter">{</span> +<span id="L96" class="LineNr"> 96 </span> cerr << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": most POSIX flags to the open() syscall are not supported. Just O_RDONLY and O_WRONLY for now. Zero concurrent access support.\n"</span><span class="Delimiter">;</span> +<span id="L97" class="LineNr"> 97 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Delimiter">}</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>flags & O_RDONLY<span class="Delimiter">)</span> && <span class="Delimiter">(</span>flags & O_WRONLY<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L100" class="LineNr">100 </span> cerr << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": can't open a file for both reading and writing at once. See <a href="http://man7.org/linux/man-pages/man2/open.2.html">http://man7.org/linux/man-pages/man2/open.2.html</a>.\n"</span><span class="Delimiter">;</span> +<span id="L101" class="LineNr">101 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L102" class="LineNr">102 </span> <span class="Delimiter">}</span> +<span id="L103" class="LineNr">103 </span><span class="Delimiter">}</span> +<span id="L104" class="LineNr">104 </span> +<span id="L105" class="LineNr">105 </span><span class="Normal">void</span> <a href='020syscalls.cc.html#L105'>check_mode</a><span class="Delimiter">(</span><span class="Normal">int</span> <a href='010---vm.cc.html#L23'>reg</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L106" class="LineNr">106 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[reg]<span class="Delimiter">.</span>u != <span class="PreProc">0</span><span class="Constant">600</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L107" class="LineNr">107 </span> cerr << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <a href='010---vm.cc.html#L29'>EIP</a> << <span class="Constant">": SubX is oblivious to file permissions; register "</span> << <a href='010---vm.cc.html#L23'>reg</a> << <span class="Constant">" must be 0.\n"</span><span class="Delimiter">;</span> +<span id="L108" class="LineNr">108 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> <span class="Delimiter">}</span> +<span id="L110" class="LineNr">110 </span><span class="Delimiter">}</span> +<span id="L111" class="LineNr">111 </span> +<span id="L112" class="LineNr">112 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L113" class="LineNr">113 </span><span class="Normal">uint32_t</span> <span class="Special"><a href='020syscalls.cc.html#L113'>Next_segment</a></span> = <span class="Constant">0xb0000000</span><span class="Delimiter">;</span> <span class="Comment">// 0xc0000000 and up is reserved for Linux kernel</span> +<span id="L114" class="LineNr">114 </span><span class="Normal">const</span> <span class="Normal">uint32_t</span> <a href='020syscalls.cc.html#L114'>SPACE_FOR_SEGMENT</a> = <span class="Constant">0x01000000</span><span class="Delimiter">;</span> +<span id="L115" class="LineNr">115 </span><span class="Delimiter">:(code)</span> +<span id="L116" class="LineNr">116 </span><span class="Normal">uint32_t</span> <a href='020syscalls.cc.html#L116'>new_segment</a><span class="Delimiter">(</span><span class="Normal">uint32_t</span> length<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L117" class="LineNr">117 </span> <span class="Normal">uint32_t</span> result = <span class="Special"><a href='020syscalls.cc.html#L113'>Next_segment</a></span><span class="Delimiter">;</span> +<span id="L118" class="LineNr">118 </span> <span class="Special"><a href='010---vm.cc.html#L180'>Mem</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>vma<span class="Delimiter">(</span><span class="Special"><a href='020syscalls.cc.html#L113'>Next_segment</a></span><span class="Delimiter">,</span> <span class="Special"><a href='020syscalls.cc.html#L113'>Next_segment</a></span>+length<span class="Delimiter">));</span> +<span id="L119" class="LineNr">119 </span> <span class="Special"><a href='020syscalls.cc.html#L113'>Next_segment</a></span> -= <a href='020syscalls.cc.html#L114'>SPACE_FOR_SEGMENT</a><span class="Delimiter">;</span> +<span id="L120" class="LineNr">120 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> +<span id="L121" class="LineNr">121 </span><span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/subx/021byte_addressing.cc.html b/html/subx/021byte_addressing.cc.html index a6b00dc7..f9f9e055 100644 --- a/html/subx/021byte_addressing.cc.html +++ b/html/subx/021byte_addressing.cc.html @@ -88,18 +88,18 @@ if ('onhashchange' in window) { <span id="L27" class="LineNr"> 27 </span> <span class="Identifier">return</span> <a href='021byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span>rm<span class="Delimiter">);</span> <span id="L28" class="LineNr"> 28 </span> <span class="Delimiter">}</span> <span id="L29" class="LineNr"> 29 </span> <span class="Comment">// the rest is as usual</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L208'>mem_addr_u8</a><span class="Delimiter">(</span><a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Identifier">return</span> <a href='010---vm.cc.html#L217'>mem_addr_u8</a><span class="Delimiter">(</span><a href='013direct_addressing.cc.html#L43'>effective_address_number</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> <span id="L31" class="LineNr"> 31 </span><span class="Delimiter">}</span> <span id="L32" class="LineNr"> 32 </span> <span id="L33" class="LineNr"> 33 </span><span class="Normal">uint8_t</span>* <a href='021byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> rm<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L34" class="LineNr"> 34 </span> <span class="Normal">uint8_t</span>* result = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint8_t</span>*><span class="Delimiter">(</span>&Reg[rm & <span class="Constant">0x3</span>]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> <span class="Comment">// _L register</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Normal">uint8_t</span>* result = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint8_t</span>*><span class="Delimiter">(</span>&<span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rm & <span class="Constant">0x3</span>]<span class="Delimiter">.</span>i<span class="Delimiter">);</span> <span class="Comment">// _L register</span> <span id="L35" class="LineNr"> 35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>rm & <span class="Constant">0x4</span><span class="Delimiter">)</span> <span id="L36" class="LineNr"> 36 </span> ++result<span class="Delimiter">;</span> <span class="Comment">// _H register; assumes host is little-endian</span> <span id="L37" class="LineNr"> 37 </span> <span class="Identifier">return</span> result<span class="Delimiter">;</span> <span id="L38" class="LineNr"> 38 </span><span class="Delimiter">}</span> <span id="L39" class="LineNr"> 39 </span> <span id="L40" class="LineNr"> 40 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L41" class="LineNr"> 41 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"88"</span><span class="Delimiter">,</span> <span class="Constant">"copy r8 to r8/m8-at-r32"</span><span class="Delimiter">);</span> +<span id="L41" class="LineNr"> 41 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"88"</span><span class="Delimiter">,</span> <span class="Constant">"copy r8 to r8/m8-at-r32"</span><span class="Delimiter">);</span> <span id="L42" class="LineNr"> 42 </span> <span id="L43" class="LineNr"> 43 </span><span class="Delimiter">:(scenario copy_r8_to_mem_at_r32)</span> <span id="L44" class="LineNr"> 44 </span><span class="Special">% Reg[EBX].i = 0x224488ab;</span> @@ -117,21 +117,21 @@ if ('onhashchange' in window) { <span id="L56" class="LineNr"> 56 </span> <span id="L57" class="LineNr"> 57 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L58" class="LineNr"> 58 </span><span class="Normal">case</span> <span class="Constant">0x88</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r8 to r/m8</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L60" class="LineNr"> 60 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rsrc = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L61" class="LineNr"> 61 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy "</span> << <a href='021byte_addressing.cc.html#L7'>rname_8bit</a><span class="Delimiter">(</span>rsrc<span class="Delimiter">)</span> << <span class="Constant">" to r8/m8-at-r32"</span> << end<span class="Delimiter">();</span> <span id="L62" class="LineNr"> 62 </span> <span class="Comment">// use unsigned to zero-extend 8-bit value to 32 bits</span> <span id="L63" class="LineNr"> 63 </span> <span class="Normal">uint8_t</span>* dest = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint8_t</span>*><span class="Delimiter">(</span><a href='021byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> <span id="L64" class="LineNr"> 64 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span>* src = <a href='021byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span>rsrc<span class="Delimiter">);</span> <span id="L65" class="LineNr"> 65 </span> *dest = *src<span class="Delimiter">;</span> -<span id="L66" class="LineNr"> 66 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L66" class="LineNr"> 66 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>*dest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L67" class="LineNr"> 67 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L68" class="LineNr"> 68 </span><span class="Delimiter">}</span> <span id="L69" class="LineNr"> 69 </span> <span id="L70" class="LineNr"> 70 </span><span class="Comment">//:</span> <span id="L71" class="LineNr"> 71 </span> <span id="L72" class="LineNr"> 72 </span><span class="Delimiter">:(before "End Initialize Op Names")</span> -<span id="L73" class="LineNr"> 73 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> <span class="Constant">"8a"</span><span class="Delimiter">,</span> <span class="Constant">"copy r8/m8-at-r32 to r8"</span><span class="Delimiter">);</span> +<span id="L73" class="LineNr"> 73 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> <span class="Constant">"8a"</span><span class="Delimiter">,</span> <span class="Constant">"copy r8/m8-at-r32 to r8"</span><span class="Delimiter">);</span> <span id="L74" class="LineNr"> 74 </span> <span id="L75" class="LineNr"> 75 </span><span class="Delimiter">:(scenario copy_mem_at_r32_to_r8)</span> <span id="L76" class="LineNr"> 76 </span><span class="Special">% Reg[EBX].i = 0xaabbcc0f; // one nibble each of lowest byte set to all 0s and all 1s, to maximize value of this test</span> @@ -150,16 +150,16 @@ if ('onhashchange' in window) { <span id="L89" class="LineNr"> 89 </span> <span id="L90" class="LineNr"> 90 </span><span class="Delimiter">:(before "End Single-Byte Opcodes")</span> <span id="L91" class="LineNr"> 91 </span><span class="Normal">case</span> <span class="Constant">0x8a</span>: <span class="Delimiter">{</span> <span class="Comment">// copy r/m8 to r8</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L355'>next</a><span class="Delimiter">();</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> modrm = <a href='010---vm.cc.html#L364'>next</a><span class="Delimiter">();</span> <span id="L93" class="LineNr"> 93 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest = <span class="Delimiter">(</span>modrm>><span class="Constant">3</span><span class="Delimiter">)</span>&<span class="Constant">0x7</span><span class="Delimiter">;</span> <span id="L94" class="LineNr"> 94 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"copy r8/m8-at-r32 to "</span> << <a href='021byte_addressing.cc.html#L7'>rname_8bit</a><span class="Delimiter">(</span>rdest<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L95" class="LineNr"> 95 </span> <span class="Comment">// use unsigned to zero-extend 8-bit value to 32 bits</span> <span id="L96" class="LineNr"> 96 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span>* src = <span class="Normal">reinterpret_cast</span><<span class="Normal">uint8_t</span>*><span class="Delimiter">(</span><a href='021byte_addressing.cc.html#L21'>effective_byte_address</a><span class="Delimiter">(</span>modrm<span class="Delimiter">));</span> <span id="L97" class="LineNr"> 97 </span> <span class="Normal">uint8_t</span>* dest = <a href='021byte_addressing.cc.html#L33'>reg_8bit</a><span class="Delimiter">(</span>rdest<span class="Delimiter">);</span> -<span id="L98" class="LineNr"> 98 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>*src<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L98" class="LineNr"> 98 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"storing 0x"</span> << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>*src<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> <span id="L99" class="LineNr"> 99 </span> *dest = *src<span class="Delimiter">;</span> <span id="L100" class="LineNr">100 </span> <span class="Normal">const</span> <span class="Normal">uint8_t</span> rdest_32bit = rdest & <span class="Constant">0x3</span><span class="Delimiter">;</span> -<span id="L101" class="LineNr">101 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rdest_32bit<span class="Delimiter">)</span> << <span class="Constant">" now contains 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << Reg[rdest_32bit]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> +<span id="L101" class="LineNr">101 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <a href='013direct_addressing.cc.html#L62'>rname</a><span class="Delimiter">(</span>rdest_32bit<span class="Delimiter">)</span> << <span class="Constant">" now contains 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Special"><a href='010---vm.cc.html#L28'>Reg</a></span>[rdest_32bit]<span class="Delimiter">.</span>u << end<span class="Delimiter">();</span> <span id="L102" class="LineNr">102 </span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span id="L103" class="LineNr">103 </span><span class="Delimiter">}</span> <span id="L104" class="LineNr">104 </span> diff --git a/html/subx/028translate.cc.html b/html/subx/028translate.cc.html index 2745d059..ccd31900 100644 --- a/html/subx/028translate.cc.html +++ b/html/subx/028translate.cc.html @@ -17,6 +17,7 @@ a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } +.Special { color: #c00000; } .Delimiter { color: #800080; } .SalientComment { color: #00ffff; } .Identifier { color: #c0a020; } @@ -88,7 +89,7 @@ if ('onhashchange' in window) { <span id="L28" class="LineNr"> 28 </span> ++i<span class="Delimiter">;</span> <span id="L29" class="LineNr"> 29 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i >= argc<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L30" class="LineNr"> 30 </span> <a href='028translate.cc.html#L68'>print_translate_usage</a><span class="Delimiter">();</span> -<span id="L31" class="LineNr"> 31 </span> cerr << <span class="Constant">"'-o' must be followed by a filename to write results to</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L31" class="LineNr"> 31 </span> cerr << <span class="Constant">"'-o' must be followed by a filename to write results to\n"</span><span class="Delimiter">;</span> <span id="L32" class="LineNr"> 32 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L33" class="LineNr"> 33 </span> <span class="Delimiter">}</span> <span id="L34" class="LineNr"> 34 </span> output_filename = argv[i]<span class="Delimiter">;</span> @@ -105,12 +106,12 @@ if ('onhashchange' in window) { <span id="L45" class="LineNr"> 45 </span> <span class="Delimiter">}</span> <span id="L46" class="LineNr"> 46 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span id="L47" class="LineNr"> 47 </span> <a href='028translate.cc.html#L68'>print_translate_usage</a><span class="Delimiter">();</span> -<span id="L48" class="LineNr"> 48 </span> cerr << <span class="Constant">"nothing to do; must provide at least one file to read</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L48" class="LineNr"> 48 </span> cerr << <span class="Constant">"nothing to do; must provide at least one file to read\n"</span><span class="Delimiter">;</span> <span id="L49" class="LineNr"> 49 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L50" class="LineNr"> 50 </span> <span class="Delimiter">}</span> <span id="L51" class="LineNr"> 51 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>output_filename<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> <span id="L52" class="LineNr"> 52 </span> <a href='028translate.cc.html#L68'>print_translate_usage</a><span class="Delimiter">();</span> -<span id="L53" class="LineNr"> 53 </span> cerr << <span class="Constant">"must provide a filename to write to using '-o'</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L53" class="LineNr"> 53 </span> cerr << <span class="Constant">"must provide a filename to write to using '-o'\n"</span><span class="Delimiter">;</span> <span id="L54" class="LineNr"> 54 </span> exit<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">);</span> <span id="L55" class="LineNr"> 55 </span> <span class="Delimiter">}</span> <span id="L56" class="LineNr"> 56 </span> <a href='011run.cc.html#L231'>transform</a><span class="Delimiter">(</span>p<span class="Delimiter">);</span> @@ -126,7 +127,7 @@ if ('onhashchange' in window) { <span id="L66" class="LineNr"> 66 </span> <span id="L67" class="LineNr"> 67 </span><span class="Delimiter">:(code)</span> <span id="L68" class="LineNr"> 68 </span><span class="Normal">void</span> <a href='028translate.cc.html#L68'>print_translate_usage</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L69" class="LineNr"> 69 </span> cerr << <span class="Constant">"Usage: subx translate file1 file2 ... -o output</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L69" class="LineNr"> 69 </span> cerr << <span class="Constant">"Usage: subx translate file1 file2 ... -o output\n"</span><span class="Delimiter">;</span> <span id="L70" class="LineNr"> 70 </span><span class="Delimiter">}</span> <span id="L71" class="LineNr"> 71 </span> <span id="L72" class="LineNr"> 72 </span><span class="Comment">// write out a program to a bare-bones ELF file</span> @@ -145,17 +146,17 @@ if ('onhashchange' in window) { <span id="L85" class="LineNr"> 85 </span><span class="Comment">#define emit(X) out.write(reinterpret_cast<const char*>(&X), sizeof(X))</span> <span id="L86" class="LineNr"> 86 </span> <span class="SalientComment">//// ehdr</span> <span id="L87" class="LineNr"> 87 </span> <span class="Comment">// e_ident</span> -<span id="L88" class="LineNr"> 88 </span> O<span class="Delimiter">(</span><span class="Constant">0x7f</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">E</span><span class="Comment">*/</span><span class="Constant">0x45</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">L</span><span class="Comment">*/</span><span class="Constant">0x4c</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">F</span><span class="Comment">*/</span><span class="Constant">0x46</span><span class="Delimiter">);</span> -<span id="L89" class="LineNr"> 89 </span> O<span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Comment">// 32-bit format</span> -<span id="L90" class="LineNr"> 90 </span> O<span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Comment">// little-endian</span> -<span id="L91" class="LineNr"> 91 </span> O<span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x0</span><span class="Delimiter">);</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Constant">8</span><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> O<span class="Delimiter">(</span><span class="Constant">0x0</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x7f</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">E</span><span class="Comment">*/</span><span class="Constant">0x45</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">L</span><span class="Comment">*/</span><span class="Constant">0x4c</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">F</span><span class="Comment">*/</span><span class="Constant">0x46</span><span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Comment">// 32-bit format</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Comment">// little-endian</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x1</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x0</span><span class="Delimiter">);</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">size_t</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <span class="Constant">8</span><span class="Delimiter">;</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x0</span><span class="Delimiter">);</span> <span class="Delimiter">}</span> <span id="L93" class="LineNr"> 93 </span> <span class="Comment">// e_type</span> -<span id="L94" class="LineNr"> 94 </span> O<span class="Delimiter">(</span><span class="Constant">0x02</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x02</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L95" class="LineNr"> 95 </span> <span class="Comment">// e_machine</span> -<span id="L96" class="LineNr"> 96 </span> O<span class="Delimiter">(</span><span class="Constant">0x03</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L97" class="LineNr"> 97 </span> <span class="Comment">// e_version</span> -<span id="L98" class="LineNr"> 98 </span> O<span class="Delimiter">(</span><span class="Constant">0x01</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> O<span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x01</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> <span class="Special">O</span><span class="Delimiter">(</span><span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L99" class="LineNr"> 99 </span> <span class="Comment">// e_entry</span> <span id="L100" class="LineNr">100 </span> <span class="Normal">int</span> e_entry = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>start<span class="Delimiter">;</span> <span class="Comment">// convention</span> <span id="L101" class="LineNr">101 </span> emit<span class="Delimiter">(</span>e_entry<span class="Delimiter">);</span> @@ -199,7 +200,7 @@ if ('onhashchange' in window) { <span id="L139" class="LineNr">139 </span> emit<span class="Delimiter">(</span>p_start<span class="Delimiter">);</span> <span id="L140" class="LineNr">140 </span> <span class="Comment">// p_filesz</span> <span id="L141" class="LineNr">141 </span> <span class="Normal">uint32_t</span> size = <a href='028translate.cc.html#L185'>num_words</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> -<span id="L142" class="LineNr">142 </span> assert<span class="Delimiter">(</span>p_offset + size < <a href='010---vm.cc.html#L115'>INITIAL_SEGMENT_SIZE</a><span class="Delimiter">);</span> +<span id="L142" class="LineNr">142 </span> assert<span class="Delimiter">(</span>p_offset + size < <a href='010---vm.cc.html#L115'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> <span id="L143" class="LineNr">143 </span> emit<span class="Delimiter">(</span>size<span class="Delimiter">);</span> <span id="L144" class="LineNr">144 </span> <span class="Comment">// p_memsz</span> <span id="L145" class="LineNr">145 </span> emit<span class="Delimiter">(</span>size<span class="Delimiter">);</span> @@ -221,7 +222,7 @@ if ('onhashchange' in window) { <span id="L161" class="LineNr">161 </span> <span class="Normal">uint32_t</span> p_align = <span class="Constant">0x1000</span><span class="Delimiter">;</span> <span class="Comment">// default page size on linux</span> <span id="L162" class="LineNr">162 </span> emit<span class="Delimiter">(</span>p_align<span class="Delimiter">);</span> <span id="L163" class="LineNr">163 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p_offset % p_align != p_start % p_align<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L164" class="LineNr">164 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"segment starting at 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << p_start << <span class="Constant">" is improperly aligned; alignment for p_offset "</span> << p_offset << <span class="Constant">" should be "</span> << <span class="Delimiter">(</span>p_offset % p_align<span class="Delimiter">)</span> << <span class="Constant">" but is "</span> << <span class="Delimiter">(</span>p_start % p_align<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> +<span id="L164" class="LineNr">164 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"segment starting at 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << p_start << <span class="Constant">" is improperly aligned; alignment for p_offset "</span> << p_offset << <span class="Constant">" should be "</span> << <span class="Delimiter">(</span>p_offset % p_align<span class="Delimiter">)</span> << <span class="Constant">" but is "</span> << <span class="Delimiter">(</span>p_start % p_align<span class="Delimiter">)</span> << <span class="cSpecial">'\n'</span> << end<span class="Delimiter">();</span> <span id="L165" class="LineNr">165 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L166" class="LineNr">166 </span> <span class="Delimiter">}</span> <span id="L167" class="LineNr">167 </span> diff --git a/html/subx/030---operands.cc.html b/html/subx/030---operands.cc.html index 7d9e6635..cf670140 100644 --- a/html/subx/030---operands.cc.html +++ b/html/subx/030---operands.cc.html @@ -15,7 +15,6 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } -.traceContains { color: #008000; } .Identifier { color: #c0a020; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } @@ -25,7 +24,7 @@ a:hover { text-decoration: underline; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.cSpecial { color: #008000; } +.traceContains { color: #008000; } --> </style> @@ -75,19 +74,19 @@ if ('onhashchange' in window) { <span id="L13" class="LineNr"> 13 </span><span class="Comment">//: pack and order the bytes corresponding to the operands in an instruction.</span> <span id="L14" class="LineNr"> 14 </span> <span id="L15" class="LineNr"> 15 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> -<span id="L16" class="LineNr"> 16 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"instructions"</span><span class="Delimiter">,</span> -<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"Each x86 instruction consists of an instruction or opcode and some number</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"of operands.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"Each operand has a type. An instruction won't have more than one operand of</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"any type.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"Each instruction has some set of allowed operand types. It'll reject others.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"The complete list of operand <a href='031check_operands.cc.html#L431'>types</a>: mod, subop, r32 (register), rm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"(register or memory), scale, index, base, disp8, disp16, disp32, imm8,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"imm32.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"Each of these has its own help page. Try reading 'subx help mod' next.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L16" class="LineNr"> 16 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"instructions"</span><span class="Delimiter">,</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Constant">"Each x86 instruction consists of an instruction or opcode and some number\n"</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Constant">"of operands.\n"</span> +<span id="L19" class="LineNr"> 19 </span> <span class="Constant">"Each operand has a type. An instruction won't have more than one operand of\n"</span> +<span id="L20" class="LineNr"> 20 </span> <span class="Constant">"any type.\n"</span> +<span id="L21" class="LineNr"> 21 </span> <span class="Constant">"Each instruction has some set of allowed operand types. It'll reject others.\n"</span> +<span id="L22" class="LineNr"> 22 </span> <span class="Constant">"The complete list of operand <a href='031check_operands.cc.html#L427'>types</a>: mod, subop, r32 (register), rm32\n"</span> +<span id="L23" class="LineNr"> 23 </span> <span class="Constant">"(register or memory), scale, index, base, disp8, disp16, disp32, imm8,\n"</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Constant">"imm32.\n"</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Constant">"Each of these has its own help page. Try reading 'subx help mod' next.\n"</span> <span id="L26" class="LineNr"> 26 </span><span class="Delimiter">);</span> <span id="L27" class="LineNr"> 27 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Contents")</span> -<span id="L28" class="LineNr"> 28 </span>cerr << <span class="Constant">" instructions</span><span class="cSpecial">\n</span><span class="Constant">"</span><span class="Delimiter">;</span> +<span id="L28" class="LineNr"> 28 </span>cerr << <span class="Constant">" instructions\n"</span><span class="Delimiter">;</span> <span id="L29" class="LineNr"> 29 </span> <span id="L30" class="LineNr"> 30 </span><span class="Delimiter">:(scenario pack_immediate_constants)</span> <span id="L31" class="LineNr"> 31 </span>== <span class="Constant">0x1</span> @@ -99,110 +98,110 @@ if ('onhashchange' in window) { <span id="L37" class="LineNr"> 37 </span><span class="Comment">//: complete set of valid operand types</span> <span id="L38" class="LineNr"> 38 </span> <span id="L39" class="LineNr"> 39 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L40" class="LineNr"> 40 </span>set<string> <a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">;</span> +<span id="L40" class="LineNr"> 40 </span>set<string> <span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">;</span> <span id="L41" class="LineNr"> 41 </span><span class="Delimiter">:(before "End One-time Setup")</span> -<span id="L42" class="LineNr"> 42 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"subop"</span><span class="Delimiter">);</span> -<span id="L43" class="LineNr"> 43 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"mod"</span><span class="Delimiter">);</span> -<span id="L44" class="LineNr"> 44 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"rm32"</span><span class="Delimiter">);</span> -<span id="L45" class="LineNr"> 45 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"base"</span><span class="Delimiter">);</span> -<span id="L46" class="LineNr"> 46 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"index"</span><span class="Delimiter">);</span> -<span id="L47" class="LineNr"> 47 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"scale"</span><span class="Delimiter">);</span> -<span id="L48" class="LineNr"> 48 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"r32"</span><span class="Delimiter">);</span> -<span id="L49" class="LineNr"> 49 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp8"</span><span class="Delimiter">);</span> -<span id="L50" class="LineNr"> 50 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp16"</span><span class="Delimiter">);</span> -<span id="L51" class="LineNr"> 51 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp32"</span><span class="Delimiter">);</span> -<span id="L52" class="LineNr"> 52 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"imm8"</span><span class="Delimiter">);</span> -<span id="L53" class="LineNr"> 53 </span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"imm32"</span><span class="Delimiter">);</span> +<span id="L42" class="LineNr"> 42 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"subop"</span><span class="Delimiter">);</span> +<span id="L43" class="LineNr"> 43 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"mod"</span><span class="Delimiter">);</span> +<span id="L44" class="LineNr"> 44 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"rm32"</span><span class="Delimiter">);</span> +<span id="L45" class="LineNr"> 45 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"base"</span><span class="Delimiter">);</span> +<span id="L46" class="LineNr"> 46 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"index"</span><span class="Delimiter">);</span> +<span id="L47" class="LineNr"> 47 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"scale"</span><span class="Delimiter">);</span> +<span id="L48" class="LineNr"> 48 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"r32"</span><span class="Delimiter">);</span> +<span id="L49" class="LineNr"> 49 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp8"</span><span class="Delimiter">);</span> +<span id="L50" class="LineNr"> 50 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp16"</span><span class="Delimiter">);</span> +<span id="L51" class="LineNr"> 51 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"disp32"</span><span class="Delimiter">);</span> +<span id="L52" class="LineNr"> 52 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"imm8"</span><span class="Delimiter">);</span> +<span id="L53" class="LineNr"> 53 </span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>insert<span class="Delimiter">(</span><span class="Constant">"imm32"</span><span class="Delimiter">);</span> <span id="L54" class="LineNr"> 54 </span> <span id="L55" class="LineNr"> 55 </span><span class="Delimiter">:(before "End <a href='001help.cc.html#L53'>Help</a> Texts")</span> <span id="L56" class="LineNr"> 56 </span><a href='030---operands.cc.html#L58'>init_operand_type_help</a><span class="Delimiter">();</span> <span id="L57" class="LineNr"> 57 </span><span class="Delimiter">:(code)</span> <span id="L58" class="LineNr"> 58 </span><span class="Normal">void</span> <a href='030---operands.cc.html#L58'>init_operand_type_help</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L59" class="LineNr"> 59 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Constant">"2-bit operand controlling the _addressing mode_ of many instructions,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"to determine how to compute the _effective address_ to look up memory at</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"based on the 'rm32' operand and potentially others.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"If mod = 3, just operate on the <a href='003trace.cc.html#L74'>contents</a> of the register specified by rm32</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Constant">" (direct mode).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"If mod = 2, effective address is usually* rm32 + disp32</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Constant">" (indirect mode with displacement).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"If mod = 1, effective address is usually* rm32 + disp8</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L69" class="LineNr"> 69 </span> <span class="Constant">" (indirect mode with displacement).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"If mod = 0, effective address is usually* rm32 (indirect mode).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L71" class="LineNr"> 71 </span> <span class="Constant">"(* - The exception is when rm32 is '4'. Register 4 is the stack pointer (ESP).</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Constant">" Using it as an address gets more involved. For more details,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Constant">" try reading the help pages for 'base', 'index' and 'scale'.)</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Constant">"developer's manual that are also included in this repo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L77" class="LineNr"> 77 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the ModR/M byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L78" class="LineNr"> 78 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L59" class="LineNr"> 59 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Constant">"2-bit operand controlling the _addressing mode_ of many instructions,\n"</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Constant">"to determine how to compute the _effective address_ to look up memory at\n"</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Constant">"based on the 'rm32' operand and potentially others.\n"</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Constant">"\n"</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Constant">"If mod = 3, just operate on the <a href='003trace.cc.html#L74'>contents</a> of the register specified by rm32\n"</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Constant">" (direct mode).\n"</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Constant">"If mod = 2, effective address is usually* rm32 + disp32\n"</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Constant">" (indirect mode with displacement).\n"</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Constant">"If mod = 1, effective address is usually* rm32 + disp8\n"</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Constant">" (indirect mode with displacement).\n"</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Constant">"If mod = 0, effective address is usually* rm32 (indirect mode).\n"</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Constant">"(* - The exception is when rm32 is '4'. Register 4 is the stack pointer (ESP).\n"</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Constant">" Using it as an address gets more involved. For more details,\n"</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Constant">" try reading the help pages for 'base', 'index' and 'scale'.)\n"</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Constant">"\n"</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software\n"</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Constant">"developer's manual that are also included in this repo:\n"</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, \"</span><span class="Constant">32</span>-bit addressing with the ModR/<span class="Special">M</span> byte<span class="Delimiter">.</span>\<span class="Constant">".\n"</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, \"</span><span class="Constant">32</span>-bit addressing with the SIB byte<span class="Delimiter">.</span>\<span class="Constant">".\n"</span> <span id="L79" class="LineNr"> 79 </span> <span class="Delimiter">);</span> -<span id="L80" class="LineNr"> 80 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"Additional 3-bit operand for determining the instruction when the opcode is 81, 8f or ff.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"Can't coexist with operand of type 'r32' in a single instruction, because the two use the same bits.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L80" class="LineNr"> 80 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Constant">"Additional 3-bit operand for determining the instruction when the opcode is 81, 8f or ff.\n"</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Constant">"Can't coexist with operand of type 'r32' in a single instruction, because the two use the same bits.\n"</span> <span id="L83" class="LineNr"> 83 </span> <span class="Delimiter">);</span> -<span id="L84" class="LineNr"> 84 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> -<span id="L85" class="LineNr"> 85 </span> <span class="Constant">"3-bit operand specifying a register operand used directly, without any further addressing modes.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L84" class="LineNr"> 84 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Constant">"3-bit operand specifying a register operand used directly, without any further addressing modes.\n"</span> <span id="L86" class="LineNr"> 86 </span> <span class="Delimiter">);</span> -<span id="L87" class="LineNr"> 87 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> -<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"32-bit value in register or memory. The precise details of its construction</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"depend on the eponymous 3-bit 'rm32' operand, the 'mod' operand, and also</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L90" class="LineNr"> 90 </span> <span class="Constant">"potentially the 'SIB' operands ('scale', 'index' and 'base') and a displacement</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L91" class="LineNr"> 91 </span> <span class="Constant">"('disp8' or 'disp32').</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"developer's manual that are also included in this repo:</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the ModR/M byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L96" class="LineNr"> 96 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte.</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L87" class="LineNr"> 87 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Constant">"32-bit value in register or memory. The precise details of its construction\n"</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Constant">"depend on the eponymous 3-bit 'rm32' operand, the 'mod' operand, and also\n"</span> +<span id="L90" class="LineNr"> 90 </span> <span class="Constant">"potentially the 'SIB' operands ('scale', 'index' and 'base') and a displacement\n"</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Constant">"('disp8' or 'disp32').\n"</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Constant">"\n"</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Constant">"For complete details, spend some time with two tables in the IA-32 software\n"</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Constant">"developer's manual that are also included in this repo:\n"</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Constant">" - modrm.pdf: volume 2, table 2-2, \"</span><span class="Constant">32</span>-bit addressing with the ModR/<span class="Special">M</span> byte<span class="Delimiter">.</span>\<span class="Constant">".\n"</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Constant">" - sib.pdf: volume 2, table 2-3, \"</span><span class="Constant">32</span>-bit addressing with the SIB byte<span class="Delimiter">.</span>\<span class="Constant">".\n"</span> <span id="L97" class="LineNr"> 97 </span> <span class="Delimiter">);</span> -<span id="L98" class="LineNr"> 98 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> -<span id="L99" class="LineNr"> 99 </span> <span class="Constant">"Additional 3-bit operand (when 'rm32' is 4, unless 'mod' is 3) specifying the</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L100" class="LineNr">100 </span> <span class="Constant">"register containing an address to look up.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L101" class="LineNr">101 </span> <span class="Constant">"This address may be further modified by 'index' and 'scale' operands.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L102" class="LineNr">102 </span> <span class="Constant">" effective address = base + index*scale + displacement (disp8 or disp32)</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L103" class="LineNr">103 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L104" class="LineNr">104 </span> <span class="Constant">"volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L105" class="LineNr">105 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L98" class="LineNr"> 98 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Constant">"Additional 3-bit operand (when 'rm32' is 4, unless 'mod' is 3) specifying the\n"</span> +<span id="L100" class="LineNr">100 </span> <span class="Constant">"register containing an address to look up.\n"</span> +<span id="L101" class="LineNr">101 </span> <span class="Constant">"This address may be further modified by 'index' and 'scale' operands.\n"</span> +<span id="L102" class="LineNr">102 </span> <span class="Constant">" effective address = base + index*scale + displacement (disp8 or disp32)\n"</span> +<span id="L103" class="LineNr">103 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,\n"</span> +<span id="L104" class="LineNr">104 </span> <span class="Constant">"volume 2, table 2-3, \"</span><span class="Constant">32</span>-bit addressing with the SIB byte\<span class="Constant">".\n"</span> +<span id="L105" class="LineNr">105 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.\n"</span> <span id="L106" class="LineNr">106 </span> <span class="Delimiter">);</span> -<span id="L107" class="LineNr">107 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> -<span id="L108" class="LineNr">108 </span> <span class="Constant">"Optional 3-bit operand (when 'rm32' is 4 unless 'mod' is 3) that can be added to</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L109" class="LineNr">109 </span> <span class="Constant">"the 'base' operand to compute the 'effective address' at which to look up memory.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L110" class="LineNr">110 </span> <span class="Constant">" effective address = base + index*scale + displacement (disp8 or disp32)</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L111" class="LineNr">111 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L112" class="LineNr">112 </span> <span class="Constant">"volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L113" class="LineNr">113 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L107" class="LineNr">107 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> +<span id="L108" class="LineNr">108 </span> <span class="Constant">"Optional 3-bit operand (when 'rm32' is 4 unless 'mod' is 3) that can be added to\n"</span> +<span id="L109" class="LineNr">109 </span> <span class="Constant">"the 'base' operand to compute the 'effective address' at which to look up memory.\n"</span> +<span id="L110" class="LineNr">110 </span> <span class="Constant">" effective address = base + index*scale + displacement (disp8 or disp32)\n"</span> +<span id="L111" class="LineNr">111 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,\n"</span> +<span id="L112" class="LineNr">112 </span> <span class="Constant">"volume 2, table 2-3, \"</span><span class="Constant">32</span>-bit addressing with the SIB byte\<span class="Constant">".\n"</span> +<span id="L113" class="LineNr">113 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.\n"</span> <span id="L114" class="LineNr">114 </span> <span class="Delimiter">);</span> -<span id="L115" class="LineNr">115 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">,</span> -<span id="L116" class="LineNr">116 </span> <span class="Constant">"Optional 2-bit operand (when 'rm32' is 4 unless 'mod' is 3) that encodes a</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L117" class="LineNr">117 </span> <span class="Constant">"power of 2 to be multiplied to the 'index' operand before adding the result to</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L118" class="LineNr">118 </span> <span class="Constant">"the 'base' operand to compute the _effective address_ to operate on.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L119" class="LineNr">119 </span> <span class="Constant">" effective address = base + index * scale + displacement (disp8 or disp32)</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L120" class="LineNr">120 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L121" class="LineNr">121 </span> <span class="Constant">"When scale is 0, use index unmodified.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L122" class="LineNr">122 </span> <span class="Constant">"When scale is 1, multiply index by 2.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L123" class="LineNr">123 </span> <span class="Constant">"When scale is 2, multiply index by 4.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L124" class="LineNr">124 </span> <span class="Constant">"When scale is 3, multiply index by 8.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L125" class="LineNr">125 </span> <span class="Constant">"</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L126" class="LineNr">126 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L127" class="LineNr">127 </span> <span class="Constant">"volume 2, table 2-3, </span><span class="cSpecial">\"</span><span class="Constant">32-bit addressing with the SIB byte</span><span class="cSpecial">\"</span><span class="Constant">.</span><span class="cSpecial">\n</span><span class="Constant">"</span> -<span id="L128" class="LineNr">128 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L115" class="LineNr">115 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">,</span> +<span id="L116" class="LineNr">116 </span> <span class="Constant">"Optional 2-bit operand (when 'rm32' is 4 unless 'mod' is 3) that encodes a\n"</span> +<span id="L117" class="LineNr">117 </span> <span class="Constant">"power of 2 to be multiplied to the 'index' operand before adding the result to\n"</span> +<span id="L118" class="LineNr">118 </span> <span class="Constant">"the 'base' operand to compute the _effective address_ to operate on.\n"</span> +<span id="L119" class="LineNr">119 </span> <span class="Constant">" effective address = base + index * scale + displacement (disp8 or disp32)\n"</span> +<span id="L120" class="LineNr">120 </span> <span class="Constant">"\n"</span> +<span id="L121" class="LineNr">121 </span> <span class="Constant">"When scale is 0, use index unmodified.\n"</span> +<span id="L122" class="LineNr">122 </span> <span class="Constant">"When scale is 1, multiply index by 2.\n"</span> +<span id="L123" class="LineNr">123 </span> <span class="Constant">"When scale is 2, multiply index by 4.\n"</span> +<span id="L124" class="LineNr">124 </span> <span class="Constant">"When scale is 3, multiply index by 8.\n"</span> +<span id="L125" class="LineNr">125 </span> <span class="Constant">"\n"</span> +<span id="L126" class="LineNr">126 </span> <span class="Constant">"For complete details, spend some time with the IA-32 software developer's manual,\n"</span> +<span id="L127" class="LineNr">127 </span> <span class="Constant">"volume 2, table 2-3, \"</span><span class="Constant">32</span>-bit addressing with the SIB byte\<span class="Constant">".\n"</span> +<span id="L128" class="LineNr">128 </span> <span class="Constant">"It is included in this repository as 'sib.pdf'.\n"</span> <span id="L129" class="LineNr">129 </span> <span class="Delimiter">);</span> -<span id="L130" class="LineNr">130 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">,</span> -<span id="L131" class="LineNr">131 </span> <span class="Constant">"8-bit value to be added in many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L130" class="LineNr">130 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">,</span> +<span id="L131" class="LineNr">131 </span> <span class="Constant">"8-bit value to be added in many instructions.\n"</span> <span id="L132" class="LineNr">132 </span> <span class="Delimiter">);</span> -<span id="L133" class="LineNr">133 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">,</span> -<span id="L134" class="LineNr">134 </span> <span class="Constant">"16-bit value to be added in many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L133" class="LineNr">133 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">,</span> +<span id="L134" class="LineNr">134 </span> <span class="Constant">"16-bit value to be added in many instructions.\n"</span> <span id="L135" class="LineNr">135 </span> <span class="Delimiter">);</span> -<span id="L136" class="LineNr">136 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">,</span> -<span id="L137" class="LineNr">137 </span> <span class="Constant">"32-bit value to be added in many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L136" class="LineNr">136 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">,</span> +<span id="L137" class="LineNr">137 </span> <span class="Constant">"32-bit value to be added in many instructions.\n"</span> <span id="L138" class="LineNr">138 </span> <span class="Delimiter">);</span> -<span id="L139" class="LineNr">139 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">,</span> -<span id="L140" class="LineNr">140 </span> <span class="Constant">"8-bit value for many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L139" class="LineNr">139 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">,</span> +<span id="L140" class="LineNr">140 </span> <span class="Constant">"8-bit value for many instructions.\n"</span> <span id="L141" class="LineNr">141 </span> <span class="Delimiter">);</span> -<span id="L142" class="LineNr">142 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='001help.cc.html#L53'>Help</a><span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">,</span> -<span id="L143" class="LineNr">143 </span> <span class="Constant">"32-bit value for many instructions.</span><span class="cSpecial">\n</span><span class="Constant">"</span> +<span id="L142" class="LineNr">142 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='001help.cc.html#L53'>Help</a></span><span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">,</span> +<span id="L143" class="LineNr">143 </span> <span class="Constant">"32-bit value for many instructions.\n"</span> <span id="L144" class="LineNr">144 </span> <span class="Delimiter">);</span> <span id="L145" class="LineNr">145 </span><span class="Delimiter">}</span> <span id="L146" class="LineNr">146 </span> @@ -210,7 +209,7 @@ if ('onhashchange' in window) { <span id="L148" class="LineNr">148 </span> <span id="L149" class="LineNr">149 </span><span class="Delimiter">:(after "Begin Transforms")</span> <span id="L150" class="LineNr">150 </span><span class="Comment">// Begin Level-2 Transforms</span> -<span id="L151" class="LineNr">151 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pack_operands<span class="Delimiter">);</span> +<span id="L151" class="LineNr">151 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>pack_operands<span class="Delimiter">);</span> <span id="L152" class="LineNr">152 </span><span class="Comment">// End Level-2 Transforms</span> <span id="L153" class="LineNr">153 </span> <span id="L154" class="LineNr">154 </span><span class="Delimiter">:(code)</span> @@ -348,7 +347,7 @@ if ('onhashchange' in window) { <span id="L286" class="LineNr">286 </span>string <a href='030---operands.cc.html#L286'>hex_byte_to_string</a><span class="Delimiter">(</span><span class="Normal">uint8_t</span> val<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L287" class="LineNr">287 </span> ostringstream out<span class="Delimiter">;</span> <span id="L288" class="LineNr">288 </span> <span class="Comment">// uint8_t prints without padding, but int8_t will expand to 32 bits again</span> -<span id="L289" class="LineNr">289 </span> out << <a href='010---vm.cc.html#L403'>HEXBYTE</a> << <a href='010---vm.cc.html#L406'>NUM</a><span class="Delimiter">(</span>val<span class="Delimiter">);</span> +<span id="L289" class="LineNr">289 </span> out << <a href='010---vm.cc.html#L412'>HEXBYTE</a> << <a href='010---vm.cc.html#L415'>NUM</a><span class="Delimiter">(</span>val<span class="Delimiter">);</span> <span id="L290" class="LineNr">290 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span id="L291" class="LineNr">291 </span><span class="Delimiter">}</span> <span id="L292" class="LineNr">292 </span> @@ -457,7 +456,7 @@ if ('onhashchange' in window) { <span id="L395" class="LineNr">395 </span> <span id="L396" class="LineNr">396 </span><span class="Normal">bool</span> <a href='030---operands.cc.html#L396'>contains_any_operand_metadata</a><span class="Delimiter">(</span><span class="Normal">const</span> word& <a href='011run.cc.html#L123'>word</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L397" class="LineNr">397 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='011run.cc.html#L123'>word</a><span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> -<span id="L398" class="LineNr">398 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='011run.cc.html#L123'>word</a><span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> != <a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>end<span class="Delimiter">())</span> +<span id="L398" class="LineNr">398 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>find<span class="Delimiter">(</span><a href='011run.cc.html#L123'>word</a><span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">))</span> != <span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span id="L399" class="LineNr">399 </span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> <span id="L400" class="LineNr">400 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L401" class="LineNr">401 </span><span class="Delimiter">}</span> @@ -467,7 +466,7 @@ if ('onhashchange' in window) { <span id="L405" class="LineNr">405 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L406" class="LineNr">406 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> m<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L407" class="LineNr">407 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>result<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L408" class="LineNr">408 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' has conflicting "</span> << m << <span class="Constant">" operands</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L408" class="LineNr">408 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"' has conflicting "</span> << m << <span class="Constant">" operands\n"</span> << end<span class="Delimiter">();</span> <span id="L409" class="LineNr">409 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L410" class="LineNr">410 </span> <span class="Delimiter">}</span> <span id="L411" class="LineNr">411 </span> result =<span class="Constant"> true</span><span class="Delimiter">;</span> @@ -480,9 +479,9 @@ if ('onhashchange' in window) { <span id="L418" class="LineNr">418 </span> <span class="Normal">bool</span> metadata_found =<span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L419" class="LineNr">419 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L420" class="LineNr">420 </span> <span class="Normal">const</span> string& curr = w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L421" class="LineNr">421 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>find<span class="Delimiter">(</span>curr<span class="Delimiter">)</span> == <a href='030---operands.cc.html#L40'>Instruction_operands</a><span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ignore unrecognized metadata</span> +<span id="L421" class="LineNr">421 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>find<span class="Delimiter">(</span>curr<span class="Delimiter">)</span> == <span class="Special"><a href='030---operands.cc.html#L40'>Instruction_operands</a></span><span class="Delimiter">.</span>end<span class="Delimiter">())</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ignore unrecognized metadata</span> <span id="L422" class="LineNr">422 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>metadata_found<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L423" class="LineNr">423 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' has conflicting operand types; it should have only one</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L423" class="LineNr">423 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' has conflicting operand types; it should have only one\n"</span> << end<span class="Delimiter">();</span> <span id="L424" class="LineNr">424 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> <span id="L425" class="LineNr">425 </span> <span class="Delimiter">}</span> <span id="L426" class="LineNr">426 </span> metadata_found =<span class="Constant"> true</span><span class="Delimiter">;</span> diff --git a/html/subx/031check_operands.cc.html b/html/subx/031check_operands.cc.html index 8e64fe65..8d06d539 100644 --- a/html/subx/031check_operands.cc.html +++ b/html/subx/031check_operands.cc.html @@ -26,7 +26,6 @@ a:hover { text-decoration: underline; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.cSpecial { color: #008000; } .traceContains { color: #008000; } --> </style> @@ -87,18 +86,18 @@ if ('onhashchange' in window) { <span id="L23" class="LineNr"> 23 </span><span class="Normal">void</span> check_operands<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L24" class="LineNr"> 24 </span> <a href='011run.cc.html#L123'>word</a> op = <a href='031check_operands.cc.html#L36'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">));</span> <span id="L25" class="LineNr"> 25 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L26" class="LineNr"> 26 </span> <a href='031check_operands.cc.html#L523'>check_operands_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L26" class="LineNr"> 26 </span> <a href='031check_operands.cc.html#L519'>check_operands_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> <span id="L27" class="LineNr"> 27 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L28" class="LineNr"> 28 </span> <span class="Delimiter">}</span> <span id="L29" class="LineNr"> 29 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"f3"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L30" class="LineNr"> 30 </span> <a href='031check_operands.cc.html#L491'>check_operands_f3</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L30" class="LineNr"> 30 </span> <a href='031check_operands.cc.html#L487'>check_operands_f3</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> <span id="L31" class="LineNr"> 31 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L32" class="LineNr"> 32 </span> <span class="Delimiter">}</span> <span id="L33" class="LineNr"> 33 </span> check_operands<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> <span id="L34" class="LineNr"> 34 </span><span class="Delimiter">}</span> <span id="L35" class="LineNr"> 35 </span> <span id="L36" class="LineNr"> 36 </span><a href='011run.cc.html#L123'>word</a> <a href='031check_operands.cc.html#L36'>preprocess_op</a><span class="Delimiter">(</span><a href='011run.cc.html#L123'>word</a><span class="Comment">/*</span><span class="Comment">copy</span><span class="Comment">*/</span> op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L37" class="LineNr"> 37 </span> op<span class="Delimiter">.</span>data = <a href='031check_operands.cc.html#L556'>tolower</a><span class="Delimiter">(</span>op<span class="Delimiter">.</span>data<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span> +<span id="L37" class="LineNr"> 37 </span> op<span class="Delimiter">.</span>data = <a href='031check_operands.cc.html#L552'>tolower</a><span class="Delimiter">(</span>op<span class="Delimiter">.</span>data<span class="Delimiter">.</span>c_str<span class="Delimiter">());</span> <span id="L38" class="LineNr"> 38 </span> <span class="Comment">// opcodes can't be negative</span> <span id="L39" class="LineNr"> 39 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L93'>starts_with</a><span class="Delimiter">(</span>op<span class="Delimiter">.</span>data<span class="Delimiter">,</span> <span class="Constant">"0x"</span><span class="Delimiter">))</span> <span id="L40" class="LineNr"> 40 </span> op<span class="Delimiter">.</span>data = op<span class="Delimiter">.</span>data<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">);</span> @@ -130,14 +129,14 @@ if ('onhashchange' in window) { <span id="L66" class="LineNr"> 66 </span> <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a> <span id="L67" class="LineNr"> 67 </span><span class="Delimiter">};</span> <span id="L68" class="LineNr"> 68 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L69" class="LineNr"> 69 </span>vector<string> <a href='031check_operands.cc.html#L69'>Operand_type_name</a><span class="Delimiter">;</span> -<span id="L70" class="LineNr"> 70 </span>map<string<span class="Delimiter">,</span> operand_type> <a href='031check_operands.cc.html#L70'>Operand_type</a><span class="Delimiter">;</span> +<span id="L69" class="LineNr"> 69 </span>vector<string> <span class="Special"><a href='031check_operands.cc.html#L69'>Operand_type_name</a></span><span class="Delimiter">;</span> +<span id="L70" class="LineNr"> 70 </span>map<string<span class="Delimiter">,</span> operand_type> <span class="Special"><a href='031check_operands.cc.html#L70'>Operand_type</a></span><span class="Delimiter">;</span> <span id="L71" class="LineNr"> 71 </span><span class="Delimiter">:(before "End One-time Setup")</span> <span id="L72" class="LineNr"> 72 </span><a href='031check_operands.cc.html#L74'>init_op_types</a><span class="Delimiter">();</span> <span id="L73" class="LineNr"> 73 </span><span class="Delimiter">:(code)</span> <span id="L74" class="LineNr"> 74 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L74'>init_op_types</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> <span id="L75" class="LineNr"> 75 </span> assert<span class="Delimiter">(</span><a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a> <= <span class="Comment">/*</span><span class="Comment">bits in a uint8_t</span><span class="Comment">*/</span><span class="Constant">8</span><span class="Delimiter">);</span> -<span id="L76" class="LineNr"> 76 </span> <a href='031check_operands.cc.html#L69'>Operand_type_name</a><span class="Delimiter">.</span>resize<span class="Delimiter">(</span><a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">);</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Special"><a href='031check_operands.cc.html#L69'>Operand_type_name</a></span><span class="Delimiter">.</span>resize<span class="Delimiter">(</span><a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">);</span> <span id="L77" class="LineNr"> 77 </span> <span class="Comment">#define DEF(type) Operand_type_name.at(type) = tolower(#type), put(Operand_type, tolower(#type), type);</span> <span id="L78" class="LineNr"> 78 </span> DEF<span class="Delimiter">(</span><a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">);</span> <span id="L79" class="LineNr"> 79 </span> DEF<span class="Delimiter">(</span><a href='031check_operands.cc.html#L60'>SUBOP</a><span class="Delimiter">);</span> @@ -150,7 +149,7 @@ if ('onhashchange' in window) { <span id="L86" class="LineNr"> 86 </span><span class="Delimiter">}</span> <span id="L87" class="LineNr"> 87 </span> <span id="L88" class="LineNr"> 88 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L89" class="LineNr"> 89 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">;</span> +<span id="L89" class="LineNr"> 89 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">;</span> <span id="L90" class="LineNr"> 90 </span><span class="Normal">const</span> <span class="Normal">uint8_t</span> <a href='031check_operands.cc.html#L90'>INVALID_OPERANDS</a> = <span class="Constant">0xff</span><span class="Delimiter">;</span> <span class="Comment">// no instruction uses all the operand types</span> <span id="L91" class="LineNr"> 91 </span><span class="Delimiter">:(before "End One-time Setup")</span> <span id="L92" class="LineNr"> 92 </span><a href='031check_operands.cc.html#L94'>init_permitted_operands</a><span class="Delimiter">();</span> @@ -158,478 +157,474 @@ if ('onhashchange' in window) { <span id="L94" class="LineNr"> 94 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L94'>init_permitted_operands</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> <span id="L95" class="LineNr"> 95 </span> <span class="SalientComment">//// Class A: just op, no operands</span> <span id="L96" class="LineNr"> 96 </span> <span class="Comment">// halt</span> -<span id="L97" class="LineNr"> 97 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"f4"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L97" class="LineNr"> 97 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"f4"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L98" class="LineNr"> 98 </span> <span class="Comment">// inc</span> -<span id="L99" class="LineNr"> 99 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"40"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L100" class="LineNr">100 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"41"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L101" class="LineNr">101 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"42"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L102" class="LineNr">102 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"43"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L103" class="LineNr">103 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"44"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L104" class="LineNr">104 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"45"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L105" class="LineNr">105 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"46"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L106" class="LineNr">106 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"47"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L99" class="LineNr"> 99 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"40"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"41"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"42"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L102" class="LineNr">102 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"43"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L103" class="LineNr">103 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"44"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L104" class="LineNr">104 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"45"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"46"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L106" class="LineNr">106 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"47"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L107" class="LineNr">107 </span> <span class="Comment">// dec</span> -<span id="L108" class="LineNr">108 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"48"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L109" class="LineNr">109 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"49"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L110" class="LineNr">110 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"4a"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L111" class="LineNr">111 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"4b"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L112" class="LineNr">112 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"4c"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L113" class="LineNr">113 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"4d"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L114" class="LineNr">114 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"4e"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L115" class="LineNr">115 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"4f"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"48"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"49"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L110" class="LineNr">110 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"4a"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L111" class="LineNr">111 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"4b"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L112" class="LineNr">112 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"4c"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L113" class="LineNr">113 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"4d"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L114" class="LineNr">114 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"4e"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L115" class="LineNr">115 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"4f"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L116" class="LineNr">116 </span> <span class="Comment">// push</span> -<span id="L117" class="LineNr">117 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"50"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L118" class="LineNr">118 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L119" class="LineNr">119 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L120" class="LineNr">120 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L121" class="LineNr">121 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"54"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L122" class="LineNr">122 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"55"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L123" class="LineNr">123 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"56"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L124" class="LineNr">124 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"57"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L117" class="LineNr">117 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"50"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L118" class="LineNr">118 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"51"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L119" class="LineNr">119 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"52"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L120" class="LineNr">120 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"53"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"54"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L122" class="LineNr">122 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"55"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L123" class="LineNr">123 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"56"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L124" class="LineNr">124 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"57"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L125" class="LineNr">125 </span> <span class="Comment">// pop</span> -<span id="L126" class="LineNr">126 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L127" class="LineNr">127 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L128" class="LineNr">128 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"5a"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L129" class="LineNr">129 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"5b"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L130" class="LineNr">130 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L131" class="LineNr">131 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L132" class="LineNr">132 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> -<span id="L133" class="LineNr">133 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L126" class="LineNr">126 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"58"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L127" class="LineNr">127 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"59"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L128" class="LineNr">128 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"5a"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"5b"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L130" class="LineNr">130 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"5c"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L131" class="LineNr">131 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"5d"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"5e"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L133" class="LineNr">133 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"5f"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L134" class="LineNr">134 </span> <span class="Comment">// return</span> -<span id="L135" class="LineNr">135 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"c3"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> +<span id="L135" class="LineNr">135 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"c3"</span><span class="Delimiter">,</span> <span class="Constant">0x00</span><span class="Delimiter">);</span> <span id="L136" class="LineNr">136 </span> <span id="L137" class="LineNr">137 </span> <span class="SalientComment">//// Class B: just op and disp8</span> <span id="L138" class="LineNr">138 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> <span id="L139" class="LineNr">139 </span> <span class="Comment">// 0 0 0 |0 1 0 0</span> <span id="L140" class="LineNr">140 </span> <span id="L141" class="LineNr">141 </span> <span class="Comment">// jump</span> -<span id="L142" class="LineNr">142 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"eb"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> -<span id="L143" class="LineNr">143 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"74"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> -<span id="L144" class="LineNr">144 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"75"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> -<span id="L145" class="LineNr">145 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"7c"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> -<span id="L146" class="LineNr">146 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"7d"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> -<span id="L147" class="LineNr">147 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"7e"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> -<span id="L148" class="LineNr">148 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"7f"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L142" class="LineNr">142 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"eb"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L143" class="LineNr">143 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"74"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L144" class="LineNr">144 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"75"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L145" class="LineNr">145 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"7c"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L146" class="LineNr">146 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"7d"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L147" class="LineNr">147 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"7e"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> +<span id="L148" class="LineNr">148 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"7f"</span><span class="Delimiter">,</span> <span class="Constant">0x04</span><span class="Delimiter">);</span> <span id="L149" class="LineNr">149 </span> -<span id="L150" class="LineNr">150 </span> <span class="SalientComment">//// Class C: just op and disp16</span> +<span id="L150" class="LineNr">150 </span> <span class="SalientComment">//// Class D: just op and disp32</span> <span id="L151" class="LineNr">151 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L152" class="LineNr">152 </span> <span class="Comment">// 0 0 0 |1 0 0 0</span> -<span id="L153" class="LineNr">153 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"e9"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> <span class="Comment">// jump</span> -<span id="L154" class="LineNr">154 </span> -<span id="L155" class="LineNr">155 </span> <span class="SalientComment">//// Class D: just op and disp32</span> -<span id="L156" class="LineNr">156 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L157" class="LineNr">157 </span> <span class="Comment">// 0 0 1 |0 0 0 0</span> -<span id="L158" class="LineNr">158 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"e8"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> <span class="Comment">// call</span> -<span id="L159" class="LineNr">159 </span> -<span id="L160" class="LineNr">160 </span> <span class="SalientComment">//// Class E: just op and imm8</span> -<span id="L161" class="LineNr">161 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L162" class="LineNr">162 </span> <span class="Comment">// 0 1 0 |0 0 0 0</span> -<span id="L163" class="LineNr">163 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"cd"</span><span class="Delimiter">,</span> <span class="Constant">0x20</span><span class="Delimiter">);</span> <span class="Comment">// software interrupt</span> -<span id="L164" class="LineNr">164 </span> -<span id="L165" class="LineNr">165 </span> <span class="SalientComment">//// Class F: just op and imm32</span> -<span id="L166" class="LineNr">166 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L167" class="LineNr">167 </span> <span class="Comment">// 1 0 0 |0 0 0 0</span> -<span id="L168" class="LineNr">168 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// add</span> -<span id="L169" class="LineNr">169 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// subtract</span> -<span id="L170" class="LineNr">170 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"25"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// and</span> -<span id="L171" class="LineNr">171 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"0d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// or</span> -<span id="L172" class="LineNr">172 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"35"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// xor</span> -<span id="L173" class="LineNr">173 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"3d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// compare</span> -<span id="L174" class="LineNr">174 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"68"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// push</span> -<span id="L175" class="LineNr">175 </span> <span class="Comment">// copy</span> -<span id="L176" class="LineNr">176 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"b8"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L177" class="LineNr">177 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"b9"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L178" class="LineNr">178 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L179" class="LineNr">179 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"bb"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L180" class="LineNr">180 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"bc"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L181" class="LineNr">181 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"bd"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L182" class="LineNr">182 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"be"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> -<span id="L183" class="LineNr">183 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"bf"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L152" class="LineNr">152 </span> <span class="Comment">// 0 0 1 |0 0 0 0</span> +<span id="L153" class="LineNr">153 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"e8"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> <span class="Comment">// call</span> +<span id="L154" class="LineNr">154 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"e9"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> <span class="Comment">// jump</span> +<span id="L155" class="LineNr">155 </span> +<span id="L156" class="LineNr">156 </span> <span class="SalientComment">//// Class E: just op and imm8</span> +<span id="L157" class="LineNr">157 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L158" class="LineNr">158 </span> <span class="Comment">// 0 1 0 |0 0 0 0</span> +<span id="L159" class="LineNr">159 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"cd"</span><span class="Delimiter">,</span> <span class="Constant">0x20</span><span class="Delimiter">);</span> <span class="Comment">// software interrupt</span> +<span id="L160" class="LineNr">160 </span> +<span id="L161" class="LineNr">161 </span> <span class="SalientComment">//// Class F: just op and imm32</span> +<span id="L162" class="LineNr">162 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment">// 1 0 0 |0 0 0 0</span> +<span id="L164" class="LineNr">164 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"05"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// add</span> +<span id="L165" class="LineNr">165 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"2d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// subtract</span> +<span id="L166" class="LineNr">166 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"25"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// and</span> +<span id="L167" class="LineNr">167 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"0d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// or</span> +<span id="L168" class="LineNr">168 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"35"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// xor</span> +<span id="L169" class="LineNr">169 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"3d"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// compare</span> +<span id="L170" class="LineNr">170 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"68"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> <span class="Comment">// push</span> +<span id="L171" class="LineNr">171 </span> <span class="Comment">// copy</span> +<span id="L172" class="LineNr">172 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"b8"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L173" class="LineNr">173 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"b9"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L174" class="LineNr">174 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"ba"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L175" class="LineNr">175 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"bb"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L176" class="LineNr">176 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"bc"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L177" class="LineNr">177 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"bd"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L178" class="LineNr">178 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"be"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L179" class="LineNr">179 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"bf"</span><span class="Delimiter">,</span> <span class="Constant">0x40</span><span class="Delimiter">);</span> +<span id="L180" class="LineNr">180 </span> +<span id="L181" class="LineNr">181 </span> <span class="SalientComment">//// Class M: using ModR/M byte</span> +<span id="L182" class="LineNr">182 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L183" class="LineNr">183 </span> <span class="Comment">// 0 0 0 |0 0 0 1</span> <span id="L184" class="LineNr">184 </span> -<span id="L185" class="LineNr">185 </span> <span class="SalientComment">//// Class M: using ModR/M byte</span> -<span id="L186" class="LineNr">186 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L187" class="LineNr">187 </span> <span class="Comment">// 0 0 0 |0 0 0 1</span> -<span id="L188" class="LineNr">188 </span> -<span id="L189" class="LineNr">189 </span> <span class="Comment">// add</span> -<span id="L190" class="LineNr">190 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"01"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L191" class="LineNr">191 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"03"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L192" class="LineNr">192 </span> <span class="Comment">// subtract</span> -<span id="L193" class="LineNr">193 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"29"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L194" class="LineNr">194 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"2b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L195" class="LineNr">195 </span> <span class="Comment">// and</span> -<span id="L196" class="LineNr">196 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"21"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L197" class="LineNr">197 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"23"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L198" class="LineNr">198 </span> <span class="Comment">// or</span> -<span id="L199" class="LineNr">199 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"09"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L200" class="LineNr">200 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"0b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L201" class="LineNr">201 </span> <span class="Comment">// xor</span> -<span id="L202" class="LineNr">202 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"31"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L203" class="LineNr">203 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"33"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L204" class="LineNr">204 </span> <span class="Comment">// compare</span> -<span id="L205" class="LineNr">205 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"39"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L206" class="LineNr">206 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"3b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L207" class="LineNr">207 </span> <span class="Comment">// copy</span> -<span id="L208" class="LineNr">208 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"88"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L209" class="LineNr">209 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"89"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L210" class="LineNr">210 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"8a"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L211" class="LineNr">211 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"8b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L212" class="LineNr">212 </span> <span class="Comment">// swap</span> -<span id="L213" class="LineNr">213 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L214" class="LineNr">214 </span> <span class="Comment">// copy address (lea)</span> -<span id="L215" class="LineNr">215 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L216" class="LineNr">216 </span> <span class="Comment">// pop</span> -<span id="L217" class="LineNr">217 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L218" class="LineNr">218 </span> -<span id="L219" class="LineNr">219 </span> <span class="SalientComment">//// Class O: op, ModR/M and subop (not r32)</span> -<span id="L220" class="LineNr">220 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L221" class="LineNr">221 </span> <span class="Comment">// 0 0 0 |0 0 1 1</span> -<span id="L222" class="LineNr">222 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"f7"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// test/not/mul/div</span> -<span id="L223" class="LineNr">223 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"ff"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// jump/push/call</span> -<span id="L224" class="LineNr">224 </span> -<span id="L225" class="LineNr">225 </span> <span class="SalientComment">//// Class N: op, ModR/M and imm32</span> -<span id="L226" class="LineNr">226 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L227" class="LineNr">227 </span> <span class="Comment">// 1 0 0 |0 0 0 1</span> -<span id="L228" class="LineNr">228 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"c7"</span><span class="Delimiter">,</span> <span class="Constant">0x41</span><span class="Delimiter">);</span> <span class="Comment">// copy</span> -<span id="L229" class="LineNr">229 </span> -<span id="L230" class="LineNr">230 </span> <span class="SalientComment">//// Class P: op, ModR/M, subop (not r32) and imm32</span> -<span id="L231" class="LineNr">231 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L232" class="LineNr">232 </span> <span class="Comment">// 1 0 0 |0 0 1 1</span> -<span id="L233" class="LineNr">233 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> <span class="Constant">"81"</span><span class="Delimiter">,</span> <span class="Constant">0x43</span><span class="Delimiter">);</span> <span class="Comment">// combine</span> -<span id="L234" class="LineNr">234 </span> -<span id="L235" class="LineNr">235 </span> <span class="Comment">// End Init Permitted Operands</span> -<span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> -<span id="L237" class="LineNr">237 </span> -<span id="L238" class="LineNr">238 </span><span class="Delimiter">:(code)</span> -<span id="L239" class="LineNr">239 </span><span class="Comment">#define HAS(bitvector, bit) ((bitvector) & (1 << (bit)))</span> -<span id="L240" class="LineNr">240 </span><span class="Comment">#define SET(bitvector, bit) ((bitvector) | (1 << (bit)))</span> -<span id="L241" class="LineNr">241 </span><span class="Comment">#define CLEAR(bitvector, bit) ((bitvector) & (~(1 << (bit))))</span> -<span id="L242" class="LineNr">242 </span> -<span id="L243" class="LineNr">243 </span><span class="Normal">void</span> check_operands<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L244" class="LineNr">244 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L245" class="LineNr">245 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><a href='031check_operands.cc.html#L89'>Permitted_operands</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> -<span id="L246" class="LineNr">246 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L247" class="LineNr">247 </span> <a href='031check_operands.cc.html#L341'>check_operands_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L248" class="LineNr">248 </span> <a href='031check_operands.cc.html#L368'>compare_bitvector_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L249" class="LineNr">249 </span> <span class="Delimiter">}</span> -<span id="L250" class="LineNr">250 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L251" class="LineNr">251 </span> <a href='031check_operands.cc.html#L257'>compare_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L252" class="LineNr">252 </span> <span class="Delimiter">}</span> -<span id="L253" class="LineNr">253 </span><span class="Delimiter">}</span> -<span id="L254" class="LineNr">254 </span> -<span id="L255" class="LineNr">255 </span><span class="Comment">//: Many instructions can be checked just by comparing bitvectors.</span> -<span id="L256" class="LineNr">256 </span> -<span id="L257" class="LineNr">257 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L257'>compare_bitvector</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L258" class="LineNr">258 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='031check_operands.cc.html#L292'>has_operands</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> -<span id="L259" class="LineNr">259 </span> <span class="Normal">uint8_t</span> bitvector = <a href='031check_operands.cc.html#L283'>compute_operand_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> -<span id="L260" class="LineNr">260 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> -<span id="L261" class="LineNr">261 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> -<span id="L262" class="LineNr">262 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L263" class="LineNr">263 </span><span class="CommentedCode">//? cerr << "comparing " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> -<span id="L264" class="LineNr">264 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this operand</span> -<span id="L265" class="LineNr">265 </span> <span class="Normal">const</span> string& optype = <a href='031check_operands.cc.html#L69'>Operand_type_name</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L266" class="LineNr">266 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> -<span id="L267" class="LineNr">267 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L268" class="LineNr">268 </span> <span class="Normal">else</span> -<span id="L269" class="LineNr">269 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L270" class="LineNr">270 </span> <span class="Comment">// continue giving all errors for a single instruction</span> -<span id="L271" class="LineNr">271 </span> <span class="Delimiter">}</span> -<span id="L272" class="LineNr">272 </span> <span class="Comment">// ignore settings in any unused bits</span> -<span id="L273" class="LineNr">273 </span><span class="Delimiter">}</span> -<span id="L274" class="LineNr">274 </span> -<span id="L275" class="LineNr">275 </span>string <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L276" class="LineNr">276 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> -<span id="L277" class="LineNr">277 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> -<span id="L278" class="LineNr">278 </span> <span class="Comment">// strip stuff in parens from the name</span> -<span id="L279" class="LineNr">279 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><a href='010---vm.cc.html#L369'>Name</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> -<span id="L280" class="LineNr">280 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> -<span id="L281" class="LineNr">281 </span><span class="Delimiter">}</span> -<span id="L282" class="LineNr">282 </span> -<span id="L283" class="LineNr">283 </span><span class="Normal">uint32_t</span> <a href='031check_operands.cc.html#L283'>compute_operand_bitvector</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L284" class="LineNr">284 </span> <span class="Normal">uint32_t</span> bitvector = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L285" class="LineNr">285 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip op</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L286" class="LineNr">286 </span> bitvector = bitvector | <a href='031check_operands.cc.html#L309'>bitvector_for_operand</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> -<span id="L287" class="LineNr">287 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span> <a href='031check_operands.cc.html#L90'>INVALID_OPERANDS</a><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> -<span id="L288" class="LineNr">288 </span> <span class="Delimiter">}</span> -<span id="L289" class="LineNr">289 </span> <span class="Identifier">return</span> bitvector<span class="Delimiter">;</span> +<span id="L185" class="LineNr">185 </span> <span class="Comment">// add</span> +<span id="L186" class="LineNr">186 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"01"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L187" class="LineNr">187 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"03"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L188" class="LineNr">188 </span> <span class="Comment">// subtract</span> +<span id="L189" class="LineNr">189 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"29"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L190" class="LineNr">190 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"2b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L191" class="LineNr">191 </span> <span class="Comment">// and</span> +<span id="L192" class="LineNr">192 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"21"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L193" class="LineNr">193 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"23"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L194" class="LineNr">194 </span> <span class="Comment">// or</span> +<span id="L195" class="LineNr">195 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"09"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L196" class="LineNr">196 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"0b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment">// xor</span> +<span id="L198" class="LineNr">198 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"31"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L199" class="LineNr">199 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"33"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L200" class="LineNr">200 </span> <span class="Comment">// compare</span> +<span id="L201" class="LineNr">201 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"39"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L202" class="LineNr">202 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"3b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L203" class="LineNr">203 </span> <span class="Comment">// copy</span> +<span id="L204" class="LineNr">204 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"88"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L205" class="LineNr">205 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"89"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L206" class="LineNr">206 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"8a"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L207" class="LineNr">207 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"8b"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L208" class="LineNr">208 </span> <span class="Comment">// swap</span> +<span id="L209" class="LineNr">209 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"87"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L210" class="LineNr">210 </span> <span class="Comment">// copy address (lea)</span> +<span id="L211" class="LineNr">211 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L212" class="LineNr">212 </span> <span class="Comment">// pop</span> +<span id="L213" class="LineNr">213 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L214" class="LineNr">214 </span> +<span id="L215" class="LineNr">215 </span> <span class="SalientComment">//// Class O: op, ModR/M and subop (not r32)</span> +<span id="L216" class="LineNr">216 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L217" class="LineNr">217 </span> <span class="Comment">// 0 0 0 |0 0 1 1</span> +<span id="L218" class="LineNr">218 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"f7"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// test/not/mul/div</span> +<span id="L219" class="LineNr">219 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"ff"</span><span class="Delimiter">,</span> <span class="Constant">0x03</span><span class="Delimiter">);</span> <span class="Comment">// jump/push/call</span> +<span id="L220" class="LineNr">220 </span> +<span id="L221" class="LineNr">221 </span> <span class="SalientComment">//// Class N: op, ModR/M and imm32</span> +<span id="L222" class="LineNr">222 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L223" class="LineNr">223 </span> <span class="Comment">// 1 0 0 |0 0 0 1</span> +<span id="L224" class="LineNr">224 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"c7"</span><span class="Delimiter">,</span> <span class="Constant">0x41</span><span class="Delimiter">);</span> <span class="Comment">// copy</span> +<span id="L225" class="LineNr">225 </span> +<span id="L226" class="LineNr">226 </span> <span class="SalientComment">//// Class P: op, ModR/M, subop (not r32) and imm32</span> +<span id="L227" class="LineNr">227 </span> <span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L228" class="LineNr">228 </span> <span class="Comment">// 1 0 0 |0 0 1 1</span> +<span id="L229" class="LineNr">229 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> <span class="Constant">"81"</span><span class="Delimiter">,</span> <span class="Constant">0x43</span><span class="Delimiter">);</span> <span class="Comment">// combine</span> +<span id="L230" class="LineNr">230 </span> +<span id="L231" class="LineNr">231 </span> <span class="Comment">// End Init Permitted Operands</span> +<span id="L232" class="LineNr">232 </span><span class="Delimiter">}</span> +<span id="L233" class="LineNr">233 </span> +<span id="L234" class="LineNr">234 </span><span class="Delimiter">:(code)</span> +<span id="L235" class="LineNr">235 </span><span class="Comment">#define HAS(bitvector, bit) ((bitvector) & (1 << (bit)))</span> +<span id="L236" class="LineNr">236 </span><span class="Comment">#define SET(bitvector, bit) ((bitvector) | (1 << (bit)))</span> +<span id="L237" class="LineNr">237 </span><span class="Comment">#define CLEAR(bitvector, bit) ((bitvector) & (~(1 << (bit))))</span> +<span id="L238" class="LineNr">238 </span> +<span id="L239" class="LineNr">239 </span><span class="Normal">void</span> check_operands<span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L240" class="LineNr">240 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L241" class="LineNr">241 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L89'>Permitted_operands</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L242" class="LineNr">242 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L243" class="LineNr">243 </span> <a href='031check_operands.cc.html#L337'>check_operands_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L244" class="LineNr">244 </span> <a href='031check_operands.cc.html#L364'>compare_bitvector_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L245" class="LineNr">245 </span> <span class="Delimiter">}</span> +<span id="L246" class="LineNr">246 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L247" class="LineNr">247 </span> <a href='031check_operands.cc.html#L253'>compare_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> expected_bitvector<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L248" class="LineNr">248 </span> <span class="Delimiter">}</span> +<span id="L249" class="LineNr">249 </span><span class="Delimiter">}</span> +<span id="L250" class="LineNr">250 </span> +<span id="L251" class="LineNr">251 </span><span class="Comment">//: Many instructions can be checked just by comparing bitvectors.</span> +<span id="L252" class="LineNr">252 </span> +<span id="L253" class="LineNr">253 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L253'>compare_bitvector</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L254" class="LineNr">254 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='031check_operands.cc.html#L288'>has_operands</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L255" class="LineNr">255 </span> <span class="Normal">uint8_t</span> bitvector = <a href='031check_operands.cc.html#L279'>compute_operand_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L256" class="LineNr">256 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> +<span id="L257" class="LineNr">257 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> +<span id="L258" class="LineNr">258 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L259" class="LineNr">259 </span><span class="CommentedCode">//? cerr << "comparing " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> +<span id="L260" class="LineNr">260 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this operand</span> +<span id="L261" class="LineNr">261 </span> <span class="Normal">const</span> string& optype = <span class="Special"><a href='031check_operands.cc.html#L69'>Operand_type_name</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L262" class="LineNr">262 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> +<span id="L263" class="LineNr">263 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L264" class="LineNr">264 </span> <span class="Normal">else</span> +<span id="L265" class="LineNr">265 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L266" class="LineNr">266 </span> <span class="Comment">// continue giving all errors for a single instruction</span> +<span id="L267" class="LineNr">267 </span> <span class="Delimiter">}</span> +<span id="L268" class="LineNr">268 </span> <span class="Comment">// ignore settings in any unused bits</span> +<span id="L269" class="LineNr">269 </span><span class="Delimiter">}</span> +<span id="L270" class="LineNr">270 </span> +<span id="L271" class="LineNr">271 </span>string <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L272" class="LineNr">272 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L273" class="LineNr">273 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L274" class="LineNr">274 </span> <span class="Comment">// strip stuff in parens from the name</span> +<span id="L275" class="LineNr">275 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L378'>Name</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L276" class="LineNr">276 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> +<span id="L277" class="LineNr">277 </span><span class="Delimiter">}</span> +<span id="L278" class="LineNr">278 </span> +<span id="L279" class="LineNr">279 </span><span class="Normal">uint32_t</span> <a href='031check_operands.cc.html#L279'>compute_operand_bitvector</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L280" class="LineNr">280 </span> <span class="Normal">uint32_t</span> bitvector = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L281" class="LineNr">281 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip op</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L282" class="LineNr">282 </span> bitvector = bitvector | <a href='031check_operands.cc.html#L305'>bitvector_for_operand</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L283" class="LineNr">283 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span> <a href='031check_operands.cc.html#L90'>INVALID_OPERANDS</a><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> +<span id="L284" class="LineNr">284 </span> <span class="Delimiter">}</span> +<span id="L285" class="LineNr">285 </span> <span class="Identifier">return</span> bitvector<span class="Delimiter">;</span> +<span id="L286" class="LineNr">286 </span><span class="Delimiter">}</span> +<span id="L287" class="LineNr">287 </span> +<span id="L288" class="LineNr">288 </span><span class="Normal">bool</span> <a href='031check_operands.cc.html#L288'>has_operands</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L289" class="LineNr">289 </span> <span class="Identifier">return</span> <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">)</span> > <a href='031check_operands.cc.html#L292'>first_operand</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> <span id="L290" class="LineNr">290 </span><span class="Delimiter">}</span> <span id="L291" class="LineNr">291 </span> -<span id="L292" class="LineNr">292 </span><span class="Normal">bool</span> <a href='031check_operands.cc.html#L292'>has_operands</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L293" class="LineNr">293 </span> <span class="Identifier">return</span> <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">)</span> > <a href='031check_operands.cc.html#L296'>first_operand</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> -<span id="L294" class="LineNr">294 </span><span class="Delimiter">}</span> -<span id="L295" class="LineNr">295 </span> -<span id="L296" class="LineNr">296 </span><span class="Normal">int</span> <a href='031check_operands.cc.html#L296'>first_operand</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L297" class="LineNr">297 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> -<span id="L298" class="LineNr">298 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f2"</span> || inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f3"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L299" class="LineNr">299 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> -<span id="L300" class="LineNr">300 </span> <span class="Identifier">return</span> <span class="Constant">3</span><span class="Delimiter">;</span> -<span id="L301" class="LineNr">301 </span> <span class="Normal">else</span> -<span id="L302" class="LineNr">302 </span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> -<span id="L303" class="LineNr">303 </span> <span class="Delimiter">}</span> -<span id="L304" class="LineNr">304 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> -<span id="L305" class="LineNr">305 </span><span class="Delimiter">}</span> -<span id="L306" class="LineNr">306 </span> -<span id="L307" class="LineNr">307 </span><span class="Comment">// Scan the metadata of 'w' and return the bit corresponding to any operand type.</span> -<span id="L308" class="LineNr">308 </span><span class="Comment">// Also raise an error if metadata contains multiple operand types.</span> -<span id="L309" class="LineNr">309 </span><span class="Normal">uint32_t</span> <a href='031check_operands.cc.html#L309'>bitvector_for_operand</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L310" class="LineNr">310 </span> <span class="Normal">uint32_t</span> bv = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L311" class="LineNr">311 </span> <span class="Normal">bool</span> found =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L312" class="LineNr">312 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L313" class="LineNr">313 </span> <span class="Normal">const</span> string& curr = w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L314" class="LineNr">314 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='031check_operands.cc.html#L70'>Operand_type</a><span class="Delimiter">,</span> curr<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ignore unrecognized metadata</span> -<span id="L315" class="LineNr">315 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>found<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L316" class="LineNr">316 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' has conflicting operand types; it should have only one</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L317" class="LineNr">317 </span> <span class="Identifier">return</span> <a href='031check_operands.cc.html#L90'>INVALID_OPERANDS</a><span class="Delimiter">;</span> -<span id="L318" class="LineNr">318 </span> <span class="Delimiter">}</span> -<span id="L319" class="LineNr">319 </span> bv = <span class="Delimiter">(</span><span class="Constant">1</span> << get<span class="Delimiter">(</span><a href='031check_operands.cc.html#L70'>Operand_type</a><span class="Delimiter">,</span> curr<span class="Delimiter">));</span> -<span id="L320" class="LineNr">320 </span> found =<span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L321" class="LineNr">321 </span> <span class="Delimiter">}</span> -<span id="L322" class="LineNr">322 </span> <span class="Identifier">return</span> bv<span class="Delimiter">;</span> -<span id="L323" class="LineNr">323 </span><span class="Delimiter">}</span> -<span id="L324" class="LineNr">324 </span> -<span id="L325" class="LineNr">325 </span><span class="Delimiter">:(scenario conflicting_operand_type)</span> -<span id="L326" class="LineNr">326 </span><span class="Special">% Hide_errors = true;</span> -<span id="L327" class="LineNr">327 </span>== <span class="Constant">0x1</span> -<span id="L328" class="LineNr">328 </span>cd/software-interrupt <span class="Constant">80</span>/imm8/imm32 -<span id="L329" class="LineNr">329 </span><span class="traceContains">+error: '80/imm8/imm32' has conflicting operand types; it should have only one</span> -<span id="L330" class="LineNr">330 </span> -<span id="L331" class="LineNr">331 </span><span class="Comment">//: Instructions computing effective addresses have more complex rules, so</span> -<span id="L332" class="LineNr">332 </span><span class="Comment">//: we'll hard-code a common set of instruction-decoding rules.</span> -<span id="L333" class="LineNr">333 </span> -<span id="L334" class="LineNr">334 </span><span class="Delimiter">:(scenario check_missing_mod_operand)</span> -<span id="L335" class="LineNr">335 </span><span class="Special">% Hide_errors = true;</span> -<span id="L336" class="LineNr">336 </span>== <span class="Constant">0x1</span> -<span id="L337" class="LineNr">337 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">3</span>/rm32/ebx <span class="Constant">1</span>/imm32 -<span id="L338" class="LineNr">338 </span><span class="traceContains">+error: '81 0/add/subop 3/rm32/ebx 1/imm32' (combine rm32 with imm32 based on subop): missing mod operand</span> -<span id="L339" class="LineNr">339 </span> -<span id="L340" class="LineNr">340 </span><span class="Delimiter">:(code)</span> -<span id="L341" class="LineNr">341 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L341'>check_operands_modrm</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L342" class="LineNr">342 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> -<span id="L343" class="LineNr">343 </span> <a href='031check_operands.cc.html#L402'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L344" class="LineNr">344 </span> <a href='031check_operands.cc.html#L402'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L345" class="LineNr">345 </span> <span class="Comment">// no check for r32; some instructions don't use it; just assume it's 0 if missing</span> -<span id="L346" class="LineNr">346 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"81"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"8f"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"ff"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// keep sync'd with 'help subop'</span> -<span id="L347" class="LineNr">347 </span> <a href='031check_operands.cc.html#L402'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L348" class="LineNr">348 </span> <a href='031check_operands.cc.html#L407'>check_operand_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"should be replaced by subop"</span><span class="Delimiter">);</span> -<span id="L349" class="LineNr">349 </span> <span class="Delimiter">}</span> -<span id="L350" class="LineNr">350 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L351" class="LineNr">351 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">).</span>data != <span class="Constant">"4"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L352" class="LineNr">352 </span> <span class="Comment">// SIB byte checks</span> -<span id="L353" class="LineNr">353 </span> <span class="Normal">uint8_t</span> mod = <a href='011run.cc.html#L273'>hex_byte</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> -<span id="L354" class="LineNr">354 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Comment">/*</span><span class="Comment">direct</span><span class="Comment">*/</span><span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L355" class="LineNr">355 </span> <a href='031check_operands.cc.html#L402'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L356" class="LineNr">356 </span> <a href='031check_operands.cc.html#L402'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> <span class="Comment">// otherwise why go to SIB?</span> +<span id="L292" class="LineNr">292 </span><span class="Normal">int</span> <a href='031check_operands.cc.html#L292'>first_operand</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L293" class="LineNr">293 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L294" class="LineNr">294 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f2"</span> || inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"f3"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L295" class="LineNr">295 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">)</span> +<span id="L296" class="LineNr">296 </span> <span class="Identifier">return</span> <span class="Constant">3</span><span class="Delimiter">;</span> +<span id="L297" class="LineNr">297 </span> <span class="Normal">else</span> +<span id="L298" class="LineNr">298 </span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L299" class="LineNr">299 </span> <span class="Delimiter">}</span> +<span id="L300" class="LineNr">300 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L301" class="LineNr">301 </span><span class="Delimiter">}</span> +<span id="L302" class="LineNr">302 </span> +<span id="L303" class="LineNr">303 </span><span class="Comment">// Scan the metadata of 'w' and return the bit corresponding to any operand type.</span> +<span id="L304" class="LineNr">304 </span><span class="Comment">// Also raise an error if metadata contains multiple operand types.</span> +<span id="L305" class="LineNr">305 </span><span class="Normal">uint32_t</span> <a href='031check_operands.cc.html#L305'>bitvector_for_operand</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L306" class="LineNr">306 </span> <span class="Normal">uint32_t</span> bv = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L307" class="LineNr">307 </span> <span class="Normal">bool</span> found =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L308" class="LineNr">308 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L309" class="LineNr">309 </span> <span class="Normal">const</span> string& curr = w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L310" class="LineNr">310 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L70'>Operand_type</a></span><span class="Delimiter">,</span> curr<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// ignore unrecognized metadata</span> +<span id="L311" class="LineNr">311 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>found<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L312" class="LineNr">312 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << w<span class="Delimiter">.</span>original << <span class="Constant">"' has conflicting operand types; it should have only one\n"</span> << end<span class="Delimiter">();</span> +<span id="L313" class="LineNr">313 </span> <span class="Identifier">return</span> <a href='031check_operands.cc.html#L90'>INVALID_OPERANDS</a><span class="Delimiter">;</span> +<span id="L314" class="LineNr">314 </span> <span class="Delimiter">}</span> +<span id="L315" class="LineNr">315 </span> bv = <span class="Delimiter">(</span><span class="Constant">1</span> << get<span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L70'>Operand_type</a></span><span class="Delimiter">,</span> curr<span class="Delimiter">));</span> +<span id="L316" class="LineNr">316 </span> found =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L317" class="LineNr">317 </span> <span class="Delimiter">}</span> +<span id="L318" class="LineNr">318 </span> <span class="Identifier">return</span> bv<span class="Delimiter">;</span> +<span id="L319" class="LineNr">319 </span><span class="Delimiter">}</span> +<span id="L320" class="LineNr">320 </span> +<span id="L321" class="LineNr">321 </span><span class="Delimiter">:(scenario conflicting_operand_type)</span> +<span id="L322" class="LineNr">322 </span><span class="Special">% Hide_errors = true;</span> +<span id="L323" class="LineNr">323 </span>== <span class="Constant">0x1</span> +<span id="L324" class="LineNr">324 </span>cd/software-interrupt <span class="Constant">80</span>/imm8/imm32 +<span id="L325" class="LineNr">325 </span><span class="traceContains">+error: '80/imm8/imm32' has conflicting operand types; it should have only one</span> +<span id="L326" class="LineNr">326 </span> +<span id="L327" class="LineNr">327 </span><span class="Comment">//: Instructions computing effective addresses have more complex rules, so</span> +<span id="L328" class="LineNr">328 </span><span class="Comment">//: we'll hard-code a common set of instruction-decoding rules.</span> +<span id="L329" class="LineNr">329 </span> +<span id="L330" class="LineNr">330 </span><span class="Delimiter">:(scenario check_missing_mod_operand)</span> +<span id="L331" class="LineNr">331 </span><span class="Special">% Hide_errors = true;</span> +<span id="L332" class="LineNr">332 </span>== <span class="Constant">0x1</span> +<span id="L333" class="LineNr">333 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">3</span>/rm32/ebx <span class="Constant">1</span>/imm32 +<span id="L334" class="LineNr">334 </span><span class="traceContains">+error: '81 0/add/subop 3/rm32/ebx 1/imm32' (combine rm32 with imm32 based on subop): missing mod operand</span> +<span id="L335" class="LineNr">335 </span> +<span id="L336" class="LineNr">336 </span><span class="Delimiter">:(code)</span> +<span id="L337" class="LineNr">337 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L337'>check_operands_modrm</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L338" class="LineNr">338 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L339" class="LineNr">339 </span> <a href='031check_operands.cc.html#L398'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L340" class="LineNr">340 </span> <a href='031check_operands.cc.html#L398'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L341" class="LineNr">341 </span> <span class="Comment">// no check for r32; some instructions don't use it; just assume it's 0 if missing</span> +<span id="L342" class="LineNr">342 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>op<span class="Delimiter">.</span>data == <span class="Constant">"81"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"8f"</span> || op<span class="Delimiter">.</span>data == <span class="Constant">"ff"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span class="Comment">// keep sync'd with 'help subop'</span> +<span id="L343" class="LineNr">343 </span> <a href='031check_operands.cc.html#L398'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L344" class="LineNr">344 </span> <a href='031check_operands.cc.html#L403'>check_operand_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"should be replaced by subop"</span><span class="Delimiter">);</span> +<span id="L345" class="LineNr">345 </span> <span class="Delimiter">}</span> +<span id="L346" class="LineNr">346 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L347" class="LineNr">347 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">).</span>data != <span class="Constant">"4"</span><span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L348" class="LineNr">348 </span> <span class="Comment">// SIB byte checks</span> +<span id="L349" class="LineNr">349 </span> <span class="Normal">uint8_t</span> mod = <a href='011run.cc.html#L273'>hex_byte</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L350" class="LineNr">350 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Comment">/*</span><span class="Comment">direct</span><span class="Comment">*/</span><span class="Constant">3</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L351" class="LineNr">351 </span> <a href='031check_operands.cc.html#L398'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L352" class="LineNr">352 </span> <a href='031check_operands.cc.html#L398'>check_operand_metadata_present</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> op<span class="Delimiter">);</span> <span class="Comment">// otherwise why go to SIB?</span> +<span id="L353" class="LineNr">353 </span> <span class="Delimiter">}</span> +<span id="L354" class="LineNr">354 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L355" class="LineNr">355 </span> <a href='031check_operands.cc.html#L403'>check_operand_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"direct mode"</span><span class="Delimiter">);</span> +<span id="L356" class="LineNr">356 </span> <a href='031check_operands.cc.html#L403'>check_operand_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"direct mode"</span><span class="Delimiter">);</span> <span id="L357" class="LineNr">357 </span> <span class="Delimiter">}</span> -<span id="L358" class="LineNr">358 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L359" class="LineNr">359 </span> <a href='031check_operands.cc.html#L407'>check_operand_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"direct mode"</span><span class="Delimiter">);</span> -<span id="L360" class="LineNr">360 </span> <a href='031check_operands.cc.html#L407'>check_operand_metadata_absent</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> op<span class="Delimiter">,</span> <span class="Constant">"direct mode"</span><span class="Delimiter">);</span> -<span id="L361" class="LineNr">361 </span> <span class="Delimiter">}</span> -<span id="L362" class="LineNr">362 </span> <span class="Comment">// no check for scale; 0 (2**0 = 1) by default</span> -<span id="L363" class="LineNr">363 </span><span class="Delimiter">}</span> -<span id="L364" class="LineNr">364 </span> -<span id="L365" class="LineNr">365 </span><span class="Comment">// same as compare_bitvector, with a couple of exceptions for modrm-based instructions</span> -<span id="L366" class="LineNr">366 </span><span class="Comment">// exception 1: ignore modrm bit since we already checked it above</span> -<span id="L367" class="LineNr">367 </span><span class="Comment">// exception 2: modrm instructions can use a displacement on occasion</span> -<span id="L368" class="LineNr">368 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L368'>compare_bitvector_modrm</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L369" class="LineNr">369 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='031check_operands.cc.html#L292'>has_operands</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> -<span id="L370" class="LineNr">370 </span> <span class="Normal">uint8_t</span> bitvector = <a href='031check_operands.cc.html#L283'>compute_operand_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> -<span id="L371" class="LineNr">371 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> -<span id="L372" class="LineNr">372 </span> expected = CLEAR<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">);</span> <span class="Comment">// exception 1</span> -<span id="L373" class="LineNr">373 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> -<span id="L374" class="LineNr">374 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L375" class="LineNr">375 </span><span class="CommentedCode">//? cerr << "comparing for modrm " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> -<span id="L376" class="LineNr">376 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this operand</span> -<span id="L377" class="LineNr">377 </span> <span class="Normal">const</span> string& optype = <a href='031check_operands.cc.html#L69'>Operand_type_name</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L378" class="LineNr">378 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <a href='031check_operands.cc.html#L61'>DISP8</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L379" class="LineNr">379 </span> <span class="Normal">int32_t</span> mod = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> -<span id="L380" class="LineNr">380 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Constant">1</span><span class="Delimiter">)</span> -<span id="L381" class="LineNr">381 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L382" class="LineNr">382 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// exception 2</span> -<span id="L383" class="LineNr">383 </span> <span class="Delimiter">}</span> -<span id="L384" class="LineNr">384 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <a href='031check_operands.cc.html#L63'>DISP32</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L385" class="LineNr">385 </span> <span class="Normal">int32_t</span> mod = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> -<span id="L386" class="LineNr">386 </span> <span class="Normal">int32_t</span> rm32 = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> -<span id="L387" class="LineNr">387 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod == <span class="Constant">0</span> && rm32 == <span class="Constant">5</span><span class="Delimiter">)</span> -<span id="L388" class="LineNr">388 </span> <span class="Delimiter">;</span> <span class="Comment">// ok: special-case for loading address from disp32</span> -<span id="L389" class="LineNr">389 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Constant">2</span><span class="Delimiter">)</span> -<span id="L390" class="LineNr">390 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L391" class="LineNr">391 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// exception 2</span> -<span id="L392" class="LineNr">392 </span> <span class="Delimiter">}</span> -<span id="L393" class="LineNr">393 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> -<span id="L394" class="LineNr">394 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L395" class="LineNr">395 </span> <span class="Normal">else</span> -<span id="L396" class="LineNr">396 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L397" class="LineNr">397 </span> <span class="Comment">// continue giving all errors for a single instruction</span> -<span id="L398" class="LineNr">398 </span> <span class="Delimiter">}</span> -<span id="L399" class="LineNr">399 </span> <span class="Comment">// ignore settings in any unused bits</span> -<span id="L400" class="LineNr">400 </span><span class="Delimiter">}</span> -<span id="L401" class="LineNr">401 </span> -<span id="L402" class="LineNr">402 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L402'>check_operand_metadata_present</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& type<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L403" class="LineNr">403 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> type<span class="Delimiter">))</span> -<span id="L404" class="LineNr">404 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << type << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L405" class="LineNr">405 </span><span class="Delimiter">}</span> -<span id="L406" class="LineNr">406 </span> -<span id="L407" class="LineNr">407 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L407'>check_operand_metadata_absent</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& type<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">,</span> <span class="Normal">const</span> string& msg<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L408" class="LineNr">408 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> type<span class="Delimiter">))</span> -<span id="L409" class="LineNr">409 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L275'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << type << <span class="Constant">" operand ("</span> << msg << <span class="Constant">")</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L410" class="LineNr">410 </span><span class="Delimiter">}</span> -<span id="L411" class="LineNr">411 </span> -<span id="L412" class="LineNr">412 </span><span class="Delimiter">:(scenarios transform)</span> -<span id="L413" class="LineNr">413 </span><span class="Delimiter">:(scenario modrm_with_displacement)</span> -<span id="L414" class="LineNr">414 </span><span class="Special">% Reg[EAX].u = 0x1;</span> -<span id="L415" class="LineNr">415 </span>== <span class="Constant">0x1</span> -<span id="L416" class="LineNr">416 </span><span class="Comment"># just avoid null pointer</span> -<span id="L417" class="LineNr">417 </span>8b/copy <span class="Constant">1</span>/mod/lookup+disp8 <span class="Constant">0</span>/rm32/EAX <span class="Constant">2</span>/r32/EDX <span class="Constant">4</span>/disp8 <span class="Comment"># copy *(EAX+4) to EDX</span> -<span id="L418" class="LineNr">418 </span>$error: <span class="Constant">0</span> -<span id="L419" class="LineNr">419 </span><span class="Delimiter">:(scenarios run)</span> -<span id="L420" class="LineNr">420 </span> -<span id="L421" class="LineNr">421 </span><span class="Delimiter">:(scenario conflicting_operands_in_modrm_instruction)</span> -<span id="L422" class="LineNr">422 </span><span class="Special">% Hide_errors = true;</span> -<span id="L423" class="LineNr">423 </span>== <span class="Constant">0x1</span> -<span id="L424" class="LineNr">424 </span><span class="PreProc">0</span><span class="Constant">1</span>/add <span class="Constant">0</span>/mod <span class="Constant">3</span>/mod -<span id="L425" class="LineNr">425 </span><span class="traceContains">+error: '01/add 0/mod 3/mod' has conflicting mod operands</span> -<span id="L426" class="LineNr">426 </span> -<span id="L427" class="LineNr">427 </span><span class="Delimiter">:(scenario conflicting_operand_type_modrm)</span> -<span id="L428" class="LineNr">428 </span><span class="Special">% Hide_errors = true;</span> -<span id="L429" class="LineNr">429 </span>== <span class="Constant">0x1</span> -<span id="L430" class="LineNr">430 </span><span class="PreProc">0</span><span class="Constant">1</span>/add <span class="Constant">0</span>/mod <span class="Constant">3</span>/rm32/r32 -<span id="L431" class="LineNr">431 </span><span class="traceContains">+error: '3/rm32/r32' has conflicting operand types; it should have only one</span> -<span id="L432" class="LineNr">432 </span> -<span id="L433" class="LineNr">433 </span><span class="Delimiter">:(scenario check_missing_rm32_operand)</span> -<span id="L434" class="LineNr">434 </span><span class="Special">% Hide_errors = true;</span> -<span id="L435" class="LineNr">435 </span>== <span class="Constant">0x1</span> -<span id="L436" class="LineNr">436 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod <span class="Constant">1</span>/imm32 -<span id="L437" class="LineNr">437 </span><span class="traceContains">+error: '81 0/add/subop 0/mod 1/imm32' (combine rm32 with imm32 based on subop): missing rm32 operand</span> -<span id="L438" class="LineNr">438 </span> -<span id="L439" class="LineNr">439 </span><span class="Delimiter">:(scenario check_missing_subop_operand)</span> -<span id="L440" class="LineNr">440 </span><span class="Special">% Hide_errors = true;</span> -<span id="L441" class="LineNr">441 </span>== <span class="Constant">0x1</span> -<span id="L442" class="LineNr">442 </span><span class="Constant">81</span> <span class="Constant">0</span>/mod <span class="Constant">3</span>/rm32/ebx <span class="Constant">1</span>/imm32 -<span id="L443" class="LineNr">443 </span><span class="traceContains">+error: '81 0/mod 3/rm32/ebx 1/imm32' (combine rm32 with imm32 based on subop): missing subop operand</span> -<span id="L444" class="LineNr">444 </span> -<span id="L445" class="LineNr">445 </span><span class="Delimiter">:(scenario check_missing_base_operand)</span> -<span id="L446" class="LineNr">446 </span><span class="Special">% Hide_errors = true;</span> -<span id="L447" class="LineNr">447 </span>== <span class="Constant">0x1</span> -<span id="L448" class="LineNr">448 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">1</span>/imm32 -<span id="L449" class="LineNr">449 </span><span class="traceContains">+error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 1/imm32' (combine rm32 with imm32 based on subop): missing base operand</span> -<span id="L450" class="LineNr">450 </span> -<span id="L451" class="LineNr">451 </span><span class="Delimiter">:(scenario check_missing_index_operand)</span> -<span id="L452" class="LineNr">452 </span><span class="Special">% Hide_errors = true;</span> -<span id="L453" class="LineNr">453 </span>== <span class="Constant">0x1</span> -<span id="L454" class="LineNr">454 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">0</span>/base <span class="Constant">1</span>/imm32 -<span id="L455" class="LineNr">455 </span><span class="traceContains">+error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 0/base 1/imm32' (combine rm32 with imm32 based on subop): missing index operand</span> -<span id="L456" class="LineNr">456 </span> -<span id="L457" class="LineNr">457 </span><span class="Delimiter">:(scenario check_missing_base_operand_2)</span> -<span id="L458" class="LineNr">458 </span><span class="Special">% Hide_errors = true;</span> -<span id="L459" class="LineNr">459 </span>== <span class="Constant">0x1</span> -<span id="L460" class="LineNr">460 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">2</span>/index <span class="Constant">3</span>/scale <span class="Constant">1</span>/imm32 -<span id="L461" class="LineNr">461 </span><span class="traceContains">+error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 2/index 3/scale 1/imm32' (combine rm32 with imm32 based on subop): missing base operand</span> -<span id="L462" class="LineNr">462 </span> -<span id="L463" class="LineNr">463 </span><span class="Delimiter">:(scenario check_extra_displacement)</span> -<span id="L464" class="LineNr">464 </span><span class="Special">% Hide_errors = true;</span> -<span id="L465" class="LineNr">465 </span>== <span class="Constant">0x1</span> -<span id="L466" class="LineNr">466 </span><span class="Constant">89</span>/copy <span class="Constant">0</span>/mod/indirect <span class="Constant">0</span>/rm32/EAX <span class="Constant">1</span>/r32/ECX <span class="Constant">4</span>/disp8 -<span id="L467" class="LineNr">467 </span><span class="traceContains">+error: '89/copy 0/mod/indirect 0/rm32/EAX 1/r32/ECX 4/disp8' (copy r32 to rm32): unexpected disp8 operand</span> -<span id="L468" class="LineNr">468 </span> -<span id="L469" class="LineNr">469 </span><span class="Delimiter">:(scenario check_base_operand_not_needed_in_direct_mode)</span> -<span id="L470" class="LineNr">470 </span>== <span class="Constant">0x1</span> -<span id="L471" class="LineNr">471 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">3</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">1</span>/imm32 -<span id="L472" class="LineNr">472 </span>$error: <span class="Constant">0</span> -<span id="L473" class="LineNr">473 </span> -<span id="L474" class="LineNr">474 </span><span class="SalientComment">//:: similarly handle multi-byte opcodes</span> -<span id="L475" class="LineNr">475 </span> -<span id="L476" class="LineNr">476 </span><span class="Delimiter">:(code)</span> -<span id="L477" class="LineNr">477 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L523'>check_operands_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L478" class="LineNr">478 </span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">);</span> -<span id="L479" class="LineNr">479 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L480" class="LineNr">480 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"opcode '0f' requires a second opcode</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L481" class="LineNr">481 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L482" class="LineNr">482 </span> <span class="Delimiter">}</span> -<span id="L483" class="LineNr">483 </span> <a href='011run.cc.html#L123'>word</a> op = <a href='031check_operands.cc.html#L36'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> -<span id="L484" class="LineNr">484 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L485" class="LineNr">485 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"unknown 2-byte opcode '0f "</span> << op<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L486" class="LineNr">486 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L487" class="LineNr">487 </span> <span class="Delimiter">}</span> -<span id="L488" class="LineNr">488 </span> <a href='031check_operands.cc.html#L523'>check_operands_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L358" class="LineNr">358 </span> <span class="Comment">// no check for scale; 0 (2**0 = 1) by default</span> +<span id="L359" class="LineNr">359 </span><span class="Delimiter">}</span> +<span id="L360" class="LineNr">360 </span> +<span id="L361" class="LineNr">361 </span><span class="Comment">// same as compare_bitvector, with a couple of exceptions for modrm-based instructions</span> +<span id="L362" class="LineNr">362 </span><span class="Comment">// exception 1: ignore modrm bit since we already checked it above</span> +<span id="L363" class="LineNr">363 </span><span class="Comment">// exception 2: modrm instructions can use a displacement on occasion</span> +<span id="L364" class="LineNr">364 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L364'>compare_bitvector_modrm</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L365" class="LineNr">365 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='031check_operands.cc.html#L288'>has_operands</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L366" class="LineNr">366 </span> <span class="Normal">uint8_t</span> bitvector = <a href='031check_operands.cc.html#L279'>compute_operand_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L367" class="LineNr">367 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> +<span id="L368" class="LineNr">368 </span> expected = CLEAR<span class="Delimiter">(</span>expected<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">);</span> <span class="Comment">// exception 1</span> +<span id="L369" class="LineNr">369 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> +<span id="L370" class="LineNr">370 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L371" class="LineNr">371 </span><span class="CommentedCode">//? cerr << "comparing for modrm " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> +<span id="L372" class="LineNr">372 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this operand</span> +<span id="L373" class="LineNr">373 </span> <span class="Normal">const</span> string& optype = <span class="Special"><a href='031check_operands.cc.html#L69'>Operand_type_name</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L374" class="LineNr">374 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <a href='031check_operands.cc.html#L61'>DISP8</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L375" class="LineNr">375 </span> <span class="Normal">int32_t</span> mod = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L376" class="LineNr">376 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Constant">1</span><span class="Delimiter">)</span> +<span id="L377" class="LineNr">377 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L378" class="LineNr">378 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// exception 2</span> +<span id="L379" class="LineNr">379 </span> <span class="Delimiter">}</span> +<span id="L380" class="LineNr">380 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i == <a href='031check_operands.cc.html#L63'>DISP32</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L381" class="LineNr">381 </span> <span class="Normal">int32_t</span> mod = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L382" class="LineNr">382 </span> <span class="Normal">int32_t</span> rm32 = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">).</span>data<span class="Delimiter">);</span> +<span id="L383" class="LineNr">383 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod == <span class="Constant">0</span> && rm32 == <span class="Constant">5</span><span class="Delimiter">)</span> +<span id="L384" class="LineNr">384 </span> <span class="Delimiter">;</span> <span class="Comment">// ok: special-case for loading address from disp32</span> +<span id="L385" class="LineNr">385 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>mod != <span class="Constant">2</span><span class="Delimiter">)</span> +<span id="L386" class="LineNr">386 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L387" class="LineNr">387 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// exception 2</span> +<span id="L388" class="LineNr">388 </span> <span class="Delimiter">}</span> +<span id="L389" class="LineNr">389 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> +<span id="L390" class="LineNr">390 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L391" class="LineNr">391 </span> <span class="Normal">else</span> +<span id="L392" class="LineNr">392 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L393" class="LineNr">393 </span> <span class="Comment">// continue giving all errors for a single instruction</span> +<span id="L394" class="LineNr">394 </span> <span class="Delimiter">}</span> +<span id="L395" class="LineNr">395 </span> <span class="Comment">// ignore settings in any unused bits</span> +<span id="L396" class="LineNr">396 </span><span class="Delimiter">}</span> +<span id="L397" class="LineNr">397 </span> +<span id="L398" class="LineNr">398 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L398'>check_operand_metadata_present</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& type<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L399" class="LineNr">399 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> type<span class="Delimiter">))</span> +<span id="L400" class="LineNr">400 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << type << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L401" class="LineNr">401 </span><span class="Delimiter">}</span> +<span id="L402" class="LineNr">402 </span> +<span id="L403" class="LineNr">403 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L403'>check_operand_metadata_absent</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> string& type<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">,</span> <span class="Normal">const</span> string& msg<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L404" class="LineNr">404 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> type<span class="Delimiter">))</span> +<span id="L405" class="LineNr">405 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L271'>maybe_name</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << type << <span class="Constant">" operand ("</span> << msg << <span class="Constant">")\n"</span> << end<span class="Delimiter">();</span> +<span id="L406" class="LineNr">406 </span><span class="Delimiter">}</span> +<span id="L407" class="LineNr">407 </span> +<span id="L408" class="LineNr">408 </span><span class="Delimiter">:(scenarios transform)</span> +<span id="L409" class="LineNr">409 </span><span class="Delimiter">:(scenario modrm_with_displacement)</span> +<span id="L410" class="LineNr">410 </span><span class="Special">% Reg[EAX].u = 0x1;</span> +<span id="L411" class="LineNr">411 </span>== <span class="Constant">0x1</span> +<span id="L412" class="LineNr">412 </span><span class="Comment"># just avoid null pointer</span> +<span id="L413" class="LineNr">413 </span>8b/copy <span class="Constant">1</span>/mod/lookup+disp8 <span class="Constant">0</span>/rm32/EAX <span class="Constant">2</span>/r32/EDX <span class="Constant">4</span>/disp8 <span class="Comment"># copy *(EAX+4) to EDX</span> +<span id="L414" class="LineNr">414 </span>$error: <span class="Constant">0</span> +<span id="L415" class="LineNr">415 </span><span class="Delimiter">:(scenarios run)</span> +<span id="L416" class="LineNr">416 </span> +<span id="L417" class="LineNr">417 </span><span class="Delimiter">:(scenario conflicting_operands_in_modrm_instruction)</span> +<span id="L418" class="LineNr">418 </span><span class="Special">% Hide_errors = true;</span> +<span id="L419" class="LineNr">419 </span>== <span class="Constant">0x1</span> +<span id="L420" class="LineNr">420 </span><span class="PreProc">0</span><span class="Constant">1</span>/add <span class="Constant">0</span>/mod <span class="Constant">3</span>/mod +<span id="L421" class="LineNr">421 </span><span class="traceContains">+error: '01/add 0/mod 3/mod' has conflicting mod operands</span> +<span id="L422" class="LineNr">422 </span> +<span id="L423" class="LineNr">423 </span><span class="Delimiter">:(scenario conflicting_operand_type_modrm)</span> +<span id="L424" class="LineNr">424 </span><span class="Special">% Hide_errors = true;</span> +<span id="L425" class="LineNr">425 </span>== <span class="Constant">0x1</span> +<span id="L426" class="LineNr">426 </span><span class="PreProc">0</span><span class="Constant">1</span>/add <span class="Constant">0</span>/mod <span class="Constant">3</span>/rm32/r32 +<span id="L427" class="LineNr">427 </span><span class="traceContains">+error: '3/rm32/r32' has conflicting operand types; it should have only one</span> +<span id="L428" class="LineNr">428 </span> +<span id="L429" class="LineNr">429 </span><span class="Delimiter">:(scenario check_missing_rm32_operand)</span> +<span id="L430" class="LineNr">430 </span><span class="Special">% Hide_errors = true;</span> +<span id="L431" class="LineNr">431 </span>== <span class="Constant">0x1</span> +<span id="L432" class="LineNr">432 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod <span class="Constant">1</span>/imm32 +<span id="L433" class="LineNr">433 </span><span class="traceContains">+error: '81 0/add/subop 0/mod 1/imm32' (combine rm32 with imm32 based on subop): missing rm32 operand</span> +<span id="L434" class="LineNr">434 </span> +<span id="L435" class="LineNr">435 </span><span class="Delimiter">:(scenario check_missing_subop_operand)</span> +<span id="L436" class="LineNr">436 </span><span class="Special">% Hide_errors = true;</span> +<span id="L437" class="LineNr">437 </span>== <span class="Constant">0x1</span> +<span id="L438" class="LineNr">438 </span><span class="Constant">81</span> <span class="Constant">0</span>/mod <span class="Constant">3</span>/rm32/ebx <span class="Constant">1</span>/imm32 +<span id="L439" class="LineNr">439 </span><span class="traceContains">+error: '81 0/mod 3/rm32/ebx 1/imm32' (combine rm32 with imm32 based on subop): missing subop operand</span> +<span id="L440" class="LineNr">440 </span> +<span id="L441" class="LineNr">441 </span><span class="Delimiter">:(scenario check_missing_base_operand)</span> +<span id="L442" class="LineNr">442 </span><span class="Special">% Hide_errors = true;</span> +<span id="L443" class="LineNr">443 </span>== <span class="Constant">0x1</span> +<span id="L444" class="LineNr">444 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">1</span>/imm32 +<span id="L445" class="LineNr">445 </span><span class="traceContains">+error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 1/imm32' (combine rm32 with imm32 based on subop): missing base operand</span> +<span id="L446" class="LineNr">446 </span> +<span id="L447" class="LineNr">447 </span><span class="Delimiter">:(scenario check_missing_index_operand)</span> +<span id="L448" class="LineNr">448 </span><span class="Special">% Hide_errors = true;</span> +<span id="L449" class="LineNr">449 </span>== <span class="Constant">0x1</span> +<span id="L450" class="LineNr">450 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">0</span>/base <span class="Constant">1</span>/imm32 +<span id="L451" class="LineNr">451 </span><span class="traceContains">+error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 0/base 1/imm32' (combine rm32 with imm32 based on subop): missing index operand</span> +<span id="L452" class="LineNr">452 </span> +<span id="L453" class="LineNr">453 </span><span class="Delimiter">:(scenario check_missing_base_operand_2)</span> +<span id="L454" class="LineNr">454 </span><span class="Special">% Hide_errors = true;</span> +<span id="L455" class="LineNr">455 </span>== <span class="Constant">0x1</span> +<span id="L456" class="LineNr">456 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">0</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">2</span>/index <span class="Constant">3</span>/scale <span class="Constant">1</span>/imm32 +<span id="L457" class="LineNr">457 </span><span class="traceContains">+error: '81 0/add/subop 0/mod/indirect 4/rm32/use-sib 2/index 3/scale 1/imm32' (combine rm32 with imm32 based on subop): missing base operand</span> +<span id="L458" class="LineNr">458 </span> +<span id="L459" class="LineNr">459 </span><span class="Delimiter">:(scenario check_extra_displacement)</span> +<span id="L460" class="LineNr">460 </span><span class="Special">% Hide_errors = true;</span> +<span id="L461" class="LineNr">461 </span>== <span class="Constant">0x1</span> +<span id="L462" class="LineNr">462 </span><span class="Constant">89</span>/copy <span class="Constant">0</span>/mod/indirect <span class="Constant">0</span>/rm32/EAX <span class="Constant">1</span>/r32/ECX <span class="Constant">4</span>/disp8 +<span id="L463" class="LineNr">463 </span><span class="traceContains">+error: '89/copy 0/mod/indirect 0/rm32/EAX 1/r32/ECX 4/disp8' (copy r32 to rm32): unexpected disp8 operand</span> +<span id="L464" class="LineNr">464 </span> +<span id="L465" class="LineNr">465 </span><span class="Delimiter">:(scenario check_base_operand_not_needed_in_direct_mode)</span> +<span id="L466" class="LineNr">466 </span>== <span class="Constant">0x1</span> +<span id="L467" class="LineNr">467 </span><span class="Constant">81</span> <span class="Constant">0</span>/add/subop <span class="Constant">3</span>/mod/indirect <span class="Constant">4</span>/rm32/use-sib <span class="Constant">1</span>/imm32 +<span id="L468" class="LineNr">468 </span>$error: <span class="Constant">0</span> +<span id="L469" class="LineNr">469 </span> +<span id="L470" class="LineNr">470 </span><span class="SalientComment">//:: similarly handle multi-byte opcodes</span> +<span id="L471" class="LineNr">471 </span> +<span id="L472" class="LineNr">472 </span><span class="Delimiter">:(code)</span> +<span id="L473" class="LineNr">473 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L519'>check_operands_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L474" class="LineNr">474 </span> assert<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">).</span>data == <span class="Constant">"0f"</span><span class="Delimiter">);</span> +<span id="L475" class="LineNr">475 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">)</span> == <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L476" class="LineNr">476 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"opcode '0f' requires a second opcode\n"</span> << end<span class="Delimiter">();</span> +<span id="L477" class="LineNr">477 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L478" class="LineNr">478 </span> <span class="Delimiter">}</span> +<span id="L479" class="LineNr">479 </span> <a href='011run.cc.html#L123'>word</a> op = <a href='031check_operands.cc.html#L36'>preprocess_op</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">1</span><span class="Delimiter">));</span> +<span id="L480" class="LineNr">480 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L481" class="LineNr">481 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"unknown 2-byte opcode '0f "</span> << op<span class="Delimiter">.</span>data << <span class="Constant">"'\n"</span> << end<span class="Delimiter">();</span> +<span id="L482" class="LineNr">482 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L483" class="LineNr">483 </span> <span class="Delimiter">}</span> +<span id="L484" class="LineNr">484 </span> <a href='031check_operands.cc.html#L519'>check_operands_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L485" class="LineNr">485 </span><span class="Delimiter">}</span> +<span id="L486" class="LineNr">486 </span> +<span id="L487" class="LineNr">487 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L487'>check_operands_f3</a><span class="Delimiter">(</span><span class="Normal">const</span> line& <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L488" class="LineNr">488 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"no supported opcodes starting with f3\n"</span> << end<span class="Delimiter">();</span> <span id="L489" class="LineNr">489 </span><span class="Delimiter">}</span> <span id="L490" class="LineNr">490 </span> -<span id="L491" class="LineNr">491 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L491'>check_operands_f3</a><span class="Delimiter">(</span><span class="Normal">const</span> line& <span class="Comment">/*</span><span class="Comment">unused</span><span class="Comment">*/</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L492" class="LineNr">492 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"no supported opcodes starting with f3</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L493" class="LineNr">493 </span><span class="Delimiter">}</span> -<span id="L494" class="LineNr">494 </span> -<span id="L495" class="LineNr">495 </span><span class="Delimiter">:(scenario check_missing_disp16_operand)</span> -<span id="L496" class="LineNr">496 </span><span class="Special">% Hide_errors = true;</span> -<span id="L497" class="LineNr">497 </span>== <span class="Constant">0x1</span> -<span id="L498" class="LineNr">498 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L499" class="LineNr">499 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L500" class="LineNr">500 </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> -<span id="L501" class="LineNr">501 </span> <span class="Constant">0f</span> <span class="Constant">84</span> <span class="Comment"># jmp if ZF to ??</span> -<span id="L502" class="LineNr">502 </span><span class="traceContains">+error: '0f 84' (jump disp16 bytes away if equal, if ZF is set): missing disp16 operand</span> -<span id="L503" class="LineNr">503 </span> -<span id="L504" class="LineNr">504 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L505" class="LineNr">505 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">;</span> -<span id="L506" class="LineNr">506 </span><span class="Delimiter">:(before "End Init Permitted Operands")</span> -<span id="L507" class="LineNr">507 </span><span class="SalientComment">//// Class C: just op and disp16</span> -<span id="L508" class="LineNr">508 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L509" class="LineNr">509 </span><span class="Comment">// 0 0 0 |1 0 0 0</span> -<span id="L510" class="LineNr">510 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"84"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> -<span id="L511" class="LineNr">511 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"85"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> -<span id="L512" class="LineNr">512 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"8c"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> -<span id="L513" class="LineNr">513 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> -<span id="L514" class="LineNr">514 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"8e"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> -<span id="L515" class="LineNr">515 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">0x08</span><span class="Delimiter">);</span> -<span id="L516" class="LineNr">516 </span> -<span id="L517" class="LineNr">517 </span><span class="SalientComment">//// Class M: using ModR/M byte</span> -<span id="L518" class="LineNr">518 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> -<span id="L519" class="LineNr">519 </span><span class="Comment">// 0 0 0 |0 0 0 1</span> -<span id="L520" class="LineNr">520 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> <span class="Constant">"af"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> -<span id="L521" class="LineNr">521 </span> -<span id="L522" class="LineNr">522 </span><span class="Delimiter">:(code)</span> -<span id="L523" class="LineNr">523 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L523'>check_operands_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L524" class="LineNr">524 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><a href='031check_operands.cc.html#L505'>Permitted_operands_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> -<span id="L525" class="LineNr">525 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">))</span> -<span id="L526" class="LineNr">526 </span> <a href='031check_operands.cc.html#L341'>check_operands_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> -<span id="L527" class="LineNr">527 </span> <a href='031check_operands.cc.html#L530'>compare_bitvector_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> CLEAR<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">),</span> op<span class="Delimiter">);</span> -<span id="L528" class="LineNr">528 </span><span class="Delimiter">}</span> -<span id="L529" class="LineNr">529 </span> -<span id="L530" class="LineNr">530 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L530'>compare_bitvector_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L531" class="LineNr">531 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='031check_operands.cc.html#L292'>has_operands</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> -<span id="L532" class="LineNr">532 </span> <span class="Normal">uint8_t</span> bitvector = <a href='031check_operands.cc.html#L283'>compute_operand_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> -<span id="L533" class="LineNr">533 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> -<span id="L534" class="LineNr">534 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> -<span id="L535" class="LineNr">535 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L536" class="LineNr">536 </span><span class="CommentedCode">//? cerr << "comparing " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> -<span id="L537" class="LineNr">537 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this operand</span> -<span id="L538" class="LineNr">538 </span> <span class="Normal">const</span> string& optype = <a href='031check_operands.cc.html#L69'>Operand_type_name</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L539" class="LineNr">539 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> -<span id="L540" class="LineNr">540 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L548'>maybe_name_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L541" class="LineNr">541 </span> <span class="Normal">else</span> -<span id="L542" class="LineNr">542 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L548'>maybe_name_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << optype << <span class="Constant">" operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L543" class="LineNr">543 </span> <span class="Comment">// continue giving all errors for a single instruction</span> -<span id="L544" class="LineNr">544 </span> <span class="Delimiter">}</span> -<span id="L545" class="LineNr">545 </span> <span class="Comment">// ignore settings in any unused bits</span> -<span id="L546" class="LineNr">546 </span><span class="Delimiter">}</span> -<span id="L547" class="LineNr">547 </span> -<span id="L548" class="LineNr">548 </span>string <a href='031check_operands.cc.html#L548'>maybe_name_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L549" class="LineNr">549 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> -<span id="L550" class="LineNr">550 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> -<span id="L551" class="LineNr">551 </span> <span class="Comment">// strip stuff in parens from the name</span> -<span id="L552" class="LineNr">552 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><a href='010---vm.cc.html#L370'>Name_0f</a><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> -<span id="L553" class="LineNr">553 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> -<span id="L554" class="LineNr">554 </span><span class="Delimiter">}</span> -<span id="L555" class="LineNr">555 </span> -<span id="L556" class="LineNr">556 </span>string <a href='031check_operands.cc.html#L556'>tolower</a><span class="Delimiter">(</span><span class="Normal">const</span> <span class="Normal">char</span>* s<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L557" class="LineNr">557 </span> ostringstream out<span class="Delimiter">;</span> -<span id="L558" class="LineNr">558 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> *s<span class="Delimiter">;</span> ++s<span class="Delimiter">)</span> -<span id="L559" class="LineNr">559 </span> out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span><a href='031check_operands.cc.html#L556'>tolower</a><span class="Delimiter">(</span>*s<span class="Delimiter">));</span> -<span id="L560" class="LineNr">560 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span id="L561" class="LineNr">561 </span><span class="Delimiter">}</span> +<span id="L491" class="LineNr">491 </span><span class="Delimiter">:(scenario check_missing_disp32_operand)</span> +<span id="L492" class="LineNr">492 </span><span class="Special">% Hide_errors = true;</span> +<span id="L493" class="LineNr">493 </span>== <span class="Constant">0x1</span> +<span id="L494" class="LineNr">494 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L495" class="LineNr">495 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L496" class="LineNr">496 </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> +<span id="L497" class="LineNr">497 </span> <span class="Constant">0f</span> <span class="Constant">84</span> <span class="Comment"># jmp if ZF to ??</span> +<span id="L498" class="LineNr">498 </span><span class="traceContains">+error: '0f 84' (jump disp32 bytes away if equal, if ZF is set): missing disp32 operand</span> +<span id="L499" class="LineNr">499 </span> +<span id="L500" class="LineNr">500 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L501" class="LineNr">501 </span>map<<span class="Comment">/*</span><span class="Comment">op</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Comment">/*</span><span class="Comment">bitvector</span><span class="Comment">*/</span><span class="Normal">uint8_t</span>> <span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">;</span> +<span id="L502" class="LineNr">502 </span><span class="Delimiter">:(before "End Init Permitted Operands")</span> +<span id="L503" class="LineNr">503 </span><span class="SalientComment">//// Class D: just op and disp32</span> +<span id="L504" class="LineNr">504 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L505" class="LineNr">505 </span><span class="Comment">// 0 0 1 |0 0 0 0</span> +<span id="L506" class="LineNr">506 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"84"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L507" class="LineNr">507 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"85"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L508" class="LineNr">508 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8c"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L509" class="LineNr">509 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8d"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L510" class="LineNr">510 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8e"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L511" class="LineNr">511 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"8f"</span><span class="Delimiter">,</span> <span class="Constant">0x10</span><span class="Delimiter">);</span> +<span id="L512" class="LineNr">512 </span> +<span id="L513" class="LineNr">513 </span><span class="SalientComment">//// Class M: using ModR/M byte</span> +<span id="L514" class="LineNr">514 </span><span class="Comment">// imm32 imm8 disp32 |disp16 disp8 subop modrm</span> +<span id="L515" class="LineNr">515 </span><span class="Comment">// 0 0 0 |0 0 0 1</span> +<span id="L516" class="LineNr">516 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> <span class="Constant">"af"</span><span class="Delimiter">,</span> <span class="Constant">0x01</span><span class="Delimiter">);</span> +<span id="L517" class="LineNr">517 </span> +<span id="L518" class="LineNr">518 </span><span class="Delimiter">:(code)</span> +<span id="L519" class="LineNr">519 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L519'>check_operands_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L520" class="LineNr">520 </span> <span class="Normal">uint8_t</span> expected_bitvector = get<span class="Delimiter">(</span><span class="Special"><a href='031check_operands.cc.html#L501'>Permitted_operands_0f</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L521" class="LineNr">521 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>HAS<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">))</span> +<span id="L522" class="LineNr">522 </span> <a href='031check_operands.cc.html#L337'>check_operands_modrm</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> op<span class="Delimiter">);</span> +<span id="L523" class="LineNr">523 </span> <a href='031check_operands.cc.html#L526'>compare_bitvector_0f</a><span class="Delimiter">(</span>inst<span class="Delimiter">,</span> CLEAR<span class="Delimiter">(</span>expected_bitvector<span class="Delimiter">,</span> <a href='031check_operands.cc.html#L59'>MODRM</a><span class="Delimiter">),</span> op<span class="Delimiter">);</span> +<span id="L524" class="LineNr">524 </span><span class="Delimiter">}</span> +<span id="L525" class="LineNr">525 </span> +<span id="L526" class="LineNr">526 </span><span class="Normal">void</span> <a href='031check_operands.cc.html#L526'>compare_bitvector_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">,</span> <span class="Normal">uint8_t</span> expected<span class="Delimiter">,</span> <span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L527" class="LineNr">527 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L379'>all_hex_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">)</span> && <a href='031check_operands.cc.html#L288'>has_operands</a><span class="Delimiter">(</span>inst<span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// deliberately programming in raw hex; we'll raise a warning elsewhere</span> +<span id="L528" class="LineNr">528 </span> <span class="Normal">uint8_t</span> bitvector = <a href='031check_operands.cc.html#L279'>compute_operand_bitvector</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L529" class="LineNr">529 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// duplicate operand type</span> +<span id="L530" class="LineNr">530 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>bitvector == expected<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// all good with this instruction</span> +<span id="L531" class="LineNr">531 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='031check_operands.cc.html#L66'>NUM_OPERAND_TYPES</a><span class="Delimiter">;</span> ++i<span class="Delimiter">,</span> bitvector >>= <span class="Constant">1</span><span class="Delimiter">,</span> expected >>= <span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L532" class="LineNr">532 </span><span class="CommentedCode">//? cerr << "comparing " << HEXBYTE << NUM(bitvector) << " with " << NUM(expected) << '\n';</span> +<span id="L533" class="LineNr">533 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> == <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// all good with this operand</span> +<span id="L534" class="LineNr">534 </span> <span class="Normal">const</span> string& optype = <span class="Special"><a href='031check_operands.cc.html#L69'>Operand_type_name</a></span><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L535" class="LineNr">535 </span> <span class="Normal">if</span> <span class="Delimiter">((</span>bitvector & <span class="Constant">0x1</span><span class="Delimiter">)</span> > <span class="Delimiter">(</span>expected & <span class="Constant">0x1</span><span class="Delimiter">))</span> +<span id="L536" class="LineNr">536 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L544'>maybe_name_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": unexpected "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L537" class="LineNr">537 </span> <span class="Normal">else</span> +<span id="L538" class="LineNr">538 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << <a href='031check_operands.cc.html#L544'>maybe_name_0f</a><span class="Delimiter">(</span>op<span class="Delimiter">)</span> << <span class="Constant">": missing "</span> << optype << <span class="Constant">" operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L539" class="LineNr">539 </span> <span class="Comment">// continue giving all errors for a single instruction</span> +<span id="L540" class="LineNr">540 </span> <span class="Delimiter">}</span> +<span id="L541" class="LineNr">541 </span> <span class="Comment">// ignore settings in any unused bits</span> +<span id="L542" class="LineNr">542 </span><span class="Delimiter">}</span> +<span id="L543" class="LineNr">543 </span> +<span id="L544" class="LineNr">544 </span>string <a href='031check_operands.cc.html#L544'>maybe_name_0f</a><span class="Delimiter">(</span><span class="Normal">const</span> word& op<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L545" class="LineNr">545 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!is_hex_byte<span class="Delimiter">(</span>op<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L546" class="LineNr">546 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">return</span> <span class="Constant">""</span><span class="Delimiter">;</span> +<span id="L547" class="LineNr">547 </span> <span class="Comment">// strip stuff in parens from the name</span> +<span id="L548" class="LineNr">548 </span> <span class="Normal">const</span> string& s = get<span class="Delimiter">(</span><span class="Special"><a href='010---vm.cc.html#L379'>Name_0f</a></span><span class="Delimiter">,</span> op<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L549" class="LineNr">549 </span> <span class="Identifier">return</span> <span class="Constant">" ("</span>+s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> s<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="Constant">" ("</span><span class="Delimiter">))</span>+<span class="Constant">')'</span><span class="Delimiter">;</span> +<span id="L550" class="LineNr">550 </span><span class="Delimiter">}</span> +<span id="L551" class="LineNr">551 </span> +<span id="L552" class="LineNr">552 </span>string <a href='031check_operands.cc.html#L552'>tolower</a><span class="Delimiter">(</span><span class="Normal">const</span> <span class="Normal">char</span>* s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L553" class="LineNr">553 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L554" class="LineNr">554 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Comment">/*</span><span class="Comment">nada</span><span class="Comment">*/</span><span class="Delimiter">;</span> *s<span class="Delimiter">;</span> ++s<span class="Delimiter">)</span> +<span id="L555" class="LineNr">555 </span> out << <span class="Normal">static_cast</span><<span class="Normal">char</span>><span class="Delimiter">(</span><a href='031check_operands.cc.html#L552'>tolower</a><span class="Delimiter">(</span>*s<span class="Delimiter">));</span> +<span id="L556" class="LineNr">556 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L557" class="LineNr">557 </span><span class="Delimiter">}</span> +<span id="L558" class="LineNr">558 </span> +<span id="L559" class="LineNr">559 </span><span class="Comment">#undef HAS</span> +<span id="L560" class="LineNr">560 </span><span class="Comment">#undef SET</span> +<span id="L561" class="LineNr">561 </span><span class="Comment">#undef CLEAR</span> <span id="L562" class="LineNr">562 </span> -<span id="L563" class="LineNr">563 </span><span class="Comment">#undef HAS</span> -<span id="L564" class="LineNr">564 </span><span class="Comment">#undef SET</span> -<span id="L565" class="LineNr">565 </span><span class="Comment">#undef CLEAR</span> -<span id="L566" class="LineNr">566 </span> -<span id="L567" class="LineNr">567 </span><span class="Delimiter">:(before "End Includes")</span> -<span id="L568" class="LineNr">568 </span><span class="Comment">#include<cctype></span> +<span id="L563" class="LineNr">563 </span><span class="Delimiter">:(before "End Includes")</span> +<span id="L564" class="LineNr">564 </span><span class="Comment">#include<cctype></span> </pre> </body> </html> diff --git a/html/subx/032check_operand_bounds.cc.html b/html/subx/032check_operand_bounds.cc.html index 9648b995..e21d0265 100644 --- a/html/subx/032check_operand_bounds.cc.html +++ b/html/subx/032check_operand_bounds.cc.html @@ -70,19 +70,19 @@ if ('onhashchange' in window) { <span id="L7" class="LineNr"> 7 </span><span class="traceContains">+error: '4/mod' too large to fit in bitfield mod</span> <span id="L8" class="LineNr"> 8 </span> <span id="L9" class="LineNr"> 9 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L10" class="LineNr">10 </span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>> <a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">;</span> +<span id="L10" class="LineNr">10 </span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>> <span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">;</span> <span id="L11" class="LineNr">11 </span><span class="Delimiter">:(before "End One-time Setup")</span> -<span id="L12" class="LineNr">12 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> -<span id="L13" class="LineNr">13 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">2</span><span class="Delimiter">);</span> -<span id="L14" class="LineNr">14 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> -<span id="L15" class="LineNr">15 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> -<span id="L16" class="LineNr">16 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> -<span id="L17" class="LineNr">17 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">2</span><span class="Delimiter">);</span> -<span id="L18" class="LineNr">18 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> -<span id="L19" class="LineNr">19 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">8</span><span class="Delimiter">);</span> -<span id="L20" class="LineNr">20 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">16</span><span class="Delimiter">);</span> +<span id="L12" class="LineNr">12 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"subop"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L13" class="LineNr">13 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L14" class="LineNr">14 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"rm32"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L15" class="LineNr">15 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"base"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L16" class="LineNr">16 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"index"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L17" class="LineNr">17 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"scale"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L18" class="LineNr">18 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"r32"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">3</span><span class="Delimiter">);</span> +<span id="L19" class="LineNr">19 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L20" class="LineNr">20 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">16</span><span class="Delimiter">);</span> <span id="L21" class="LineNr">21 </span><span class="Comment">// no bound needed for disp32</span> -<span id="L22" class="LineNr">22 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">8</span><span class="Delimiter">);</span> +<span id="L22" class="LineNr">22 </span><a href='001help.cc.html#L253'>put_new</a><span class="Delimiter">(</span><span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">,</span> <span class="Constant">"imm8"</span><span class="Delimiter">,</span> <span class="Constant">1</span><<<span class="Constant">8</span><span class="Delimiter">);</span> <span id="L23" class="LineNr">23 </span><span class="Comment">// no bound needed for imm32</span> <span id="L24" class="LineNr">24 </span> <span id="L25" class="LineNr">25 </span><span class="Delimiter">:(before "Pack Operands(segment code)")</span> @@ -93,14 +93,14 @@ if ('onhashchange' in window) { <span id="L30" class="LineNr">30 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- check operand bounds"</span> << end<span class="Delimiter">();</span> <span id="L31" class="LineNr">31 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L32" class="LineNr">32 </span> <span class="Normal">const</span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L33" class="LineNr">33 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <a href='031check_operands.cc.html#L296'>first_operand</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> +<span id="L33" class="LineNr">33 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <a href='031check_operands.cc.html#L292'>first_operand</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span id="L34" class="LineNr">34 </span> check_operand_bounds<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">));</span> <span id="L35" class="LineNr">35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span class="Comment">// stop at the first mal-formed instruction</span> <span id="L36" class="LineNr">36 </span> <span class="Delimiter">}</span> <span id="L37" class="LineNr">37 </span><span class="Delimiter">}</span> <span id="L38" class="LineNr">38 </span> <span id="L39" class="LineNr">39 </span><span class="Normal">void</span> check_operand_bounds<span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L40" class="LineNr">40 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>::iterator p = <a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L40" class="LineNr">40 </span> <span class="Normal">for</span> <span class="Delimiter">(</span>map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>::iterator p = <span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">.</span>begin<span class="Delimiter">();</span> p != <span class="Special"><a href='032check_operand_bounds.cc.html#L10'>Operand_bound</a></span><span class="Delimiter">.</span>end<span class="Delimiter">();</span> ++p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L41" class="LineNr">41 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_operand_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> p<span class="Delimiter">-></span>first<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L42" class="LineNr">42 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!looks_like_hex_int<span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// later transforms are on their own to do their own bounds checking</span> <span id="L43" class="LineNr">43 </span> <span class="Normal">int32_t</span> x = <a href='011run.cc.html#L362'>parse_int</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>data<span class="Delimiter">);</span> diff --git a/html/subx/034compute_segment_address.cc.html b/html/subx/034compute_segment_address.cc.html index 52753bc6..3a46ee38 100644 --- a/html/subx/034compute_segment_address.cc.html +++ b/html/subx/034compute_segment_address.cc.html @@ -15,11 +15,11 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } -.cSpecial { color: #008000; } .traceContains { color: #008000; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -82,45 +82,45 @@ if ('onhashchange' in window) { <span id="L21" class="LineNr"> 21 </span><span class="Comment">//: the new data to existing data for the segment.</span> <span id="L22" class="LineNr"> 22 </span> <span id="L23" class="LineNr"> 23 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L24" class="LineNr"> 24 </span>map<<span class="Comment">/*</span><span class="Comment">name</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Normal">int</span>> <a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">;</span> -<span id="L25" class="LineNr"> 25 </span><span class="Normal">bool</span> <a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// global to permit cross-layer communication</span> -<span id="L26" class="LineNr"> 26 </span><span class="Normal">int</span> <a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a> = -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// global to permit cross-layer communication</span> +<span id="L24" class="LineNr"> 24 </span>map<<span class="Comment">/*</span><span class="Comment">name</span><span class="Comment">*/</span>string<span class="Delimiter">,</span> <span class="Normal">int</span>> <span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">;</span> +<span id="L25" class="LineNr"> 25 </span><span class="Normal">bool</span> <span class="Special"><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// global to permit cross-layer communication</span> +<span id="L26" class="LineNr"> 26 </span><span class="Normal">int</span> <span class="Special"><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a></span> = -<span class="Constant">1</span><span class="Delimiter">;</span> <span class="Comment">// global to permit cross-layer communication</span> <span id="L27" class="LineNr"> 27 </span><span class="Delimiter">:(before "End Reset")</span> -<span id="L28" class="LineNr"> 28 </span><a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> -<span id="L29" class="LineNr"> 29 </span><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L30" class="LineNr"> 30 </span><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a> = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L28" class="LineNr"> 28 </span><span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> +<span id="L29" class="LineNr"> 29 </span><span class="Special"><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L30" class="LineNr"> 30 </span><span class="Special"><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a></span> = -<span class="Constant">1</span><span class="Delimiter">;</span> <span id="L31" class="LineNr"> 31 </span> <span id="L32" class="LineNr"> 32 </span><span class="Delimiter">:(before "End Segment Parsing Special-cases(segment_title)")</span> <span id="L33" class="LineNr"> 33 </span><span class="Normal">if</span> <span class="Delimiter">(</span>!starts_with<span class="Delimiter">(</span>segment_title<span class="Delimiter">,</span> <span class="Constant">"0x"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L34" class="LineNr"> 34 </span> <a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L35" class="LineNr"> 35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">,</span> segment_title<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Special"><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">,</span> segment_title<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L36" class="LineNr"> 36 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"new segment '"</span> << segment_title << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> <span id="L37" class="LineNr"> 37 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>segment_title == <span class="Constant">"code"</span><span class="Delimiter">)</span> -<span id="L38" class="LineNr"> 38 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">,</span> segment_title<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L38" class="LineNr"> 38 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">,</span> segment_title<span class="Delimiter">,</span> <span class="Constant">0</span><span class="Delimiter">);</span> <span id="L39" class="LineNr"> 39 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>segment_title == <span class="Constant">"data"</span><span class="Delimiter">)</span> -<span id="L40" class="LineNr"> 40 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">,</span> segment_title<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L40" class="LineNr"> 40 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">,</span> segment_title<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> <span id="L41" class="LineNr"> 41 </span> <span class="Normal">else</span> -<span id="L42" class="LineNr"> 42 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">,</span> segment_title<span class="Delimiter">,</span> max<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>out<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">)));</span> +<span id="L42" class="LineNr"> 42 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">,</span> segment_title<span class="Delimiter">,</span> max<span class="Delimiter">(</span><span class="Constant">2</span><span class="Delimiter">,</span> <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>out<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">)));</span> <span id="L43" class="LineNr"> 43 </span> out<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>segment<span class="Delimiter">());</span> <span id="L44" class="LineNr"> 44 </span> <span class="Delimiter">}</span> <span id="L45" class="LineNr"> 45 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> <span id="L46" class="LineNr"> 46 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"prepending to segment '"</span> << segment_title << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> <span id="L47" class="LineNr"> 47 </span> <span class="Delimiter">}</span> -<span id="L48" class="LineNr"> 48 </span> <a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a> = get<span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L24'>Segment_index</a><span class="Delimiter">,</span> segment_title<span class="Delimiter">);</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Special"><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a></span> = get<span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L24'>Segment_index</a></span><span class="Delimiter">,</span> segment_title<span class="Delimiter">);</span> <span id="L49" class="LineNr"> 49 </span><span class="Delimiter">}</span> <span id="L50" class="LineNr"> 50 </span> <span id="L51" class="LineNr"> 51 </span><span class="Delimiter">:(before "End flush(p, lines) Special-cases")</span> -<span id="L52" class="LineNr"> 52 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || <a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a> < <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"input does not start with a '==' section header</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L52" class="LineNr"> 52 </span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a></span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">()</span> || <span class="Special"><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a></span> < <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"input does not start with a '==' section header\n"</span> << end<span class="Delimiter">();</span> <span id="L55" class="LineNr"> 55 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L56" class="LineNr"> 56 </span> <span class="Delimiter">}</span> <span id="L57" class="LineNr"> 57 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse"</span><span class="Delimiter">)</span> << <span class="Constant">"flushing to segment"</span> << end<span class="Delimiter">();</span> -<span id="L58" class="LineNr"> 58 </span> vector<line>& curr_segment_data = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a><span class="Delimiter">).</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">;</span> +<span id="L58" class="LineNr"> 58 </span> vector<line>& curr_segment_data = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Special"><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a></span><span class="Delimiter">).</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">;</span> <span id="L59" class="LineNr"> 59 </span> curr_segment_data<span class="Delimiter">.</span>insert<span class="Delimiter">(</span>curr_segment_data<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> <a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> <a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>end<span class="Delimiter">());</span> <span id="L60" class="LineNr"> 60 </span> <a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>clear<span class="Delimiter">();</span> -<span id="L61" class="LineNr"> 61 </span> <a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L62" class="LineNr"> 62 </span> <a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a> = -<span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Special"><a href='034compute_segment_address.cc.html#L25'>Currently_parsing_named_segment</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Special"><a href='034compute_segment_address.cc.html#L26'>Currently_parsing_segment_index</a></span> = -<span class="Constant">1</span><span class="Delimiter">;</span> <span id="L63" class="LineNr"> 63 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L64" class="LineNr"> 64 </span><span class="Delimiter">}</span> <span id="L65" class="LineNr"> 65 </span> @@ -145,7 +145,7 @@ if ('onhashchange' in window) { <span id="L84" class="LineNr"> 84 </span><span class="Comment">//: compute segment address</span> <span id="L85" class="LineNr"> 85 </span> <span id="L86" class="LineNr"> 86 </span><span class="Delimiter">:(before "End Level-2 Transforms")</span> -<span id="L87" class="LineNr"> 87 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L90'>compute_segment_starts</a><span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='034compute_segment_address.cc.html#L90'>compute_segment_starts</a><span class="Delimiter">);</span> <span id="L88" class="LineNr"> 88 </span> <span id="L89" class="LineNr"> 89 </span><span class="Delimiter">:(code)</span> <span id="L90" class="LineNr"> 90 </span><span class="Normal">void</span> <a href='034compute_segment_address.cc.html#L90'>compute_segment_starts</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -155,14 +155,14 @@ if ('onhashchange' in window) { <span id="L94" class="LineNr"> 94 </span> segment& curr = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> <span id="L95" class="LineNr"> 95 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>start == <span class="Constant">0</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L96" class="LineNr"> 96 </span> curr<span class="Delimiter">.</span>start = <a href='012elf.cc.html#L135'>CODE_SEGMENT</a> + i*SPACE_FOR_SEGMENT + p_offset<span class="Delimiter">;</span> -<span id="L97" class="LineNr"> 97 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"segment "</span> << i << <span class="Constant">" begins at address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << curr<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> +<span id="L97" class="LineNr"> 97 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"segment "</span> << i << <span class="Constant">" begins at address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << curr<span class="Delimiter">.</span>start << end<span class="Delimiter">();</span> <span id="L98" class="LineNr"> 98 </span> <span class="Delimiter">}</span> -<span id="L99" class="LineNr"> 99 </span> p_offset += <a href='034compute_segment_address.cc.html#L104'>size_of</a><span class="Delimiter">(</span>curr<span class="Delimiter">);</span> -<span id="L100" class="LineNr">100 </span> assert<span class="Delimiter">(</span>p_offset < <a href='010---vm.cc.html#L115'>INITIAL_SEGMENT_SIZE</a><span class="Delimiter">);</span> <span class="Comment">// for now we get less and less available space in each successive segment</span> +<span id="L99" class="LineNr"> 99 </span> p_offset += size_of<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L100" class="LineNr">100 </span> assert<span class="Delimiter">(</span>p_offset < <a href='010---vm.cc.html#L115'>SEGMENT_ALIGNMENT</a><span class="Delimiter">);</span> <span class="Comment">// for now we get less and less available space in each successive segment</span> <span id="L101" class="LineNr">101 </span> <span class="Delimiter">}</span> <span id="L102" class="LineNr">102 </span><span class="Delimiter">}</span> <span id="L103" class="LineNr">103 </span> -<span id="L104" class="LineNr">104 </span><span class="Normal">uint32_t</span> <a href='034compute_segment_address.cc.html#L104'>size_of</a><span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L104" class="LineNr">104 </span><span class="Normal">uint32_t</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> segment& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L105" class="LineNr">105 </span> <span class="Normal">uint32_t</span> sum = <span class="Constant">0</span><span class="Delimiter">;</span> <span id="L106" class="LineNr">106 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span id="L107" class="LineNr">107 </span> sum += <a href='034compute_segment_address.cc.html#L112'>num_bytes</a><span class="Delimiter">(</span>s<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> @@ -172,31 +172,35 @@ if ('onhashchange' in window) { <span id="L111" class="LineNr">111 </span><span class="Comment">// Assumes all bitfields are packed.</span> <span id="L112" class="LineNr">112 </span><span class="Normal">uint32_t</span> <a href='034compute_segment_address.cc.html#L112'>num_bytes</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L113" class="LineNr">113 </span> <span class="Normal">uint32_t</span> sum = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L114" class="LineNr">114 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L115" class="LineNr">115 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L116" class="LineNr">116 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> || has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Comment">// only multi-byte operands</span> -<span id="L117" class="LineNr">117 </span> sum += <span class="Constant">4</span><span class="Delimiter">;</span> -<span id="L118" class="LineNr">118 </span> <span class="Comment">// End num_bytes(curr) Special-cases</span> -<span id="L119" class="LineNr">119 </span> <span class="Normal">else</span> -<span id="L120" class="LineNr">120 </span> sum++<span class="Delimiter">;</span> -<span id="L121" class="LineNr">121 </span> <span class="Delimiter">}</span> -<span id="L122" class="LineNr">122 </span> <span class="Identifier">return</span> sum<span class="Delimiter">;</span> -<span id="L123" class="LineNr">123 </span><span class="Delimiter">}</span> -<span id="L124" class="LineNr">124 </span> -<span id="L125" class="LineNr">125 </span><span class="Comment">//: Dependencies:</span> -<span id="L126" class="LineNr">126 </span><span class="Comment">//: - We'd like to compute segment addresses before setting up global variables,</span> -<span id="L127" class="LineNr">127 </span><span class="Comment">//: because computing addresses for global variables requires knowing where</span> -<span id="L128" class="LineNr">128 </span><span class="Comment">//: the data segment starts.</span> -<span id="L129" class="LineNr">129 </span><span class="Comment">//: - We'd like to finish expanding labels before computing segment addresses,</span> -<span id="L130" class="LineNr">130 </span><span class="Comment">//: because it would make computing the sizes of segments more self-contained</span> -<span id="L131" class="LineNr">131 </span><span class="Comment">//: (num_bytes).</span> -<span id="L132" class="LineNr">132 </span><span class="Comment">//:</span> -<span id="L133" class="LineNr">133 </span><span class="Comment">//: Decision: compute segment addresses before expanding labels, by being</span> -<span id="L134" class="LineNr">134 </span><span class="Comment">//: aware in this layer of certain operand types that will eventually occupy</span> -<span id="L135" class="LineNr">135 </span><span class="Comment">//: multiple bytes.</span> +<span id="L114" class="LineNr">114 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L115" class="LineNr">115 </span> sum += size_of<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L116" class="LineNr">116 </span> <span class="Identifier">return</span> sum<span class="Delimiter">;</span> +<span id="L117" class="LineNr">117 </span><span class="Delimiter">}</span> +<span id="L118" class="LineNr">118 </span> +<span id="L119" class="LineNr">119 </span><span class="Normal">int</span> size_of<span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L120" class="LineNr">120 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> || has_operand_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> +<span id="L121" class="LineNr">121 </span> <span class="Identifier">return</span> <span class="Constant">4</span><span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>w<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> +<span id="L123" class="LineNr">123 </span> <span class="Identifier">return</span> <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L124" class="LineNr">124 </span> <span class="Comment">// End size_of(word w) Special-cases</span> +<span id="L125" class="LineNr">125 </span> <span class="Normal">else</span> +<span id="L126" class="LineNr">126 </span> <span class="Identifier">return</span> <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L127" class="LineNr">127 </span><span class="Delimiter">}</span> +<span id="L128" class="LineNr">128 </span> +<span id="L129" class="LineNr">129 </span><span class="Comment">//: Dependencies:</span> +<span id="L130" class="LineNr">130 </span><span class="Comment">//: - We'd like to compute segment addresses before setting up global variables,</span> +<span id="L131" class="LineNr">131 </span><span class="Comment">//: because computing addresses for global variables requires knowing where</span> +<span id="L132" class="LineNr">132 </span><span class="Comment">//: the data segment starts.</span> +<span id="L133" class="LineNr">133 </span><span class="Comment">//: - We'd like to finish expanding labels before computing segment addresses,</span> +<span id="L134" class="LineNr">134 </span><span class="Comment">//: because it would make computing the sizes of segments more self-contained</span> +<span id="L135" class="LineNr">135 </span><span class="Comment">//: (num_bytes).</span> <span id="L136" class="LineNr">136 </span><span class="Comment">//:</span> -<span id="L137" class="LineNr">137 </span><span class="Comment">//: The layer to expand labels later hooks into num_bytes() to teach this</span> -<span id="L138" class="LineNr">138 </span><span class="Comment">//: layer that labels occupy zero space in the binary.</span> +<span id="L137" class="LineNr">137 </span><span class="Comment">//: Decision: compute segment addresses before expanding labels, by being</span> +<span id="L138" class="LineNr">138 </span><span class="Comment">//: aware in this layer of certain operand types that will eventually occupy</span> +<span id="L139" class="LineNr">139 </span><span class="Comment">//: multiple bytes.</span> +<span id="L140" class="LineNr">140 </span><span class="Comment">//:</span> +<span id="L141" class="LineNr">141 </span><span class="Comment">//: The layer to expand labels later hooks into num_bytes() to teach this</span> +<span id="L142" class="LineNr">142 </span><span class="Comment">//: layer that labels occupy zero space in the binary.</span> </pre> </body> </html> diff --git a/html/subx/035labels.cc.html b/html/subx/035labels.cc.html index a00b1bc7..2e388d80 100644 --- a/html/subx/035labels.cc.html +++ b/html/subx/035labels.cc.html @@ -113,19 +113,19 @@ if ('onhashchange' in window) { <span id="L51" class="LineNr"> 51 </span><span class="Delimiter">:(code)</span> <span id="L52" class="LineNr"> 52 </span><span class="Normal">void</span> <a href='035labels.cc.html#L52'>check_valid_name</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L53" class="LineNr"> 53 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Delimiter">{</span> -<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"empty name!</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L54" class="LineNr"> 54 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"empty name!\n"</span> << end<span class="Delimiter">();</span> <span id="L55" class="LineNr"> 55 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L56" class="LineNr"> 56 </span> <span class="Delimiter">}</span> <span id="L57" class="LineNr"> 57 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> == <span class="Constant">'-'</span><span class="Delimiter">)</span> -<span id="L58" class="LineNr"> 58 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' starts with '-', which can be confused with a negative number; use a different name</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L58" class="LineNr"> 58 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' starts with '-', which can be confused with a negative number; use a different name\n"</span> << end<span class="Delimiter">();</span> <span id="L59" class="LineNr"> 59 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>s<span class="Delimiter">.</span>substr<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">)</span> == <span class="Constant">"0x"</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L60" class="LineNr"> 60 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' looks like a hex number; use a different name</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L60" class="LineNr"> 60 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' looks like a hex number; use a different name\n"</span> << end<span class="Delimiter">();</span> <span id="L61" class="LineNr"> 61 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L62" class="LineNr"> 62 </span> <span class="Delimiter">}</span> <span id="L63" class="LineNr"> 63 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isdigit<span class="Delimiter">(</span>s<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)))</span> -<span id="L64" class="LineNr"> 64 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' starts with a digit, and so can be confused with a negative number; use a different name.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L64" class="LineNr"> 64 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' starts with a digit, and so can be confused with a negative number; use a different name.\n"</span> << end<span class="Delimiter">();</span> <span id="L65" class="LineNr"> 65 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>s<span class="Delimiter">)</span> == <span class="Constant">2</span><span class="Delimiter">)</span> -<span id="L66" class="LineNr"> 66 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' is two characters long which can look like raw hex bytes at a glance; use a different name</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L66" class="LineNr"> 66 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << s << <span class="Constant">"' is two characters long which can look like raw hex bytes at a glance; use a different name\n"</span> << end<span class="Delimiter">();</span> <span id="L67" class="LineNr"> 67 </span><span class="Delimiter">}</span> <span id="L68" class="LineNr"> 68 </span> <span id="L69" class="LineNr"> 69 </span><span class="Comment">//: Now that that's done, let's start using names as labels.</span> @@ -137,7 +137,7 @@ if ('onhashchange' in window) { <span id="L75" class="LineNr"> 75 </span><span class="traceContains">+transform: label 'loop' is at address 1</span> <span id="L76" class="LineNr"> 76 </span> <span id="L77" class="LineNr"> 77 </span><span class="Delimiter">:(before "End Level-2 Transforms")</span> -<span id="L78" class="LineNr"> 78 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='035labels.cc.html#L80'>rewrite_labels</a><span class="Delimiter">);</span> +<span id="L78" class="LineNr"> 78 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='035labels.cc.html#L80'>rewrite_labels</a><span class="Delimiter">);</span> <span id="L79" class="LineNr"> 79 </span><span class="Delimiter">:(code)</span> <span id="L80" class="LineNr"> 80 </span><span class="Normal">void</span> <a href='035labels.cc.html#L80'>rewrite_labels</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L81" class="LineNr"> 81 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- rewrite labels"</span> << end<span class="Delimiter">();</span> @@ -146,9 +146,9 @@ if ('onhashchange' in window) { <span id="L84" class="LineNr"> 84 </span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>> byte_index<span class="Delimiter">;</span> <span class="Comment">// values are unsigned, but we're going to do subtractions on them so they need to fit in 31 bits</span> <span id="L85" class="LineNr"> 85 </span> <a href='035labels.cc.html#L92'>compute_byte_indices_for_labels</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> byte_index<span class="Delimiter">);</span> <span id="L86" class="LineNr"> 86 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L87" class="LineNr"> 87 </span> <a href='035labels.cc.html#L148'>drop_labels</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">);</span> +<span id="L87" class="LineNr"> 87 </span> <a href='035labels.cc.html#L153'>drop_labels</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">);</span> <span id="L88" class="LineNr"> 88 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L89" class="LineNr"> 89 </span> <a href='035labels.cc.html#L160'>replace_labels_with_displacements</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> byte_index<span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span> <a href='035labels.cc.html#L165'>replace_labels_with_displacements</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> byte_index<span class="Delimiter">);</span> <span id="L90" class="LineNr"> 90 </span><span class="Delimiter">}</span> <span id="L91" class="LineNr"> 91 </span> <span id="L92" class="LineNr"> 92 </span><span class="Normal">void</span> <a href='035labels.cc.html#L92'>compute_byte_indices_for_labels</a><span class="Delimiter">(</span><span class="Normal">const</span> segment& <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>>& byte_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> @@ -164,172 +164,177 @@ if ('onhashchange' in window) { <span id="L102" class="LineNr">102 </span> <span class="Comment">// have to deal with bitfields.</span> <span id="L103" class="LineNr">103 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> || has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> <span id="L104" class="LineNr">104 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">)</span> -<span id="L105" class="LineNr">105 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': don't use ':' when jumping to labels</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> +<span id="L105" class="LineNr">105 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': don't use ':' when jumping to labels\n"</span> << end<span class="Delimiter">();</span> <span id="L106" class="LineNr">106 </span> current_byte += <span class="Constant">4</span><span class="Delimiter">;</span> <span id="L107" class="LineNr">107 </span> <span class="Delimiter">}</span> -<span id="L108" class="LineNr">108 </span> <span class="Comment">// automatically handle /disp8 and /imm8 here</span> -<span id="L109" class="LineNr">109 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L110" class="LineNr">110 </span> ++current_byte<span class="Delimiter">;</span> -<span id="L111" class="LineNr">111 </span> <span class="Delimiter">}</span> -<span id="L112" class="LineNr">112 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L113" class="LineNr">113 </span> string label = <a href='035labels.cc.html#L204'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> -<span id="L114" class="LineNr">114 </span> <span class="Comment">// ensure labels look sufficiently different from raw hex</span> -<span id="L115" class="LineNr">115 </span> <a href='035labels.cc.html#L52'>check_valid_name</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> -<span id="L116" class="LineNr">116 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L117" class="LineNr">117 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L396'>contains_any_operand_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">))</span> -<span id="L118" class="LineNr">118 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label definition (':') not allowed in operand</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L119" class="LineNr">119 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> -<span id="L120" class="LineNr">120 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': labels can only be the first <a href='011run.cc.html#L123'>word</a> in a line.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L121" class="LineNr">121 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='035labels.cc.html#L133'>Map_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> -<span id="L122" class="LineNr">122 </span> <a href='035labels.cc.html#L133'>Map_file</a> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << <span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span>start + current_byte<span class="Delimiter">)</span> << <span class="Constant">' '</span> << label << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> -<span id="L123" class="LineNr">123 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> label<span class="Delimiter">,</span> current_byte<span class="Delimiter">);</span> -<span id="L124" class="LineNr">124 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"label '"</span> << label << <span class="Constant">"' is at address "</span> << <span class="Delimiter">(</span>current_byte+code<span class="Delimiter">.</span>start<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> -<span id="L125" class="LineNr">125 </span> <span class="Comment">// no modifying current_byte; label definitions won't be in the final binary</span> -<span id="L126" class="LineNr">126 </span> <span class="Delimiter">}</span> -<span id="L127" class="LineNr">127 </span> <span class="Delimiter">}</span> -<span id="L128" class="LineNr">128 </span> <span class="Delimiter">}</span> -<span id="L129" class="LineNr">129 </span><span class="Delimiter">}</span> -<span id="L130" class="LineNr">130 </span> -<span id="L131" class="LineNr">131 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L132" class="LineNr">132 </span><span class="Normal">bool</span> <a href='035labels.cc.html#L132'>Dump_map</a> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// currently used only by 'subx translate'</span> -<span id="L133" class="LineNr">133 </span>ofstream <a href='035labels.cc.html#L133'>Map_file</a><span class="Delimiter">;</span> -<span id="L134" class="LineNr">134 </span><span class="Delimiter">:(before "End Commandline Options")</span> -<span id="L135" class="LineNr">135 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--map"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L136" class="LineNr">136 </span> <a href='035labels.cc.html#L132'>Dump_map</a> =<span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L137" class="LineNr">137 </span> <span class="Comment">// End --map Settings</span> -<span id="L138" class="LineNr">138 </span><span class="Delimiter">}</span> -<span id="L139" class="LineNr">139 </span><span class="Comment">//: wait to open "map" for writing until we're sure we aren't trying to read it</span> -<span id="L140" class="LineNr">140 </span><span class="Delimiter">:(after "Begin subx translate")</span> -<span id="L141" class="LineNr">141 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='035labels.cc.html#L132'>Dump_map</a><span class="Delimiter">)</span> -<span id="L142" class="LineNr">142 </span> <a href='035labels.cc.html#L133'>Map_file</a><span class="Delimiter">.</span>open<span class="Delimiter">(</span><span class="Constant">"map"</span><span class="Delimiter">);</span> -<span id="L143" class="LineNr">143 </span><span class="Delimiter">:(before "End subx translate")</span> -<span id="L144" class="LineNr">144 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='035labels.cc.html#L132'>Dump_map</a><span class="Delimiter">)</span> -<span id="L145" class="LineNr">145 </span> <a href='035labels.cc.html#L133'>Map_file</a><span class="Delimiter">.</span>close<span class="Delimiter">();</span> -<span id="L146" class="LineNr">146 </span> -<span id="L147" class="LineNr">147 </span><span class="Delimiter">:(code)</span> -<span id="L148" class="LineNr">148 </span><span class="Normal">void</span> <a href='035labels.cc.html#L148'>drop_labels</a><span class="Delimiter">(</span>segment& <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L149" class="LineNr">149 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L150" class="LineNr">150 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L151" class="LineNr">151 </span> vector<word>::iterator new_end = remove_if<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <a href='035labels.cc.html#L156'>is_label</a><span class="Delimiter">);</span> -<span id="L152" class="LineNr">152 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>erase<span class="Delimiter">(</span>new_end<span class="Delimiter">,</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L153" class="LineNr">153 </span> <span class="Delimiter">}</span> -<span id="L154" class="LineNr">154 </span><span class="Delimiter">}</span> -<span id="L155" class="LineNr">155 </span> -<span id="L156" class="LineNr">156 </span><span class="Normal">bool</span> <a href='035labels.cc.html#L156'>is_label</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L157" class="LineNr">157 </span> <span class="Identifier">return</span> *w<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">;</span> -<span id="L158" class="LineNr">158 </span><span class="Delimiter">}</span> -<span id="L159" class="LineNr">159 </span> -<span id="L160" class="LineNr">160 </span><span class="Normal">void</span> <a href='035labels.cc.html#L160'>replace_labels_with_displacements</a><span class="Delimiter">(</span>segment& <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>>& byte_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L161" class="LineNr">161 </span> <span class="Normal">int32_t</span> byte_index_next_instruction_starts_at = <span class="Constant">0</span><span class="Delimiter">;</span> -<span id="L162" class="LineNr">162 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L163" class="LineNr">163 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L164" class="LineNr">164 </span> byte_index_next_instruction_starts_at += <a href='034compute_segment_address.cc.html#L112'>num_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> -<span id="L165" class="LineNr">165 </span> <a href='011run.cc.html#L117'>line</a> new_inst<span class="Delimiter">;</span> -<span id="L166" class="LineNr">166 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L167" class="LineNr">167 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> -<span id="L168" class="LineNr">168 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L169" class="LineNr">169 </span> <span class="Normal">int32_t</span> displacement = <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span>get<span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> - byte_index_next_instruction_starts_at<span class="Delimiter">;</span> -<span id="L170" class="LineNr">170 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L171" class="LineNr">171 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>displacement > <span class="Constant">0xff</span> || displacement < -<span class="Constant">0x7f</span><span class="Delimiter">)</span> -<span id="L172" class="LineNr">172 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label too far away for displacement "</span> << std::hex << displacement << <span class="Constant">" to fit in 8 bits</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L173" class="LineNr">173 </span> <span class="Normal">else</span> -<span id="L174" class="LineNr">174 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> -<span id="L175" class="LineNr">175 </span> <span class="Delimiter">}</span> -<span id="L176" class="LineNr">176 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L177" class="LineNr">177 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>displacement > <span class="Constant">0xffff</span> || displacement < -<span class="Constant">0x7fff</span><span class="Delimiter">)</span> -<span id="L178" class="LineNr">178 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label too far away for displacement "</span> << std::hex << displacement << <span class="Constant">" to fit in 16 bits</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L179" class="LineNr">179 </span> <span class="Normal">else</span> -<span id="L180" class="LineNr">180 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> -<span id="L181" class="LineNr">181 </span> <span class="Delimiter">}</span> -<span id="L182" class="LineNr">182 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L183" class="LineNr">183 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> -<span id="L184" class="LineNr">184 </span> <span class="Delimiter">}</span> -<span id="L185" class="LineNr">185 </span> <span class="Delimiter">}</span> -<span id="L186" class="LineNr">186 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L187" class="LineNr">187 </span> new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> -<span id="L188" class="LineNr">188 </span> <span class="Delimiter">}</span> -<span id="L189" class="LineNr">189 </span> <span class="Delimiter">}</span> -<span id="L190" class="LineNr">190 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> -<span id="L191" class="LineNr">191 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after <a href='011run.cc.html#L231'>transform</a>: '"</span> << data_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> -<span id="L192" class="LineNr">192 </span> <span class="Delimiter">}</span> -<span id="L193" class="LineNr">193 </span><span class="Delimiter">}</span> -<span id="L194" class="LineNr">194 </span> -<span id="L195" class="LineNr">195 </span>string <a href='035labels.cc.html#L195'>data_to_string</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L196" class="LineNr">196 </span> ostringstream out<span class="Delimiter">;</span> -<span id="L197" class="LineNr">197 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L198" class="LineNr">198 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> -<span id="L199" class="LineNr">199 </span> out << inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> -<span id="L200" class="LineNr">200 </span> <span class="Delimiter">}</span> -<span id="L201" class="LineNr">201 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span id="L202" class="LineNr">202 </span><span class="Delimiter">}</span> -<span id="L203" class="LineNr">203 </span> -<span id="L204" class="LineNr">204 </span>string <a href='035labels.cc.html#L204'>drop_last</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L205" class="LineNr">205 </span> <span class="Identifier">return</span> string<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> --s<span class="Delimiter">.</span>end<span class="Delimiter">());</span> -<span id="L206" class="LineNr">206 </span><span class="Delimiter">}</span> -<span id="L207" class="LineNr">207 </span> -<span id="L208" class="LineNr">208 </span><span class="Comment">//: Label definitions must be the first word on a line. No jumping inside</span> -<span id="L209" class="LineNr">209 </span><span class="Comment">//: instructions.</span> -<span id="L210" class="LineNr">210 </span><span class="Comment">//: They should also be the only word on a line.</span> -<span id="L211" class="LineNr">211 </span><span class="Comment">//: However, you can absolutely have multiple labels map to the same address,</span> -<span id="L212" class="LineNr">212 </span><span class="Comment">//: as long as they're on separate lines.</span> -<span id="L213" class="LineNr">213 </span> -<span id="L214" class="LineNr">214 </span><span class="Delimiter">:(scenario multiple_labels_at)</span> -<span id="L215" class="LineNr">215 </span>== <span class="Constant">0x1</span> -<span id="L216" class="LineNr">216 </span><span class="Comment"># address 1</span> -<span id="L217" class="LineNr">217 </span><span class="Normal">loop</span>: -<span id="L218" class="LineNr">218 </span> $loop2: -<span id="L219" class="LineNr">219 </span><span class="Comment"># address 1 (labels take up no space)</span> -<span id="L220" class="LineNr">220 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 -<span id="L221" class="LineNr">221 </span><span class="Comment"># address 6</span> -<span id="L222" class="LineNr">222 </span> eb $loop2/disp8 -<span id="L223" class="LineNr">223 </span><span class="Comment"># address 8</span> -<span id="L224" class="LineNr">224 </span> eb $loop3/disp8 -<span id="L225" class="LineNr">225 </span><span class="Comment"># address 0xa</span> -<span id="L226" class="LineNr">226 </span> $loop3: -<span id="L227" class="LineNr">227 </span><span class="traceContains">+transform: label 'loop' is at address 1</span> -<span id="L228" class="LineNr">228 </span><span class="traceContains">+transform: label '$loop2' is at address 1</span> -<span id="L229" class="LineNr">229 </span><span class="traceContains">+transform: label '$loop3' is at address a</span> -<span id="L230" class="LineNr">230 </span><span class="Comment"># first jump is to -7</span> -<span id="L231" class="LineNr">231 </span><span class="traceContains">+transform: instruction after <a href='011run.cc.html#L231'>transform</a>: 'eb f9'</span> -<span id="L232" class="LineNr">232 </span><span class="Comment"># second jump is to 0 (fall through)</span> -<span id="L233" class="LineNr">233 </span><span class="traceContains">+transform: instruction after <a href='011run.cc.html#L231'>transform</a>: 'eb 00'</span> -<span id="L234" class="LineNr">234 </span> -<span id="L235" class="LineNr">235 </span><span class="Delimiter">:(scenario label_too_short)</span> -<span id="L236" class="LineNr">236 </span><span class="Special">% Hide_errors = true;</span> -<span id="L237" class="LineNr">237 </span>== <span class="Constant">0x1</span> -<span id="L238" class="LineNr">238 </span><span class="Normal">xz</span>: -<span id="L239" class="LineNr">239 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 -<span id="L240" class="LineNr">240 </span><span class="traceContains">+error: 'xz' is two characters long which can look like raw hex bytes at a glance; use a different name</span> -<span id="L241" class="LineNr">241 </span> -<span id="L242" class="LineNr">242 </span><span class="Delimiter">:(scenario label_hex)</span> -<span id="L243" class="LineNr">243 </span><span class="Special">% Hide_errors = true;</span> -<span id="L244" class="LineNr">244 </span>== <span class="Constant">0x1</span> -<span id="L245" class="LineNr">245 </span><span class="Constant">0xab</span>: -<span id="L246" class="LineNr">246 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 -<span id="L247" class="LineNr">247 </span><span class="traceContains">+error: '0xab' looks like a hex number; use a different name</span> -<span id="L248" class="LineNr">248 </span> -<span id="L249" class="LineNr">249 </span><span class="Delimiter">:(scenario label_negative_hex)</span> -<span id="L250" class="LineNr">250 </span><span class="Special">% Hide_errors = true;</span> -<span id="L251" class="LineNr">251 </span>== <span class="Constant">0x1</span> -<span id="L252" class="LineNr">252 </span> -a: <span class="Comment"># indent to avoid looking like a trace_should_not_contain command for this scenario</span> -<span id="L253" class="LineNr">253 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 -<span id="L254" class="LineNr">254 </span><span class="traceContains">+error: '-a' starts with '-', which can be confused with a negative number; use a different name</span> -<span id="L255" class="LineNr">255 </span> -<span id="L256" class="LineNr">256 </span><span class="Comment">//: now that we have labels, we need to adjust segment size computation to</span> -<span id="L257" class="LineNr">257 </span><span class="Comment">//: ignore them.</span> -<span id="L258" class="LineNr">258 </span> -<span id="L259" class="LineNr">259 </span><span class="Delimiter">:(scenario segment_size_ignores_labels)</span> -<span id="L260" class="LineNr">260 </span>== <a href='031check_operands.cc.html#L11'>code</a> <span class="Comment"># 0x09000074</span> -<span id="L261" class="LineNr">261 </span> <span class="PreProc">0</span><span class="Constant">5</span>/add <span class="Constant">0x0d0c0b0a</span>/imm32 <span class="Comment"># 5 bytes</span> -<span id="L262" class="LineNr">262 </span><span class="Normal">foo</span>: <span class="Comment"># 0 bytes</span> -<span id="L263" class="LineNr">263 </span>== data <span class="Comment"># 0x0a000079</span> -<span id="L264" class="LineNr">264 </span><span class="Normal">bar</span>: -<span id="L265" class="LineNr">265 </span> <span class="PreProc">0</span><span class="Constant">0</span> -<span id="L266" class="LineNr">266 </span><span class="traceContains">+transform: segment 1 begins at address 0x0a000079</span> -<span id="L267" class="LineNr">267 </span> -<span id="L268" class="LineNr">268 </span><span class="Delimiter">:(before "End num_bytes(curr) Special-cases")</span> -<span id="L269" class="LineNr">269 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='035labels.cc.html#L156'>is_label</a><span class="Delimiter">(</span>curr<span class="Delimiter">))</span> -<span id="L270" class="LineNr">270 </span> <span class="Delimiter">;</span> <span class="Comment">// don't count it</span> +<span id="L108" class="LineNr">108 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L109" class="LineNr">109 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">)</span> +<span id="L110" class="LineNr">110 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': don't use ':' when jumping to labels\n"</span> << end<span class="Delimiter">();</span> +<span id="L111" class="LineNr">111 </span> current_byte += <span class="Constant">2</span><span class="Delimiter">;</span> +<span id="L112" class="LineNr">112 </span> <span class="Delimiter">}</span> +<span id="L113" class="LineNr">113 </span> <span class="Comment">// automatically handle /disp8 and /imm8 here</span> +<span id="L114" class="LineNr">114 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L115" class="LineNr">115 </span> ++current_byte<span class="Delimiter">;</span> +<span id="L116" class="LineNr">116 </span> <span class="Delimiter">}</span> +<span id="L117" class="LineNr">117 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L118" class="LineNr">118 </span> string label = <a href='035labels.cc.html#L209'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L119" class="LineNr">119 </span> <span class="Comment">// ensure labels look sufficiently different from raw hex</span> +<span id="L120" class="LineNr">120 </span> <a href='035labels.cc.html#L52'>check_valid_name</a><span class="Delimiter">(</span>label<span class="Delimiter">);</span> +<span id="L121" class="LineNr">121 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='030---operands.cc.html#L396'>contains_any_operand_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">))</span> +<span id="L123" class="LineNr">123 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label definition (':') not allowed in operand\n"</span> << end<span class="Delimiter">();</span> +<span id="L124" class="LineNr">124 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> +<span id="L125" class="LineNr">125 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': labels can only be the first <a href='011run.cc.html#L123'>word</a> in a line.\n"</span> << end<span class="Delimiter">();</span> +<span id="L126" class="LineNr">126 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> +<span id="L127" class="LineNr">127 </span> <span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << <span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span>start + current_byte<span class="Delimiter">)</span> << <span class="Constant">' '</span> << label << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L128" class="LineNr">128 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> label<span class="Delimiter">,</span> current_byte<span class="Delimiter">);</span> +<span id="L129" class="LineNr">129 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"label '"</span> << label << <span class="Constant">"' is at address "</span> << <span class="Delimiter">(</span>current_byte+code<span class="Delimiter">.</span>start<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L130" class="LineNr">130 </span> <span class="Comment">// no modifying current_byte; label definitions won't be in the final binary</span> +<span id="L131" class="LineNr">131 </span> <span class="Delimiter">}</span> +<span id="L132" class="LineNr">132 </span> <span class="Delimiter">}</span> +<span id="L133" class="LineNr">133 </span> <span class="Delimiter">}</span> +<span id="L134" class="LineNr">134 </span><span class="Delimiter">}</span> +<span id="L135" class="LineNr">135 </span> +<span id="L136" class="LineNr">136 </span><span class="Delimiter">:(before "End Globals")</span> +<span id="L137" class="LineNr">137 </span><span class="Normal">bool</span> <span class="Special"><a href='035labels.cc.html#L137'>Dump_map</a></span> =<span class="Constant"> false</span><span class="Delimiter">;</span> <span class="Comment">// currently used only by 'subx translate'</span> +<span id="L138" class="LineNr">138 </span>ofstream <span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span><span class="Delimiter">;</span> +<span id="L139" class="LineNr">139 </span><span class="Delimiter">:(before "End Commandline Options")</span> +<span id="L140" class="LineNr">140 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L89'>is_equal</a><span class="Delimiter">(</span>*arg<span class="Delimiter">,</span> <span class="Constant">"--map"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L141" class="LineNr">141 </span> <span class="Special"><a href='035labels.cc.html#L137'>Dump_map</a></span> =<span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L142" class="LineNr">142 </span> <span class="Comment">// End --map Settings</span> +<span id="L143" class="LineNr">143 </span><span class="Delimiter">}</span> +<span id="L144" class="LineNr">144 </span><span class="Comment">//: wait to open "map" for writing until we're sure we aren't trying to read it</span> +<span id="L145" class="LineNr">145 </span><span class="Delimiter">:(after "Begin subx translate")</span> +<span id="L146" class="LineNr">146 </span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='035labels.cc.html#L137'>Dump_map</a></span><span class="Delimiter">)</span> +<span id="L147" class="LineNr">147 </span> <span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span><span class="Delimiter">.</span>open<span class="Delimiter">(</span><span class="Constant">"map"</span><span class="Delimiter">);</span> +<span id="L148" class="LineNr">148 </span><span class="Delimiter">:(before "End subx translate")</span> +<span id="L149" class="LineNr">149 </span><span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='035labels.cc.html#L137'>Dump_map</a></span><span class="Delimiter">)</span> +<span id="L150" class="LineNr">150 </span> <span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span><span class="Delimiter">.</span>close<span class="Delimiter">();</span> +<span id="L151" class="LineNr">151 </span> +<span id="L152" class="LineNr">152 </span><span class="Delimiter">:(code)</span> +<span id="L153" class="LineNr">153 </span><span class="Normal">void</span> <a href='035labels.cc.html#L153'>drop_labels</a><span class="Delimiter">(</span>segment& <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L154" class="LineNr">154 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L155" class="LineNr">155 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L156" class="LineNr">156 </span> vector<word>::iterator new_end = remove_if<span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>end<span class="Delimiter">(),</span> <a href='035labels.cc.html#L161'>is_label</a><span class="Delimiter">);</span> +<span id="L157" class="LineNr">157 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>erase<span class="Delimiter">(</span>new_end<span class="Delimiter">,</span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L158" class="LineNr">158 </span> <span class="Delimiter">}</span> +<span id="L159" class="LineNr">159 </span><span class="Delimiter">}</span> +<span id="L160" class="LineNr">160 </span> +<span id="L161" class="LineNr">161 </span><span class="Normal">bool</span> <a href='035labels.cc.html#L161'>is_label</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L162" class="LineNr">162 </span> <span class="Identifier">return</span> *w<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> == <span class="Constant">':'</span><span class="Delimiter">;</span> +<span id="L163" class="LineNr">163 </span><span class="Delimiter">}</span> +<span id="L164" class="LineNr">164 </span> +<span id="L165" class="LineNr">165 </span><span class="Normal">void</span> <a href='035labels.cc.html#L165'>replace_labels_with_displacements</a><span class="Delimiter">(</span>segment& <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">int32_t</span>>& byte_index<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L166" class="LineNr">166 </span> <span class="Normal">int32_t</span> byte_index_next_instruction_starts_at = <span class="Constant">0</span><span class="Delimiter">;</span> +<span id="L167" class="LineNr">167 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L168" class="LineNr">168 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L169" class="LineNr">169 </span> byte_index_next_instruction_starts_at += <a href='034compute_segment_address.cc.html#L112'>num_bytes</a><span class="Delimiter">(</span>inst<span class="Delimiter">);</span> +<span id="L170" class="LineNr">170 </span> <a href='011run.cc.html#L117'>line</a> new_inst<span class="Delimiter">;</span> +<span id="L171" class="LineNr">171 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L172" class="LineNr">172 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L173" class="LineNr">173 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L174" class="LineNr">174 </span> <span class="Normal">int32_t</span> displacement = <span class="Normal">static_cast</span><<span class="Normal">int32_t</span>><span class="Delimiter">(</span>get<span class="Delimiter">(</span>byte_index<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> - byte_index_next_instruction_starts_at<span class="Delimiter">;</span> +<span id="L175" class="LineNr">175 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp8"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L176" class="LineNr">176 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>displacement > <span class="Constant">0xff</span> || displacement < -<span class="Constant">0x7f</span><span class="Delimiter">)</span> +<span id="L177" class="LineNr">177 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label too far away for displacement "</span> << std::hex << displacement << <span class="Constant">" to fit in 8 bits\n"</span> << end<span class="Delimiter">();</span> +<span id="L178" class="LineNr">178 </span> <span class="Normal">else</span> +<span id="L179" class="LineNr">179 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">1</span><span class="Delimiter">);</span> +<span id="L180" class="LineNr">180 </span> <span class="Delimiter">}</span> +<span id="L181" class="LineNr">181 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp16"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L182" class="LineNr">182 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>displacement > <span class="Constant">0xffff</span> || displacement < -<span class="Constant">0x7fff</span><span class="Delimiter">)</span> +<span id="L183" class="LineNr">183 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': label too far away for displacement "</span> << std::hex << displacement << <span class="Constant">" to fit in 16 bits\n"</span> << end<span class="Delimiter">();</span> +<span id="L184" class="LineNr">184 </span> <span class="Normal">else</span> +<span id="L185" class="LineNr">185 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">2</span><span class="Delimiter">);</span> +<span id="L186" class="LineNr">186 </span> <span class="Delimiter">}</span> +<span id="L187" class="LineNr">187 </span> <span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L188" class="LineNr">188 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> displacement<span class="Delimiter">,</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L189" class="LineNr">189 </span> <span class="Delimiter">}</span> +<span id="L190" class="LineNr">190 </span> <span class="Delimiter">}</span> +<span id="L191" class="LineNr">191 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L192" class="LineNr">192 </span> new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L193" class="LineNr">193 </span> <span class="Delimiter">}</span> +<span id="L194" class="LineNr">194 </span> <span class="Delimiter">}</span> +<span id="L195" class="LineNr">195 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> +<span id="L196" class="LineNr">196 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after <a href='011run.cc.html#L231'>transform</a>: '"</span> << data_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L197" class="LineNr">197 </span> <span class="Delimiter">}</span> +<span id="L198" class="LineNr">198 </span><span class="Delimiter">}</span> +<span id="L199" class="LineNr">199 </span> +<span id="L200" class="LineNr">200 </span>string <a href='035labels.cc.html#L200'>data_to_string</a><span class="Delimiter">(</span><span class="Normal">const</span> line& inst<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L201" class="LineNr">201 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L202" class="LineNr">202 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L203" class="LineNr">203 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L204" class="LineNr">204 </span> out << inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L205" class="LineNr">205 </span> <span class="Delimiter">}</span> +<span id="L206" class="LineNr">206 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L207" class="LineNr">207 </span><span class="Delimiter">}</span> +<span id="L208" class="LineNr">208 </span> +<span id="L209" class="LineNr">209 </span>string <a href='035labels.cc.html#L209'>drop_last</a><span class="Delimiter">(</span><span class="Normal">const</span> string& s<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L210" class="LineNr">210 </span> <span class="Identifier">return</span> string<span class="Delimiter">(</span>s<span class="Delimiter">.</span>begin<span class="Delimiter">(),</span> --s<span class="Delimiter">.</span>end<span class="Delimiter">());</span> +<span id="L211" class="LineNr">211 </span><span class="Delimiter">}</span> +<span id="L212" class="LineNr">212 </span> +<span id="L213" class="LineNr">213 </span><span class="Comment">//: Label definitions must be the first word on a line. No jumping inside</span> +<span id="L214" class="LineNr">214 </span><span class="Comment">//: instructions.</span> +<span id="L215" class="LineNr">215 </span><span class="Comment">//: They should also be the only word on a line.</span> +<span id="L216" class="LineNr">216 </span><span class="Comment">//: However, you can absolutely have multiple labels map to the same address,</span> +<span id="L217" class="LineNr">217 </span><span class="Comment">//: as long as they're on separate lines.</span> +<span id="L218" class="LineNr">218 </span> +<span id="L219" class="LineNr">219 </span><span class="Delimiter">:(scenario multiple_labels_at)</span> +<span id="L220" class="LineNr">220 </span>== <span class="Constant">0x1</span> +<span id="L221" class="LineNr">221 </span><span class="Comment"># address 1</span> +<span id="L222" class="LineNr">222 </span><span class="Normal">loop</span>: +<span id="L223" class="LineNr">223 </span> $loop2: +<span id="L224" class="LineNr">224 </span><span class="Comment"># address 1 (labels take up no space)</span> +<span id="L225" class="LineNr">225 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 +<span id="L226" class="LineNr">226 </span><span class="Comment"># address 6</span> +<span id="L227" class="LineNr">227 </span> eb $loop2/disp8 +<span id="L228" class="LineNr">228 </span><span class="Comment"># address 8</span> +<span id="L229" class="LineNr">229 </span> eb $loop3/disp8 +<span id="L230" class="LineNr">230 </span><span class="Comment"># address 0xa</span> +<span id="L231" class="LineNr">231 </span> $loop3: +<span id="L232" class="LineNr">232 </span><span class="traceContains">+transform: label 'loop' is at address 1</span> +<span id="L233" class="LineNr">233 </span><span class="traceContains">+transform: label '$loop2' is at address 1</span> +<span id="L234" class="LineNr">234 </span><span class="traceContains">+transform: label '$loop3' is at address a</span> +<span id="L235" class="LineNr">235 </span><span class="Comment"># first jump is to -7</span> +<span id="L236" class="LineNr">236 </span><span class="traceContains">+transform: instruction after <a href='011run.cc.html#L231'>transform</a>: 'eb f9'</span> +<span id="L237" class="LineNr">237 </span><span class="Comment"># second jump is to 0 (fall through)</span> +<span id="L238" class="LineNr">238 </span><span class="traceContains">+transform: instruction after <a href='011run.cc.html#L231'>transform</a>: 'eb 00'</span> +<span id="L239" class="LineNr">239 </span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">:(scenario label_too_short)</span> +<span id="L241" class="LineNr">241 </span><span class="Special">% Hide_errors = true;</span> +<span id="L242" class="LineNr">242 </span>== <span class="Constant">0x1</span> +<span id="L243" class="LineNr">243 </span><span class="Normal">xz</span>: +<span id="L244" class="LineNr">244 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 +<span id="L245" class="LineNr">245 </span><span class="traceContains">+error: 'xz' is two characters long which can look like raw hex bytes at a glance; use a different name</span> +<span id="L246" class="LineNr">246 </span> +<span id="L247" class="LineNr">247 </span><span class="Delimiter">:(scenario label_hex)</span> +<span id="L248" class="LineNr">248 </span><span class="Special">% Hide_errors = true;</span> +<span id="L249" class="LineNr">249 </span>== <span class="Constant">0x1</span> +<span id="L250" class="LineNr">250 </span><span class="Constant">0xab</span>: +<span id="L251" class="LineNr">251 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 +<span id="L252" class="LineNr">252 </span><span class="traceContains">+error: '0xab' looks like a hex number; use a different name</span> +<span id="L253" class="LineNr">253 </span> +<span id="L254" class="LineNr">254 </span><span class="Delimiter">:(scenario label_negative_hex)</span> +<span id="L255" class="LineNr">255 </span><span class="Special">% Hide_errors = true;</span> +<span id="L256" class="LineNr">256 </span>== <span class="Constant">0x1</span> +<span id="L257" class="LineNr">257 </span> -a: <span class="Comment"># indent to avoid looking like a trace_should_not_contain command for this scenario</span> +<span id="L258" class="LineNr">258 </span> <span class="PreProc">0</span><span class="Constant">5</span> <span class="Constant">0x0d0c0b0a</span>/imm32 +<span id="L259" class="LineNr">259 </span><span class="traceContains">+error: '-a' starts with '-', which can be confused with a negative number; use a different name</span> +<span id="L260" class="LineNr">260 </span> +<span id="L261" class="LineNr">261 </span><span class="Comment">//: now that we have labels, we need to adjust segment size computation to</span> +<span id="L262" class="LineNr">262 </span><span class="Comment">//: ignore them.</span> +<span id="L263" class="LineNr">263 </span> +<span id="L264" class="LineNr">264 </span><span class="Delimiter">:(scenario segment_size_ignores_labels)</span> +<span id="L265" class="LineNr">265 </span>== <a href='031check_operands.cc.html#L11'>code</a> <span class="Comment"># 0x09000074</span> +<span id="L266" class="LineNr">266 </span> <span class="PreProc">0</span><span class="Constant">5</span>/add <span class="Constant">0x0d0c0b0a</span>/imm32 <span class="Comment"># 5 bytes</span> +<span id="L267" class="LineNr">267 </span><span class="Normal">foo</span>: <span class="Comment"># 0 bytes</span> +<span id="L268" class="LineNr">268 </span>== data <span class="Comment"># 0x0a000079</span> +<span id="L269" class="LineNr">269 </span><span class="Normal">bar</span>: +<span id="L270" class="LineNr">270 </span> <span class="PreProc">0</span><span class="Constant">0</span> +<span id="L271" class="LineNr">271 </span><span class="traceContains">+transform: segment 1 begins at address 0x0a000079</span> +<span id="L272" class="LineNr">272 </span> +<span id="L273" class="LineNr">273 </span><span class="Delimiter">:(before "End size_of(word w) Special-cases")</span> +<span id="L274" class="LineNr">274 </span><span class="Normal">else</span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='035labels.cc.html#L161'>is_label</a><span class="Delimiter">(</span>w<span class="Delimiter">))</span> +<span id="L275" class="LineNr">275 </span> <span class="Identifier">return</span> <span class="Constant">0</span><span class="Delimiter">;</span> </pre> </body> </html> diff --git a/html/subx/036global_variables.cc.html b/html/subx/036global_variables.cc.html index 5d783d16..24e8a9ee 100644 --- a/html/subx/036global_variables.cc.html +++ b/html/subx/036global_variables.cc.html @@ -21,12 +21,12 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } -.SalientComment { color: #00ffff; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } -.Special { color: #c00000; } +.SalientComment { color: #00ffff; } .PreProc { color: #800080; } --> </style> @@ -75,11 +75,11 @@ if ('onhashchange' in window) { <span id="L11" class="LineNr"> 11 </span>b9 x/imm32 <span id="L12" class="LineNr"> 12 </span>== data <span id="L13" class="LineNr"> 13 </span><span class="Normal">x</span>: -<span id="L14" class="LineNr"> 14 </span><span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> +<span id="L14" class="LineNr"> 14 </span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span id="L15" class="LineNr"> 15 </span><span class="traceContains">+transform: global variable 'x' is at address 0x0a000079</span> <span id="L16" class="LineNr"> 16 </span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">:(before "End Level-2 Transforms")</span> -<span id="L18" class="LineNr"> 18 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='036global_variables.cc.html#L20'>rewrite_global_variables</a><span class="Delimiter">);</span> +<span id="L18" class="LineNr"> 18 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='036global_variables.cc.html#L20'>rewrite_global_variables</a><span class="Delimiter">);</span> <span id="L19" class="LineNr"> 19 </span><span class="Delimiter">:(code)</span> <span id="L20" class="LineNr"> 20 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L20'>rewrite_global_variables</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L21" class="LineNr"> 21 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- rewrite global variables"</span> << end<span class="Delimiter">();</span> @@ -102,19 +102,19 @@ if ('onhashchange' in window) { <span id="L38" class="LineNr"> 38 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L39" class="LineNr"> 39 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> <span id="L40" class="LineNr"> 40 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L41" class="LineNr"> 41 </span> ++current_address<span class="Delimiter">;</span> +<span id="L41" class="LineNr"> 41 </span> current_address += size_of<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> <span id="L42" class="LineNr"> 42 </span> <span class="Delimiter">}</span> <span id="L43" class="LineNr"> 43 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> -<span id="L44" class="LineNr"> 44 </span> string variable = <a href='035labels.cc.html#L204'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L44" class="LineNr"> 44 </span> string variable = <a href='035labels.cc.html#L209'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> <span id="L45" class="LineNr"> 45 </span> <span class="Comment">// ensure variables look sufficiently different from raw hex</span> <span id="L46" class="LineNr"> 46 </span> <a href='035labels.cc.html#L52'>check_valid_name</a><span class="Delimiter">(</span>variable<span class="Delimiter">);</span> <span id="L47" class="LineNr"> 47 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='003trace.cc.html#L224'>trace_contains_errors</a><span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> <span id="L48" class="LineNr"> 48 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>j > <span class="Constant">0</span><span class="Delimiter">)</span> -<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': global variable names can only be the first <a href='011run.cc.html#L123'>word</a> in a line.</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L50" class="LineNr"> 50 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='035labels.cc.html#L133'>Map_file</a><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> -<span id="L51" class="LineNr"> 51 </span> <a href='035labels.cc.html#L133'>Map_file</a> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << current_address << <span class="Constant">' '</span> << variable << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> +<span id="L49" class="LineNr"> 49 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': global variable names can only be the first <a href='011run.cc.html#L123'>word</a> in a line.\n"</span> << end<span class="Delimiter">();</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span><span class="Delimiter">.</span>is_open<span class="Delimiter">())</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Special"><a href='035labels.cc.html#L138'>Map_file</a></span> << <span class="Constant">"0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << current_address << <span class="Constant">' '</span> << variable << <span class="cSpecial">'\n'</span><span class="Delimiter">;</span> <span id="L52" class="LineNr"> 52 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span>address<span class="Delimiter">,</span> variable<span class="Delimiter">,</span> current_address<span class="Delimiter">);</span> -<span id="L53" class="LineNr"> 53 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"global variable '"</span> << variable << <span class="Constant">"' is at address 0x"</span> << <a href='010---vm.cc.html#L404'>HEXWORD</a> << current_address << end<span class="Delimiter">();</span> +<span id="L53" class="LineNr"> 53 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"global variable '"</span> << variable << <span class="Constant">"' is at address 0x"</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << current_address << end<span class="Delimiter">();</span> <span id="L54" class="LineNr"> 54 </span> <span class="Comment">// no modifying current_address; global variable definitions won't be in the final binary</span> <span id="L55" class="LineNr"> 55 </span> <span class="Delimiter">}</span> <span id="L56" class="LineNr"> 56 </span> <span class="Delimiter">}</span> @@ -123,122 +123,162 @@ if ('onhashchange' in window) { <span id="L59" class="LineNr"> 59 </span> <span id="L60" class="LineNr"> 60 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L60'>drop_global_variables</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L61" class="LineNr"> 61 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip <a href='031check_operands.cc.html#L11'>code</a> segment</span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> -<span id="L62" class="LineNr"> 62 </span> <a href='035labels.cc.html#L148'>drop_labels</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> +<span id="L62" class="LineNr"> 62 </span> <a href='035labels.cc.html#L153'>drop_labels</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">));</span> <span id="L63" class="LineNr"> 63 </span><span class="Delimiter">}</span> <span id="L64" class="LineNr"> 64 </span> <span id="L65" class="LineNr"> 65 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L65'>replace_global_variables_with_addresses</a><span class="Delimiter">(</span>program& p<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L66" class="LineNr"> 66 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L67" class="LineNr"> 67 </span> segment& <a href='031check_operands.cc.html#L11'>code</a> = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L69" class="LineNr"> 69 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L70" class="LineNr"> 70 </span> <a href='011run.cc.html#L117'>line</a> new_inst<span class="Delimiter">;</span> -<span id="L71" class="LineNr"> 71 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L74" class="LineNr"> 74 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!looks_like_hex_int<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> -<span id="L75" class="LineNr"> 75 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"missing reference to global '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L76" class="LineNr"> 76 </span> new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> -<span id="L77" class="LineNr"> 77 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span id="L78" class="LineNr"> 78 </span> <span class="Delimiter">}</span> -<span id="L79" class="LineNr"> 79 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!valid_use_of_global_variable<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L80" class="LineNr"> 80 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': can't refer to global variable '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'</span><span class="cSpecial">\n</span><span class="Constant">"</span> << end<span class="Delimiter">();</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Delimiter">}</span> -<span id="L83" class="LineNr"> 83 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">),</span> <span class="Constant">4</span><span class="Delimiter">);</span> -<span id="L84" class="LineNr"> 84 </span> <span class="Delimiter">}</span> -<span id="L85" class="LineNr"> 85 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> -<span id="L86" class="LineNr"> 86 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after <a href='011run.cc.html#L231'>transform</a>: '"</span> << data_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> -<span id="L87" class="LineNr"> 87 </span> <span class="Delimiter">}</span> -<span id="L88" class="LineNr"> 88 </span><span class="Delimiter">}</span> -<span id="L89" class="LineNr"> 89 </span> -<span id="L90" class="LineNr"> 90 </span><span class="Normal">bool</span> <a href='036global_variables.cc.html#L90'>valid_use_of_global_variable</a><span class="Delimiter">(</span><span class="Normal">const</span> word& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L91" class="LineNr"> 91 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Comment">// End Valid Uses Of Global Variable(curr)</span> -<span id="L93" class="LineNr"> 93 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L94" class="LineNr"> 94 </span><span class="Delimiter">}</span> -<span id="L95" class="LineNr"> 95 </span> -<span id="L96" class="LineNr"> 96 </span><span class="SalientComment">//:: a more complex sanity check for how we use global variables</span> -<span id="L97" class="LineNr"> 97 </span><span class="Comment">//: requires first saving some data early before we pack operands</span> -<span id="L98" class="LineNr"> 98 </span> -<span id="L99" class="LineNr"> 99 </span><span class="Delimiter">:(after "Begin Level-2 Transforms")</span> -<span id="L100" class="LineNr">100 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='036global_variables.cc.html#L102'>correlate_disp32_with_mod</a><span class="Delimiter">);</span> -<span id="L101" class="LineNr">101 </span><span class="Delimiter">:(code)</span> -<span id="L102" class="LineNr">102 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L102'>correlate_disp32_with_mod</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L103" class="LineNr">103 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> -<span id="L104" class="LineNr">104 </span> segment& <a href='031check_operands.cc.html#L11'>code</a> = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> -<span id="L105" class="LineNr">105 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L106" class="LineNr">106 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> -<span id="L107" class="LineNr">107 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L108" class="LineNr">108 </span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> -<span id="L109" class="LineNr">109 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> -<span id="L110" class="LineNr">110 </span> && has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">))</span> -<span id="L111" class="LineNr">111 </span> curr<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"has_mod"</span><span class="Delimiter">);</span> -<span id="L112" class="LineNr">112 </span> <span class="Delimiter">}</span> -<span id="L113" class="LineNr">113 </span> <span class="Delimiter">}</span> -<span id="L114" class="LineNr">114 </span><span class="Delimiter">}</span> -<span id="L115" class="LineNr">115 </span> -<span id="L116" class="LineNr">116 </span><span class="Delimiter">:(before "End Valid Uses Of Global Variable(curr)")</span> -<span id="L117" class="LineNr">117 </span><span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> -<span id="L118" class="LineNr">118 </span> <span class="Identifier">return</span> <a href='036global_variables.cc.html#L123'>has_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"has_mod"</span><span class="Delimiter">);</span> -<span id="L119" class="LineNr">119 </span><span class="Comment">// todo: more sophisticated check, to ensure we don't use global variable</span> -<span id="L120" class="LineNr">120 </span><span class="Comment">// addresses as a real displacement added to other operands.</span> -<span id="L121" class="LineNr">121 </span> -<span id="L122" class="LineNr">122 </span><span class="Delimiter">:(code)</span> -<span id="L123" class="LineNr">123 </span><span class="Normal">bool</span> <a href='036global_variables.cc.html#L123'>has_metadata</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">,</span> <span class="Normal">const</span> string& m<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L124" class="LineNr">124 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> -<span id="L125" class="LineNr">125 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == m<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> -<span id="L126" class="LineNr">126 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> -<span id="L127" class="LineNr">127 </span><span class="Delimiter">}</span> -<span id="L128" class="LineNr">128 </span> -<span id="L129" class="LineNr">129 </span><span class="Delimiter">:(scenario global_variable_disallowed_in_jump)</span> -<span id="L130" class="LineNr">130 </span><span class="Special">% Hide_errors = true;</span> -<span id="L131" class="LineNr">131 </span>== <a href='031check_operands.cc.html#L11'>code</a> -<span id="L132" class="LineNr">132 </span>eb/jump x/disp8 -<span id="L133" class="LineNr">133 </span>== data -<span id="L134" class="LineNr">134 </span><span class="Normal">x</span>: -<span id="L135" class="LineNr">135 </span><span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> -<span id="L136" class="LineNr">136 </span><span class="traceContains">+error: 'eb/jump x/disp8': can't refer to global variable 'x'</span> -<span id="L137" class="LineNr">137 </span><span class="Comment"># sub-optimal error message; should be</span> -<span id="L138" class="LineNr">138 </span><span class="CommentedCode">#? +error: can't jump to data (variable 'x')</span> -<span id="L139" class="LineNr">139 </span> -<span id="L140" class="LineNr">140 </span><span class="Delimiter">:(scenario global_variable_disallowed_in_call)</span> -<span id="L141" class="LineNr">141 </span><span class="Special">% Hide_errors = true;</span> -<span id="L142" class="LineNr">142 </span>== <a href='031check_operands.cc.html#L11'>code</a> -<span id="L143" class="LineNr">143 </span>e8/call x/disp32 -<span id="L144" class="LineNr">144 </span>== data -<span id="L145" class="LineNr">145 </span><span class="Normal">x</span>: -<span id="L146" class="LineNr">146 </span><span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> -<span id="L147" class="LineNr">147 </span><span class="traceContains">+error: 'e8/call x/disp32': can't refer to global variable 'x'</span> -<span id="L148" class="LineNr">148 </span><span class="Comment"># sub-optimal error message; should be</span> -<span id="L149" class="LineNr">149 </span><span class="CommentedCode">#? +error: can't call to the data segment ('x')</span> -<span id="L150" class="LineNr">150 </span> -<span id="L151" class="LineNr">151 </span><span class="Delimiter">:(scenario disp32_data_with_modrm)</span> -<span id="L152" class="LineNr">152 </span>== <a href='031check_operands.cc.html#L11'>code</a> -<span id="L153" class="LineNr">153 </span>8b/copy <span class="Constant">0</span>/mod/indirect <span class="Constant">5</span>/rm32/<span class="Delimiter">.</span>disp32 <span class="Constant">2</span>/r32/EDX x/disp32 -<span id="L154" class="LineNr">154 </span>== data -<span id="L155" class="LineNr">155 </span><span class="Normal">x</span>: -<span id="L156" class="LineNr">156 </span><span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> -<span id="L157" class="LineNr">157 </span>$error: <span class="Constant">0</span> -<span id="L158" class="LineNr">158 </span> -<span id="L159" class="LineNr">159 </span><span class="Delimiter">:(scenarios transform)</span> -<span id="L160" class="LineNr">160 </span><span class="Delimiter">:(scenario disp32_data_with_call)</span> -<span id="L161" class="LineNr">161 </span>== <a href='031check_operands.cc.html#L11'>code</a> -<span id="L162" class="LineNr">162 </span><span class="Normal">foo</span>: -<span id="L163" class="LineNr">163 </span>e8/call bar/disp32 -<span id="L164" class="LineNr">164 </span><span class="Normal">bar</span>: -<span id="L165" class="LineNr">165 </span>$error: <span class="Constant">0</span> -<span id="L166" class="LineNr">166 </span> -<span id="L167" class="LineNr">167 </span><span class="Delimiter">:(code)</span> -<span id="L168" class="LineNr">168 </span>string to_full_string<span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L169" class="LineNr">169 </span> ostringstream out<span class="Delimiter">;</span> -<span id="L170" class="LineNr">170 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L171" class="LineNr">171 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> -<span id="L172" class="LineNr">172 </span> out << in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> -<span id="L173" class="LineNr">173 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>metadata<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> -<span id="L174" class="LineNr">174 </span> out << <span class="Constant">'/'</span> << in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> -<span id="L175" class="LineNr">175 </span> <span class="Delimiter">}</span> -<span id="L176" class="LineNr">176 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> -<span id="L177" class="LineNr">177 </span><span class="Delimiter">}</span> +<span id="L67" class="LineNr"> 67 </span> <a href='036global_variables.cc.html#L72'>replace_global_variables_in_code_segment</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">),</span> address<span class="Delimiter">);</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Comment">/*</span><span class="Comment">skip <a href='031check_operands.cc.html#L11'>code</a></span><span class="Comment">*/</span><span class="Constant">1</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L69" class="LineNr"> 69 </span> <a href='036global_variables.cc.html#L95'>replace_global_variables_in_data_segment</a><span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">),</span> address<span class="Delimiter">);</span> +<span id="L70" class="LineNr"> 70 </span><span class="Delimiter">}</span> +<span id="L71" class="LineNr"> 71 </span> +<span id="L72" class="LineNr"> 72 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L72'>replace_global_variables_in_code_segment</a><span class="Delimiter">(</span>segment& <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L74" class="LineNr"> 74 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L75" class="LineNr"> 75 </span> <a href='011run.cc.html#L117'>line</a> new_inst<span class="Delimiter">;</span> +<span id="L76" class="LineNr"> 76 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L77" class="LineNr"> 77 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L79" class="LineNr"> 79 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!looks_like_hex_int<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> +<span id="L80" class="LineNr"> 80 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"missing reference to global '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'\n"</span> << end<span class="Delimiter">();</span> +<span id="L81" class="LineNr"> 81 </span> new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Delimiter">}</span> +<span id="L84" class="LineNr"> 84 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!valid_use_of_global_variable<span class="Delimiter">(</span>curr<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L85" class="LineNr"> 85 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"'"</span> << to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"': can't refer to global variable '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'\n"</span> << end<span class="Delimiter">();</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Delimiter">}</span> +<span id="L88" class="LineNr"> 88 </span> emit_hex_bytes<span class="Delimiter">(</span>new_inst<span class="Delimiter">,</span> get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">),</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Delimiter">}</span> +<span id="L90" class="LineNr"> 90 </span> inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> +<span id="L91" class="LineNr"> 91 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"instruction after <a href='011run.cc.html#L231'>transform</a>: '"</span> << data_to_string<span class="Delimiter">(</span>inst<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Delimiter">}</span> +<span id="L93" class="LineNr"> 93 </span><span class="Delimiter">}</span> +<span id="L94" class="LineNr"> 94 </span> +<span id="L95" class="LineNr"> 95 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L95'>replace_global_variables_in_data_segment</a><span class="Delimiter">(</span>segment& data<span class="Delimiter">,</span> <span class="Normal">const</span> map<string<span class="Delimiter">,</span> <span class="Normal">uint32_t</span>>& address<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>data<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L97" class="LineNr"> 97 </span> line& l = data<span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L98" class="LineNr"> 98 </span> <a href='011run.cc.html#L117'>line</a> new_l<span class="Delimiter">;</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L100" class="LineNr">100 </span> <span class="Normal">const</span> word& curr = l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L101" class="LineNr">101 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!contains_key<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L102" class="LineNr">102 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!looks_like_hex_int<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">))</span> +<span id="L103" class="LineNr">103 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"missing reference to global '"</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">"'\n"</span> << end<span class="Delimiter">();</span> +<span id="L104" class="LineNr">104 </span> new_l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>curr<span class="Delimiter">);</span> +<span id="L105" class="LineNr">105 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> +<span id="L106" class="LineNr">106 </span> <span class="Delimiter">}</span> +<span id="L107" class="LineNr">107 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << curr<span class="Delimiter">.</span>data << <span class="Constant">" maps to "</span> << <a href='010---vm.cc.html#L413'>HEXWORD</a> << get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L108" class="LineNr">108 </span> emit_hex_bytes<span class="Delimiter">(</span>new_l<span class="Delimiter">,</span> get<span class="Delimiter">(</span>address<span class="Delimiter">,</span> curr<span class="Delimiter">.</span>data<span class="Delimiter">),</span> <span class="Constant">4</span><span class="Delimiter">);</span> +<span id="L109" class="LineNr">109 </span> <span class="Delimiter">}</span> +<span id="L110" class="LineNr">110 </span> l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>swap<span class="Delimiter">(</span>new_l<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> +<span id="L111" class="LineNr">111 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"after <a href='011run.cc.html#L231'>transform</a>: '"</span> << data_to_string<span class="Delimiter">(</span>l<span class="Delimiter">)</span> << <span class="Constant">"'"</span> << end<span class="Delimiter">();</span> +<span id="L112" class="LineNr">112 </span> <span class="Delimiter">}</span> +<span id="L113" class="LineNr">113 </span><span class="Delimiter">}</span> +<span id="L114" class="LineNr">114 </span> +<span id="L115" class="LineNr">115 </span><span class="Normal">bool</span> <a href='036global_variables.cc.html#L115'>valid_use_of_global_variable</a><span class="Delimiter">(</span><span class="Normal">const</span> word& curr<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L116" class="LineNr">116 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"imm32"</span><span class="Delimiter">))</span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment">// End Valid Uses Of Global Variable(curr)</span> +<span id="L118" class="LineNr">118 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L119" class="LineNr">119 </span><span class="Delimiter">}</span> +<span id="L120" class="LineNr">120 </span> +<span id="L121" class="LineNr">121 </span><span class="SalientComment">//:: a more complex sanity check for how we use global variables</span> +<span id="L122" class="LineNr">122 </span><span class="Comment">//: requires first saving some data early before we pack operands</span> +<span id="L123" class="LineNr">123 </span> +<span id="L124" class="LineNr">124 </span><span class="Delimiter">:(after "Begin Level-2 Transforms")</span> +<span id="L125" class="LineNr">125 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='036global_variables.cc.html#L127'>correlate_disp32_with_mod</a><span class="Delimiter">);</span> +<span id="L126" class="LineNr">126 </span><span class="Delimiter">:(code)</span> +<span id="L127" class="LineNr">127 </span><span class="Normal">void</span> <a href='036global_variables.cc.html#L127'>correlate_disp32_with_mod</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L128" class="LineNr">128 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L129" class="LineNr">129 </span> segment& <a href='031check_operands.cc.html#L11'>code</a> = p<span class="Delimiter">.</span><a href='011run.cc.html#L100'>segments</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">);</span> +<span id="L130" class="LineNr">130 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span><a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L131" class="LineNr">131 </span> line& inst = <a href='031check_operands.cc.html#L11'>code</a><span class="Delimiter">.</span><a href='011run.cc.html#L109'>lines</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">);</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L133" class="LineNr">133 </span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L134" class="LineNr">134 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">)</span> +<span id="L135" class="LineNr">135 </span> && has_operand_metadata<span class="Delimiter">(</span>inst<span class="Delimiter">,</span> <span class="Constant">"mod"</span><span class="Delimiter">))</span> +<span id="L136" class="LineNr">136 </span> curr<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><span class="Constant">"has_mod"</span><span class="Delimiter">);</span> +<span id="L137" class="LineNr">137 </span> <span class="Delimiter">}</span> +<span id="L138" class="LineNr">138 </span> <span class="Delimiter">}</span> +<span id="L139" class="LineNr">139 </span><span class="Delimiter">}</span> +<span id="L140" class="LineNr">140 </span> +<span id="L141" class="LineNr">141 </span><span class="Delimiter">:(before "End Valid Uses Of Global Variable(curr)")</span> +<span id="L142" class="LineNr">142 </span><span class="Normal">if</span> <span class="Delimiter">(</span>has_operand_metadata<span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"disp32"</span><span class="Delimiter">))</span> +<span id="L143" class="LineNr">143 </span> <span class="Identifier">return</span> <a href='036global_variables.cc.html#L148'>has_metadata</a><span class="Delimiter">(</span>curr<span class="Delimiter">,</span> <span class="Constant">"has_mod"</span><span class="Delimiter">);</span> +<span id="L144" class="LineNr">144 </span><span class="Comment">// todo: more sophisticated check, to ensure we don't use global variable</span> +<span id="L145" class="LineNr">145 </span><span class="Comment">// addresses as a real displacement added to other operands.</span> +<span id="L146" class="LineNr">146 </span> +<span id="L147" class="LineNr">147 </span><span class="Delimiter">:(code)</span> +<span id="L148" class="LineNr">148 </span><span class="Normal">bool</span> <a href='036global_variables.cc.html#L148'>has_metadata</a><span class="Delimiter">(</span><span class="Normal">const</span> word& w<span class="Delimiter">,</span> <span class="Normal">const</span> string& m<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L149" class="LineNr">149 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> +<span id="L150" class="LineNr">150 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>w<span class="Delimiter">.</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">)</span> == m<span class="Delimiter">)</span> <span class="Identifier">return</span><span class="Constant"> true</span><span class="Delimiter">;</span> +<span id="L151" class="LineNr">151 </span> <span class="Identifier">return</span><span class="Constant"> false</span><span class="Delimiter">;</span> +<span id="L152" class="LineNr">152 </span><span class="Delimiter">}</span> +<span id="L153" class="LineNr">153 </span> +<span id="L154" class="LineNr">154 </span><span class="Delimiter">:(scenario global_variable_disallowed_in_jump)</span> +<span id="L155" class="LineNr">155 </span><span class="Special">% Hide_errors = true;</span> +<span id="L156" class="LineNr">156 </span>== <a href='031check_operands.cc.html#L11'>code</a> +<span id="L157" class="LineNr">157 </span>eb/jump x/disp8 +<span id="L158" class="LineNr">158 </span>== data +<span id="L159" class="LineNr">159 </span><span class="Normal">x</span>: +<span id="L160" class="LineNr">160 </span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> +<span id="L161" class="LineNr">161 </span><span class="traceContains">+error: 'eb/jump x/disp8': can't refer to global variable 'x'</span> +<span id="L162" class="LineNr">162 </span><span class="Comment"># sub-optimal error message; should be</span> +<span id="L163" class="LineNr">163 </span><span class="CommentedCode">#? +error: can't jump to data (variable 'x')</span> +<span id="L164" class="LineNr">164 </span> +<span id="L165" class="LineNr">165 </span><span class="Delimiter">:(scenario global_variable_disallowed_in_call)</span> +<span id="L166" class="LineNr">166 </span><span class="Special">% Hide_errors = true;</span> +<span id="L167" class="LineNr">167 </span>== <a href='031check_operands.cc.html#L11'>code</a> +<span id="L168" class="LineNr">168 </span>e8/call x/disp32 +<span id="L169" class="LineNr">169 </span>== data +<span id="L170" class="LineNr">170 </span><span class="Normal">x</span>: +<span id="L171" class="LineNr">171 </span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> +<span id="L172" class="LineNr">172 </span><span class="traceContains">+error: 'e8/call x/disp32': can't refer to global variable 'x'</span> +<span id="L173" class="LineNr">173 </span><span class="Comment"># sub-optimal error message; should be</span> +<span id="L174" class="LineNr">174 </span><span class="CommentedCode">#? +error: can't call to the data segment ('x')</span> +<span id="L175" class="LineNr">175 </span> +<span id="L176" class="LineNr">176 </span><span class="Delimiter">:(scenario global_variable_in_data_segment)</span> +<span id="L177" class="LineNr">177 </span>== <span class="Constant">0x1</span> +<span id="L178" class="LineNr">178 </span>b9 x/imm32 +<span id="L179" class="LineNr">179 </span>== <span class="Constant">0x0a000000</span> +<span id="L180" class="LineNr">180 </span><span class="Normal">x</span>: +<span id="L181" class="LineNr">181 </span> y/imm32 +<span id="L182" class="LineNr">182 </span><span class="Normal">y</span>: +<span id="L183" class="LineNr">183 </span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> +<span id="L184" class="LineNr">184 </span><span class="Comment"># check that we loaded 'x' with the address of 'y'</span> +<span id="L185" class="LineNr">185 </span><span class="traceContains">+load: 0x0a000000 -> 04</span> +<span id="L186" class="LineNr">186 </span><span class="traceContains">+load: 0x0a000001 -> 00</span> +<span id="L187" class="LineNr">187 </span><span class="traceContains">+load: 0x0a000002 -> 00</span> +<span id="L188" class="LineNr">188 </span><span class="traceContains">+load: 0x0a000003 -> 0a</span> +<span id="L189" class="LineNr">189 </span>$error: <span class="Constant">0</span> +<span id="L190" class="LineNr">190 </span> +<span id="L191" class="LineNr">191 </span><span class="Delimiter">:(scenario disp32_data_with_modrm)</span> +<span id="L192" class="LineNr">192 </span>== <a href='031check_operands.cc.html#L11'>code</a> +<span id="L193" class="LineNr">193 </span>8b/copy <span class="Constant">0</span>/mod/indirect <span class="Constant">5</span>/rm32/<span class="Delimiter">.</span>disp32 <span class="Constant">2</span>/r32/EDX x/disp32 +<span id="L194" class="LineNr">194 </span>== data +<span id="L195" class="LineNr">195 </span><span class="Normal">x</span>: +<span id="L196" class="LineNr">196 </span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> <span class="PreProc">0</span><span class="Constant">0</span> +<span id="L197" class="LineNr">197 </span>$error: <span class="Constant">0</span> +<span id="L198" class="LineNr">198 </span> +<span id="L199" class="LineNr">199 </span><span class="Delimiter">:(scenarios transform)</span> +<span id="L200" class="LineNr">200 </span><span class="Delimiter">:(scenario disp32_data_with_call)</span> +<span id="L201" class="LineNr">201 </span>== <a href='031check_operands.cc.html#L11'>code</a> +<span id="L202" class="LineNr">202 </span><span class="Normal">foo</span>: +<span id="L203" class="LineNr">203 </span> e8/call bar/disp32 +<span id="L204" class="LineNr">204 </span><span class="Normal">bar</span>: +<span id="L205" class="LineNr">205 </span>$error: <span class="Constant">0</span> +<span id="L206" class="LineNr">206 </span> +<span id="L207" class="LineNr">207 </span><span class="Delimiter">:(code)</span> +<span id="L208" class="LineNr">208 </span>string to_full_string<span class="Delimiter">(</span><span class="Normal">const</span> line& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L209" class="LineNr">209 </span> ostringstream out<span class="Delimiter">;</span> +<span id="L210" class="LineNr">210 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> i = <span class="Constant">0</span><span class="Delimiter">;</span> i < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">);</span> ++i<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L211" class="LineNr">211 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>i > <span class="Constant">0</span><span class="Delimiter">)</span> out << <span class="Constant">' '</span><span class="Delimiter">;</span> +<span id="L212" class="LineNr">212 </span> out << in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>data<span class="Delimiter">;</span> +<span id="L213" class="LineNr">213 </span> <span class="Normal">for</span> <span class="Delimiter">(</span><span class="Normal">int</span> j = <span class="Constant">0</span><span class="Delimiter">;</span> j < <a href='001help.cc.html#L157'>SIZE</a><span class="Delimiter">(</span>in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>metadata<span class="Delimiter">);</span> ++j<span class="Delimiter">)</span> +<span id="L214" class="LineNr">214 </span> out << <span class="Constant">'/'</span> << in<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>i<span class="Delimiter">).</span>metadata<span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> +<span id="L215" class="LineNr">215 </span> <span class="Delimiter">}</span> +<span id="L216" class="LineNr">216 </span> <span class="Identifier">return</span> out<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L217" class="LineNr">217 </span><span class="Delimiter">}</span> </pre> </body> </html> diff --git a/html/subx/038---literal_strings.cc.html b/html/subx/038---literal_strings.cc.html index 479e1731..5beff626 100644 --- a/html/subx/038---literal_strings.cc.html +++ b/html/subx/038---literal_strings.cc.html @@ -17,9 +17,10 @@ a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .cSpecial { color: #008000; } .LineNr { color: #444444; } +.traceAbsent { color: #c00000; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } -.traceAbsent { color: #c00000; } +.Special { color: #c00000; } .Identifier { color: #c0a020; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } @@ -77,11 +78,11 @@ if ('onhashchange' in window) { <span id="L16" class="LineNr"> 16 </span><span class="Comment">//: layers to transform.</span> <span id="L17" class="LineNr"> 17 </span><span class="Delimiter">:(after "Begin Transforms")</span> <span id="L18" class="LineNr"> 18 </span><span class="Comment">// Begin Level-3 Transforms</span> -<span id="L19" class="LineNr"> 19 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='038---literal_strings.cc.html#L25'>transform_literal_strings</a><span class="Delimiter">);</span> +<span id="L19" class="LineNr"> 19 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='038---literal_strings.cc.html#L25'>transform_literal_strings</a><span class="Delimiter">);</span> <span id="L20" class="LineNr"> 20 </span><span class="Comment">// End Level-3 Transforms</span> <span id="L21" class="LineNr"> 21 </span> <span id="L22" class="LineNr"> 22 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L23" class="LineNr"> 23 </span><span class="Normal">int</span> <a href='038---literal_strings.cc.html#L23'>Next_auto_global</a> = <span class="Constant">1</span><span class="Delimiter">;</span> +<span id="L23" class="LineNr"> 23 </span><span class="Normal">int</span> <span class="Special"><a href='038---literal_strings.cc.html#L23'>Next_auto_global</a></span> = <span class="Constant">1</span><span class="Delimiter">;</span> <span id="L24" class="LineNr"> 24 </span><span class="Delimiter">:(code)</span> <span id="L25" class="LineNr"> 25 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L25'>transform_literal_strings</a><span class="Delimiter">(</span>program& p<span class="Delimiter">)</span> <span class="Delimiter">{</span> <span id="L26" class="LineNr"> 26 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"transform"</span><span class="Delimiter">)</span> << <span class="Constant">"-- move literal strings to data segment"</span> << end<span class="Delimiter">();</span> @@ -94,8 +95,8 @@ if ('onhashchange' in window) { <span id="L33" class="LineNr"> 33 </span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> <span id="L34" class="LineNr"> 34 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>at<span class="Delimiter">(</span><span class="Constant">0</span><span class="Delimiter">)</span> != <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span id="L35" class="LineNr"> 35 </span> ostringstream global_name<span class="Delimiter">;</span> -<span id="L36" class="LineNr"> 36 </span> global_name << <span class="Constant">"__subx_global_"</span> << <a href='038---literal_strings.cc.html#L23'>Next_auto_global</a><span class="Delimiter">;</span> -<span id="L37" class="LineNr"> 37 </span> ++Next_auto_global<span class="Delimiter">;</span> +<span id="L36" class="LineNr"> 36 </span> global_name << <span class="Constant">"__subx_global_"</span> << <span class="Special"><a href='038---literal_strings.cc.html#L23'>Next_auto_global</a></span><span class="Delimiter">;</span> +<span id="L37" class="LineNr"> 37 </span> ++<span class="Special"><a href='038---literal_strings.cc.html#L23'>Next_auto_global</a></span><span class="Delimiter">;</span> <span id="L38" class="LineNr"> 38 </span> <a href='038---literal_strings.cc.html#L52'>add_global_to_data_segment</a><span class="Delimiter">(</span>global_name<span class="Delimiter">.</span>str<span class="Delimiter">(),</span> curr<span class="Delimiter">,</span> data<span class="Delimiter">);</span> <span id="L39" class="LineNr"> 39 </span> curr<span class="Delimiter">.</span>data = global_name<span class="Delimiter">.</span>str<span class="Delimiter">();</span> <span id="L40" class="LineNr"> 40 </span> <span class="Delimiter">}</span> @@ -155,124 +156,152 @@ if ('onhashchange' in window) { <span id="L94" class="LineNr"> 94 </span> <span id="L95" class="LineNr"> 95 </span><span class="Delimiter">:(code)</span> <span id="L96" class="LineNr"> 96 </span><span class="Normal">void</span> parse_instruction_character_by_character<span class="Delimiter">(</span><span class="Normal">const</span> string& line_data<span class="Delimiter">,</span> vector<line>& out<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L97" class="LineNr"> 97 </span> <span class="Comment">// parse literals</span> -<span id="L98" class="LineNr"> 98 </span> istringstream in<span class="Delimiter">(</span>line_data<span class="Delimiter">);</span> -<span id="L99" class="LineNr"> 99 </span> in >> std::noskipws<span class="Delimiter">;</span> -<span id="L100" class="LineNr">100 </span> <a href='011run.cc.html#L117'>line</a> result<span class="Delimiter">;</span> -<span id="L101" class="LineNr">101 </span> <span class="Comment">// add tokens (words or strings) one by one</span> -<span id="L102" class="LineNr">102 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L103" class="LineNr">103 </span> <a href='038---literal_strings.cc.html#L136'>skip_whitespace</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> -<span id="L104" class="LineNr">104 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L105" class="LineNr">105 </span> <span class="Normal">char</span> c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> -<span id="L106" class="LineNr">106 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment; drop rest of line</span> -<span id="L107" class="LineNr">107 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// line metadata; skip for now</span> -<span id="L108" class="LineNr">108 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'.'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L109" class="LineNr">109 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment token at end of line</span> -<span id="L110" class="LineNr">110 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> -<span id="L111" class="LineNr">111 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// '.' followed by space is comment token; skip</span> -<span id="L112" class="LineNr">112 </span> <span class="Delimiter">}</span> -<span id="L113" class="LineNr">113 </span> ostringstream w<span class="Delimiter">;</span> -<span id="L114" class="LineNr">114 </span> w << c<span class="Delimiter">;</span> -<span id="L115" class="LineNr">115 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L116" class="LineNr">116 </span> <span class="Comment">// slurp until '"'</span> -<span id="L117" class="LineNr">117 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> -<span id="L118" class="LineNr">118 </span> in >> c<span class="Delimiter">;</span> -<span id="L119" class="LineNr">119 </span> w << c<span class="Delimiter">;</span> -<span id="L120" class="LineNr">120 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L121" class="LineNr">121 </span> <span class="Delimiter">}</span> -<span id="L122" class="LineNr">122 </span> <span class="Delimiter">}</span> -<span id="L123" class="LineNr">123 </span> <span class="Comment">// slurp any remaining characters until whitespace</span> -<span id="L124" class="LineNr">124 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && <a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// peek can sometimes trigger eof(), so do it first</span> -<span id="L125" class="LineNr">125 </span> in >> c<span class="Delimiter">;</span> -<span id="L126" class="LineNr">126 </span> w << c<span class="Delimiter">;</span> -<span id="L127" class="LineNr">127 </span> <span class="Delimiter">}</span> -<span id="L128" class="LineNr">128 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L123'>word</a><span class="Delimiter">());</span> -<span id="L129" class="LineNr">129 </span> <a href='011run.cc.html#L191'>parse_word</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>str<span class="Delimiter">(),</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">());</span> -<span id="L130" class="LineNr">130 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse2"</span><span class="Delimiter">)</span> << <span class="Constant">"word: "</span> << to_string<span class="Delimiter">(</span>result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">())</span> << end<span class="Delimiter">();</span> -<span id="L131" class="LineNr">131 </span> <span class="Delimiter">}</span> -<span id="L132" class="LineNr">132 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> -<span id="L133" class="LineNr">133 </span> out<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> -<span id="L134" class="LineNr">134 </span><span class="Delimiter">}</span> -<span id="L135" class="LineNr">135 </span> -<span id="L136" class="LineNr">136 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L136'>skip_whitespace</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L137" class="LineNr">137 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L138" class="LineNr">138 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> -<span id="L139" class="LineNr">139 </span> <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span> -<span id="L140" class="LineNr">140 </span> <span class="Delimiter">}</span> -<span id="L141" class="LineNr">141 </span><span class="Delimiter">}</span> -<span id="L142" class="LineNr">142 </span> -<span id="L143" class="LineNr">143 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L143'>skip_comment</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L144" class="LineNr">144 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L145" class="LineNr">145 </span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> -<span id="L146" class="LineNr">146 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> -<span id="L147" class="LineNr">147 </span> <span class="Delimiter">}</span> -<span id="L148" class="LineNr">148 </span><span class="Delimiter">}</span> -<span id="L149" class="LineNr">149 </span> -<span id="L150" class="LineNr">150 </span><span class="Comment">// helper for tests</span> -<span id="L151" class="LineNr">151 </span><span class="Normal">void</span> parse_instruction_character_by_character<span class="Delimiter">(</span><span class="Normal">const</span> string& line_data<span class="Delimiter">)</span> <span class="Delimiter">{</span> -<span id="L152" class="LineNr">152 </span> vector<line> out<span class="Delimiter">;</span> -<span id="L153" class="LineNr">153 </span> parse_instruction_character_by_character<span class="Delimiter">(</span>line_data<span class="Delimiter">,</span> out<span class="Delimiter">);</span> -<span id="L154" class="LineNr">154 </span><span class="Delimiter">}</span> -<span id="L155" class="LineNr">155 </span> -<span id="L156" class="LineNr">156 </span><span class="Delimiter">:(scenario parse2_comment_token_in_middle)</span> -<span id="L157" class="LineNr">157 </span>a <span class="Delimiter">.</span> z -<span id="L158" class="LineNr">158 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> -<span id="L159" class="LineNr">159 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: z</span> -<span id="L160" class="LineNr">160 </span><span class="traceAbsent">-parse2: <a href='011run.cc.html#L123'>word</a>: .</span> -<span id="L161" class="LineNr">161 </span><span class="Comment"># no other words</span> -<span id="L162" class="LineNr">162 </span>$parse2: <span class="Constant">2</span> -<span id="L163" class="LineNr">163 </span> -<span id="L164" class="LineNr">164 </span><span class="Delimiter">:(scenario parse2_word_starting_with_dot)</span> -<span id="L165" class="LineNr">165 </span>a <span class="Delimiter">.</span>b c -<span id="L166" class="LineNr">166 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> -<span id="L167" class="LineNr">167 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: .b</span> -<span id="L168" class="LineNr">168 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: c</span> -<span id="L169" class="LineNr">169 </span> -<span id="L170" class="LineNr">170 </span><span class="Delimiter">:(scenario parse2_comment_token_at_start)</span> -<span id="L171" class="LineNr">171 </span><span class="Delimiter">.</span> a b -<span id="L172" class="LineNr">172 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> -<span id="L173" class="LineNr">173 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b</span> -<span id="L174" class="LineNr">174 </span><span class="traceAbsent">-parse2: <a href='011run.cc.html#L123'>word</a>: .</span> -<span id="L175" class="LineNr">175 </span> -<span id="L176" class="LineNr">176 </span><span class="Delimiter">:(scenario parse2_comment_token_at_end)</span> -<span id="L177" class="LineNr">177 </span>a b <span class="Delimiter">.</span> -<span id="L178" class="LineNr">178 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> -<span id="L179" class="LineNr">179 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b</span> -<span id="L180" class="LineNr">180 </span><span class="traceAbsent">-parse2: <a href='011run.cc.html#L123'>word</a>: .</span> -<span id="L181" class="LineNr">181 </span> -<span id="L182" class="LineNr">182 </span><span class="Delimiter">:(scenario parse2_word_starting_with_dot_at_start)</span> -<span id="L183" class="LineNr">183 </span><span class="Delimiter">.</span>a b c -<span id="L184" class="LineNr">184 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: .a</span> -<span id="L185" class="LineNr">185 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b</span> -<span id="L186" class="LineNr">186 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: c</span> -<span id="L187" class="LineNr">187 </span> -<span id="L188" class="LineNr">188 </span><span class="Delimiter">:(scenario parse2_metadata)</span> -<span id="L189" class="LineNr">189 </span><span class="Delimiter">.</span>a b/c d -<span id="L190" class="LineNr">190 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: .a</span> -<span id="L191" class="LineNr">191 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b /c</span> -<span id="L192" class="LineNr">192 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: d</span> -<span id="L193" class="LineNr">193 </span> -<span id="L194" class="LineNr">194 </span><span class="Delimiter">:(scenario parse2_string_with_metadata)</span> -<span id="L195" class="LineNr">195 </span>a <span class="Constant">"bc def"</span>/disp32 g -<span id="L196" class="LineNr">196 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> -<span id="L197" class="LineNr">197 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: "bc def" /disp32</span> -<span id="L198" class="LineNr">198 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: g</span> -<span id="L199" class="LineNr">199 </span> -<span id="L200" class="LineNr">200 </span><span class="Delimiter">:(scenario parse2_string_with_metadata_at_end)</span> -<span id="L201" class="LineNr">201 </span>a <span class="Constant">"bc def"</span>/disp32 -<span id="L202" class="LineNr">202 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> -<span id="L203" class="LineNr">203 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: "bc def" /disp32</span> -<span id="L204" class="LineNr">204 </span> -<span id="L205" class="LineNr">205 </span><span class="Delimiter">:(code)</span> -<span id="L206" class="LineNr">206 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L206'>test_parse2_string_with_metadata_at_end_of_line_without_newline</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> -<span id="L207" class="LineNr">207 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> -<span id="L208" class="LineNr">208 </span> <span class="Constant">"68/push </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"</span><span class="Constant">/f"</span> <span class="Comment">// no newline, which is how calls from parse() will look</span> -<span id="L209" class="LineNr">209 </span> <span class="Delimiter">);</span> -<span id="L210" class="LineNr">210 </span> <a href='003trace.cc.html#L257'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> -<span id="L211" class="LineNr">211 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L123'>word</a>: 68 /push^D"</span> -<span id="L212" class="LineNr">212 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L123'>word</a>: </span><span class="cSpecial">\"</span><span class="Constant">test</span><span class="cSpecial">\"</span><span class="Constant"> /f^D"</span> -<span id="L213" class="LineNr">213 </span> <span class="Delimiter">);</span> -<span id="L214" class="LineNr">214 </span><span class="Delimiter">}</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>line_data<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="cSpecial">'\n'</span><span class="Delimiter">)</span> != string::npos && line_data<span class="Delimiter">.</span>find<span class="Delimiter">(</span><span class="cSpecial">'\n'</span><span class="Delimiter">)</span> != line_data<span class="Delimiter">.</span>size<span class="Delimiter">()</span>-<span class="Constant">1</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L98" class="LineNr"> 98 </span> <a href='003trace.cc.html#L210'>raise</a> << <span class="Constant">"parse_instruction_character_by_character: should receive only a single line\n"</span> << end<span class="Delimiter">();</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Identifier">return</span><span class="Delimiter">;</span> +<span id="L100" class="LineNr">100 </span> <span class="Delimiter">}</span> +<span id="L101" class="LineNr">101 </span> <span class="Comment">// parse literals</span> +<span id="L102" class="LineNr">102 </span> istringstream in<span class="Delimiter">(</span>line_data<span class="Delimiter">);</span> +<span id="L103" class="LineNr">103 </span> in >> std::noskipws<span class="Delimiter">;</span> +<span id="L104" class="LineNr">104 </span> <a href='011run.cc.html#L117'>line</a> result<span class="Delimiter">;</span> +<span id="L105" class="LineNr">105 </span> <span class="Comment">// add tokens (words or strings) one by one</span> +<span id="L106" class="LineNr">106 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L107" class="LineNr">107 </span> <a href='038---literal_strings.cc.html#L158'>skip_whitespace</a><span class="Delimiter">(</span>in<span class="Delimiter">);</span> +<span id="L108" class="LineNr">108 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L109" class="LineNr">109 </span> <span class="Normal">char</span> c = in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L110" class="LineNr">110 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment; drop rest of line</span> +<span id="L111" class="LineNr">111 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// line metadata; skip for now</span> +<span id="L112" class="LineNr">112 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'.'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L113" class="LineNr">113 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!has_data<span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Identifier">break</span><span class="Delimiter">;</span> <span class="Comment">// comment token at end of line</span> +<span id="L114" class="LineNr">114 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> +<span id="L115" class="LineNr">115 </span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// '.' followed by space is comment token; skip</span> +<span id="L116" class="LineNr">116 </span> <span class="Delimiter">}</span> +<span id="L117" class="LineNr">117 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span><a href='011run.cc.html#L123'>word</a><span class="Delimiter">());</span> +<span id="L118" class="LineNr">118 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L119" class="LineNr">119 </span> <span class="Comment">// slurp word data</span> +<span id="L120" class="LineNr">120 </span> ostringstream d<span class="Delimiter">;</span> +<span id="L121" class="LineNr">121 </span> d << c<span class="Delimiter">;</span> +<span id="L122" class="LineNr">122 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L123" class="LineNr">123 </span> in >> c<span class="Delimiter">;</span> +<span id="L124" class="LineNr">124 </span> d << c<span class="Delimiter">;</span> +<span id="L125" class="LineNr">125 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'"'</span><span class="Delimiter">)</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L126" class="LineNr">126 </span> <span class="Delimiter">}</span> +<span id="L127" class="LineNr">127 </span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>data = d<span class="Delimiter">.</span>str<span class="Delimiter">();</span> +<span id="L128" class="LineNr">128 </span> <span class="Comment">// slurp metadata</span> +<span id="L129" class="LineNr">129 </span> ostringstream m<span class="Delimiter">;</span> +<span id="L130" class="LineNr">130 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && <a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> +<span id="L131" class="LineNr">131 </span> in >> c<span class="Delimiter">;</span> +<span id="L132" class="LineNr">132 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>c == <span class="Constant">'/'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L133" class="LineNr">133 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!m<span class="Delimiter">.</span>str<span class="Delimiter">().</span>empty<span class="Delimiter">())</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>m<span class="Delimiter">.</span>str<span class="Delimiter">());</span> +<span id="L134" class="LineNr">134 </span> m<span class="Delimiter">.</span>str<span class="Delimiter">(</span><span class="Constant">""</span><span class="Delimiter">);</span> +<span id="L135" class="LineNr">135 </span> <span class="Delimiter">}</span> +<span id="L136" class="LineNr">136 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L137" class="LineNr">137 </span> m << c<span class="Delimiter">;</span> +<span id="L138" class="LineNr">138 </span> <span class="Delimiter">}</span> +<span id="L139" class="LineNr">139 </span> <span class="Delimiter">}</span> +<span id="L140" class="LineNr">140 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!m<span class="Delimiter">.</span>str<span class="Delimiter">().</span>empty<span class="Delimiter">())</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">().</span>metadata<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>m<span class="Delimiter">.</span>str<span class="Delimiter">());</span> +<span id="L141" class="LineNr">141 </span> <span class="Delimiter">}</span> +<span id="L142" class="LineNr">142 </span> <span class="Normal">else</span> <span class="Delimiter">{</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment">// slurp all characters until whitespace</span> +<span id="L144" class="LineNr">144 </span> ostringstream w<span class="Delimiter">;</span> +<span id="L145" class="LineNr">145 </span> w << c<span class="Delimiter">;</span> +<span id="L146" class="LineNr">146 </span> <span class="Normal">while</span> <span class="Delimiter">(</span>!isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">())</span> && <a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">))</span> <span class="Delimiter">{</span> <span class="Comment">// peek can sometimes trigger eof(), so do it first</span> +<span id="L147" class="LineNr">147 </span> in >> c<span class="Delimiter">;</span> +<span id="L148" class="LineNr">148 </span> w << c<span class="Delimiter">;</span> +<span id="L149" class="LineNr">149 </span> <span class="Delimiter">}</span> +<span id="L150" class="LineNr">150 </span> <a href='011run.cc.html#L191'>parse_word</a><span class="Delimiter">(</span>w<span class="Delimiter">.</span>str<span class="Delimiter">(),</span> result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">());</span> +<span id="L151" class="LineNr">151 </span> <span class="Delimiter">}</span> +<span id="L152" class="LineNr">152 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">99</span><span class="Delimiter">,</span> <span class="Constant">"parse2"</span><span class="Delimiter">)</span> << <span class="Constant">"word: "</span> << to_string<span class="Delimiter">(</span>result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>back<span class="Delimiter">())</span> << end<span class="Delimiter">();</span> +<span id="L153" class="LineNr">153 </span> <span class="Delimiter">}</span> +<span id="L154" class="LineNr">154 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!result<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>empty<span class="Delimiter">())</span> +<span id="L155" class="LineNr">155 </span> out<span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>result<span class="Delimiter">);</span> +<span id="L156" class="LineNr">156 </span><span class="Delimiter">}</span> +<span id="L157" class="LineNr">157 </span> +<span id="L158" class="LineNr">158 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L158'>skip_whitespace</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L159" class="LineNr">159 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><span class="Constant">true</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L160" class="LineNr">160 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && isspace<span class="Delimiter">(</span>in<span class="Delimiter">.</span>peek<span class="Delimiter">()))</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L161" class="LineNr">161 </span> <span class="Normal">else</span> <span class="Identifier">break</span><span class="Delimiter">;</span> +<span id="L162" class="LineNr">162 </span> <span class="Delimiter">}</span> +<span id="L163" class="LineNr">163 </span><span class="Delimiter">}</span> +<span id="L164" class="LineNr">164 </span> +<span id="L165" class="LineNr">165 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L165'>skip_comment</a><span class="Delimiter">(</span>istream& in<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L166" class="LineNr">166 </span> <span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> == <span class="Constant">'#'</span><span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L167" class="LineNr">167 </span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L168" class="LineNr">168 </span> <span class="Normal">while</span> <span class="Delimiter">(</span><a href='001help.cc.html#L265'>has_data</a><span class="Delimiter">(</span>in<span class="Delimiter">)</span> && in<span class="Delimiter">.</span>peek<span class="Delimiter">()</span> != <span class="cSpecial">'\n'</span><span class="Delimiter">)</span> in<span class="Delimiter">.</span>get<span class="Delimiter">();</span> +<span id="L169" class="LineNr">169 </span> <span class="Delimiter">}</span> +<span id="L170" class="LineNr">170 </span><span class="Delimiter">}</span> +<span id="L171" class="LineNr">171 </span> +<span id="L172" class="LineNr">172 </span><span class="Comment">// helper for tests</span> +<span id="L173" class="LineNr">173 </span><span class="Normal">void</span> parse_instruction_character_by_character<span class="Delimiter">(</span><span class="Normal">const</span> string& line_data<span class="Delimiter">)</span> <span class="Delimiter">{</span> +<span id="L174" class="LineNr">174 </span> vector<line> out<span class="Delimiter">;</span> +<span id="L175" class="LineNr">175 </span> parse_instruction_character_by_character<span class="Delimiter">(</span>line_data<span class="Delimiter">,</span> out<span class="Delimiter">);</span> +<span id="L176" class="LineNr">176 </span><span class="Delimiter">}</span> +<span id="L177" class="LineNr">177 </span> +<span id="L178" class="LineNr">178 </span><span class="Delimiter">:(scenario parse2_comment_token_in_middle)</span> +<span id="L179" class="LineNr">179 </span>a <span class="Delimiter">.</span> z +<span id="L180" class="LineNr">180 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> +<span id="L181" class="LineNr">181 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: z</span> +<span id="L182" class="LineNr">182 </span><span class="traceAbsent">-parse2: <a href='011run.cc.html#L123'>word</a>: .</span> +<span id="L183" class="LineNr">183 </span><span class="Comment"># no other words</span> +<span id="L184" class="LineNr">184 </span>$parse2: <span class="Constant">2</span> +<span id="L185" class="LineNr">185 </span> +<span id="L186" class="LineNr">186 </span><span class="Delimiter">:(scenario parse2_word_starting_with_dot)</span> +<span id="L187" class="LineNr">187 </span>a <span class="Delimiter">.</span>b c +<span id="L188" class="LineNr">188 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> +<span id="L189" class="LineNr">189 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: .b</span> +<span id="L190" class="LineNr">190 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: c</span> +<span id="L191" class="LineNr">191 </span> +<span id="L192" class="LineNr">192 </span><span class="Delimiter">:(scenario parse2_comment_token_at_start)</span> +<span id="L193" class="LineNr">193 </span><span class="Delimiter">.</span> a b +<span id="L194" class="LineNr">194 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> +<span id="L195" class="LineNr">195 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b</span> +<span id="L196" class="LineNr">196 </span><span class="traceAbsent">-parse2: <a href='011run.cc.html#L123'>word</a>: .</span> +<span id="L197" class="LineNr">197 </span> +<span id="L198" class="LineNr">198 </span><span class="Delimiter">:(scenario parse2_comment_token_at_end)</span> +<span id="L199" class="LineNr">199 </span>a b <span class="Delimiter">.</span> +<span id="L200" class="LineNr">200 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> +<span id="L201" class="LineNr">201 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b</span> +<span id="L202" class="LineNr">202 </span><span class="traceAbsent">-parse2: <a href='011run.cc.html#L123'>word</a>: .</span> +<span id="L203" class="LineNr">203 </span> +<span id="L204" class="LineNr">204 </span><span class="Delimiter">:(scenario parse2_word_starting_with_dot_at_start)</span> +<span id="L205" class="LineNr">205 </span><span class="Delimiter">.</span>a b c +<span id="L206" class="LineNr">206 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: .a</span> +<span id="L207" class="LineNr">207 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b</span> +<span id="L208" class="LineNr">208 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: c</span> +<span id="L209" class="LineNr">209 </span> +<span id="L210" class="LineNr">210 </span><span class="Delimiter">:(scenario parse2_metadata)</span> +<span id="L211" class="LineNr">211 </span><span class="Delimiter">.</span>a b/c d +<span id="L212" class="LineNr">212 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: .a</span> +<span id="L213" class="LineNr">213 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: b /c</span> +<span id="L214" class="LineNr">214 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: d</span> +<span id="L215" class="LineNr">215 </span> +<span id="L216" class="LineNr">216 </span><span class="Delimiter">:(scenario parse2_string_with_metadata)</span> +<span id="L217" class="LineNr">217 </span>a <span class="Constant">"bc def"</span>/disp32 g +<span id="L218" class="LineNr">218 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> +<span id="L219" class="LineNr">219 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: "bc def" /disp32</span> +<span id="L220" class="LineNr">220 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: g</span> +<span id="L221" class="LineNr">221 </span> +<span id="L222" class="LineNr">222 </span><span class="Delimiter">:(scenario parse2_string_with_metadata_at_end)</span> +<span id="L223" class="LineNr">223 </span>a <span class="Constant">"bc def"</span>/disp32 +<span id="L224" class="LineNr">224 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: a</span> +<span id="L225" class="LineNr">225 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: "bc def" /disp32</span> +<span id="L226" class="LineNr">226 </span> +<span id="L227" class="LineNr">227 </span><span class="Delimiter">:(code)</span> +<span id="L228" class="LineNr">228 </span><span class="Normal">void</span> <a href='038---literal_strings.cc.html#L228'>test_parse2_string_with_metadata_at_end_of_line_without_newline</a><span class="Delimiter">()</span> <span class="Delimiter">{</span> +<span id="L229" class="LineNr">229 </span> parse_instruction_character_by_character<span class="Delimiter">(</span> +<span id="L230" class="LineNr">230 </span> <span class="Constant">"68/push \"</span>test\<span class="Constant">"/f"</span> <span class="Comment">// no newline, which is how calls from parse() will look</span> +<span id="L231" class="LineNr">231 </span> <span class="Delimiter">);</span> +<span id="L232" class="LineNr">232 </span> <a href='003trace.cc.html#L257'>CHECK_TRACE_CONTENTS</a><span class="Delimiter">(</span> +<span id="L233" class="LineNr">233 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L123'>word</a>: 68 /push^D"</span> +<span id="L234" class="LineNr">234 </span> <span class="Constant">"parse2: <a href='011run.cc.html#L123'>word</a>: \"</span>test\<span class="Constant">" /f^D"</span> +<span id="L235" class="LineNr">235 </span> <span class="Delimiter">);</span> +<span id="L236" class="LineNr">236 </span><span class="Delimiter">}</span> +<span id="L237" class="LineNr">237 </span> +<span id="L238" class="LineNr">238 </span><span class="Comment">//: Make sure slashes inside strings don't trigger adding stuff from inside the</span> +<span id="L239" class="LineNr">239 </span><span class="Comment">//: string to metadata.</span> +<span id="L240" class="LineNr">240 </span><span class="Delimiter">:(scenario parse2_string_containing_slashes)</span> +<span id="L241" class="LineNr">241 </span>a <span class="Constant">"bc/def"</span>/disp32 +<span id="L242" class="LineNr">242 </span><span class="traceContains">+parse2: <a href='011run.cc.html#L123'>word</a>: "bc/def" /disp32</span> </pre> </body> </html> diff --git a/html/subx/039debug.cc.html b/html/subx/039debug.cc.html index 9cf21c15..c52eece9 100644 --- a/html/subx/039debug.cc.html +++ b/html/subx/039debug.cc.html @@ -18,6 +18,7 @@ a:hover { text-decoration: underline; } .LineNr { color: #444444; } .Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Normal { color: #aaaaaa; background-color: #080808; padding-bottom: 1px; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } @@ -61,7 +62,7 @@ if ('onhashchange' in window) { <span id="L4" class="LineNr"> 4 </span><span class="Comment">// (It'll only affect the trace.)</span> <span id="L5" class="LineNr"> 5 </span> <span id="L6" class="LineNr"> 6 </span><span class="Delimiter">:(before "End Globals")</span> -<span id="L7" class="LineNr"> 7 </span>map<<span class="Comment">/*</span><span class="Comment">address</span><span class="Comment">*/</span><span class="Normal">uint32_t</span><span class="Delimiter">,</span> string> <a href='039debug.cc.html#L7'>Symbol_name</a><span class="Delimiter">;</span> <span class="Comment">// used only by 'subx run'</span> +<span id="L7" class="LineNr"> 7 </span>map<<span class="Comment">/*</span><span class="Comment">address</span><span class="Comment">*/</span><span class="Normal">uint32_t</span><span class="Delimiter">,</span> string> <span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">;</span> <span class="Comment">// used only by 'subx run'</span> <span id="L8" class="LineNr"> 8 </span><span class="Delimiter">:(before "End --map Settings")</span> <span id="L9" class="LineNr"> 9 </span><a href='039debug.cc.html#L11'>load_map</a><span class="Delimiter">(</span><span class="Constant">"map"</span><span class="Delimiter">);</span> <span id="L10" class="LineNr">10 </span><span class="Delimiter">:(code)</span> @@ -73,13 +74,13 @@ if ('onhashchange' in window) { <span id="L16" class="LineNr">16 </span> fin >> addr<span class="Delimiter">;</span> <span id="L17" class="LineNr">17 </span> string name<span class="Delimiter">;</span> <span id="L18" class="LineNr">18 </span> fin >> name<span class="Delimiter">;</span> -<span id="L19" class="LineNr">19 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><a href='039debug.cc.html#L7'>Symbol_name</a><span class="Delimiter">,</span> addr<span class="Delimiter">,</span> name<span class="Delimiter">);</span> +<span id="L19" class="LineNr">19 </span> <a href='001help.cc.html#L243'>put</a><span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> addr<span class="Delimiter">,</span> name<span class="Delimiter">);</span> <span id="L20" class="LineNr">20 </span> <span class="Delimiter">}</span> <span id="L21" class="LineNr">21 </span><span class="Delimiter">}</span> <span id="L22" class="LineNr">22 </span> <span id="L23" class="LineNr">23 </span><span class="Delimiter">:(after "Run One Instruction")</span> -<span id="L24" class="LineNr">24 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span><a href='039debug.cc.html#L7'>Symbol_name</a><span class="Delimiter">,</span> <a href='010---vm.cc.html#L29'>EIP</a><span class="Delimiter">))</span> -<span id="L25" class="LineNr">25 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"== label "</span> << get<span class="Delimiter">(</span><a href='039debug.cc.html#L7'>Symbol_name</a><span class="Delimiter">,</span> <a href='010---vm.cc.html#L29'>EIP</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> +<span id="L24" class="LineNr">24 </span><span class="Normal">if</span> <span class="Delimiter">(</span><a href='001help.cc.html#L247'>contains_key</a><span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> <a href='010---vm.cc.html#L29'>EIP</a><span class="Delimiter">))</span> +<span id="L25" class="LineNr">25 </span> <a href='003trace.cc.html#L203'>trace</a><span class="Delimiter">(</span><span class="Constant">90</span><span class="Delimiter">,</span> <span class="Constant">"run"</span><span class="Delimiter">)</span> << <span class="Constant">"== label "</span> << get<span class="Delimiter">(</span><span class="Special"><a href='039debug.cc.html#L7'>Symbol_name</a></span><span class="Delimiter">,</span> <a href='010---vm.cc.html#L29'>EIP</a><span class="Delimiter">)</span> << end<span class="Delimiter">();</span> </pre> </body> </html> diff --git a/html/subx/040---tests.cc.html b/html/subx/040---tests.cc.html index a37c0e15..14ae7ce0 100644 --- a/html/subx/040---tests.cc.html +++ b/html/subx/040---tests.cc.html @@ -73,7 +73,7 @@ if ('onhashchange' in window) { <span id="L11" class="LineNr">11 </span><span class="Comment">//: knows about labels and will emit labels for previous layers to transform.</span> <span id="L12" class="LineNr">12 </span><span class="Delimiter">:(after "Begin Transforms")</span> <span id="L13" class="LineNr">13 </span><span class="Comment">// Begin Level-4 Transforms</span> -<span id="L14" class="LineNr">14 </span><a href='011run.cc.html#L229'>Transform</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>create_test_function<span class="Delimiter">);</span> +<span id="L14" class="LineNr">14 </span><span class="Special"><a href='011run.cc.html#L229'>Transform</a></span><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>create_test_function<span class="Delimiter">);</span> <span id="L15" class="LineNr">15 </span><span class="Comment">// End Level-4 Transforms</span> <span id="L16" class="LineNr">16 </span> <span id="L17" class="LineNr">17 </span><span class="Delimiter">:(scenario run_test)</span> @@ -102,7 +102,7 @@ if ('onhashchange' in window) { <span id="L40" class="LineNr">40 </span> <span class="Normal">const</span> word& curr = inst<span class="Delimiter">.</span><a href='011run.cc.html#L118'>words</a><span class="Delimiter">.</span>at<span class="Delimiter">(</span>j<span class="Delimiter">);</span> <span id="L41" class="LineNr">41 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>*curr<span class="Delimiter">.</span>data<span class="Delimiter">.</span>rbegin<span class="Delimiter">()</span> != <span class="Constant">':'</span><span class="Delimiter">)</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> <span class="Comment">// not a label</span> <span id="L42" class="LineNr">42 </span> <span class="Normal">if</span> <span class="Delimiter">(</span>!starts_with<span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">,</span> <span class="Constant">"test-"</span><span class="Delimiter">))</span> <span class="Identifier">continue</span><span class="Delimiter">;</span> -<span id="L43" class="LineNr">43 </span> string fn = <a href='035labels.cc.html#L204'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> +<span id="L43" class="LineNr">43 </span> string fn = <a href='035labels.cc.html#L209'>drop_last</a><span class="Delimiter">(</span>curr<span class="Delimiter">.</span>data<span class="Delimiter">);</span> <span id="L44" class="LineNr">44 </span> <a href='040---tests.cc.html#L36'>new_insts</a><span class="Delimiter">.</span>push_back<span class="Delimiter">(</span>call<span class="Delimiter">(</span>fn<span class="Delimiter">));</span> <span id="L45" class="LineNr">45 </span> <span class="Delimiter">}</span> <span id="L46" class="LineNr">46 </span> <span class="Delimiter">}</span> diff --git a/html/subx/050_write.subx.html b/html/subx/050_write.subx.html index ec944002..6e8e6f7e 100644 --- a/html/subx/050_write.subx.html +++ b/html/subx/050_write.subx.html @@ -56,49 +56,48 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment"># _write: write to a file descriptor</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span>== code -<span id="L4" class="LineNr"> 4 </span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L7" class="LineNr"> 7 </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> -<span id="L8" class="LineNr"> 8 </span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L10" class="LineNr">10 </span> <span class="Comment"># syscall(exit, 0) -- can't test these functions just yet</span> -<span id="L11" class="LineNr">11 </span> bb/copy-to-EBX 0/imm32 -<span id="L12" class="LineNr">12 </span> b8/copy-to-EAX 1/imm32 -<span id="L13" class="LineNr">13 </span> cd/syscall 0x80/imm8 -<span id="L14" class="LineNr">14 </span> -<span id="L15" class="LineNr">15 </span>_write: <span class="Comment"># fd : int, s : (address array byte) -> <void></span> -<span id="L16" class="LineNr">16 </span> <span class="Comment"># prolog</span> -<span id="L17" class="LineNr">17 </span> 55/push-EBP -<span id="L18" class="LineNr">18 </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="L19" class="LineNr">19 </span> <span class="Comment"># save registers</span> -<span id="L20" class="LineNr">20 </span> 50/push-EAX -<span id="L21" class="LineNr">21 </span> 51/push-ECX -<span id="L22" class="LineNr">22 </span> 52/push-EDX -<span id="L23" class="LineNr">23 </span> 53/push-EBX -<span id="L24" class="LineNr">24 </span> <span class="Comment"># syscall(write, fd, (data) s+4, (size) *s)</span> -<span id="L25" class="LineNr">25 </span> <span class="Comment"># fd : EBX</span> -<span id="L26" class="LineNr">26 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EBX</span> -<span id="L27" class="LineNr">27 </span> <span class="Comment"># data : ECX = s+4</span> -<span id="L28" class="LineNr">28 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ECX</span> -<span id="L29" class="LineNr">29 </span> 81 0/subop/add 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ECX</span> -<span id="L30" class="LineNr">30 </span> <span class="Comment"># size : EDX = *s</span> -<span id="L31" class="LineNr">31 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> -<span id="L32" class="LineNr">32 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> -<span id="L33" class="LineNr">33 </span> <span class="Comment"># syscall</span> -<span id="L34" class="LineNr">34 </span> b8/copy-to-EAX 4/imm32/write -<span id="L35" class="LineNr">35 </span> cd/syscall 0x80/imm8 -<span id="L36" class="LineNr">36 </span> <span class="Comment"># restore registers</span> -<span id="L37" class="LineNr">37 </span> 5b/pop-to-EBX -<span id="L38" class="LineNr">38 </span> 5a/pop-to-EDX -<span id="L39" class="LineNr">39 </span> 59/pop-to-ECX -<span id="L40" class="LineNr">40 </span> 58/pop-to-EAX -<span id="L41" class="LineNr">41 </span> <span class="Comment"># epilog</span> -<span id="L42" class="LineNr">42 </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="L43" class="LineNr">43 </span> 5d/pop-to-EBP -<span id="L44" class="LineNr">44 </span> c3/return -<span id="L45" class="LineNr">45 </span> -<span id="L46" class="LineNr">46 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L6" class="LineNr"> 6 </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> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># main:</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Comment"># syscall(exit, 0) -- can't test _write just yet</span> +<span id="L10" class="LineNr">10 </span> bb/copy-to-EBX 0/imm32 +<span id="L11" class="LineNr">11 </span> b8/copy-to-EAX 1/imm32 +<span id="L12" class="LineNr">12 </span> cd/syscall 0x80/imm8 +<span id="L13" class="LineNr">13 </span> +<span id="L14" class="LineNr">14 </span>_write: <span class="Comment"># fd : int, s : (address array byte) -> <void></span> +<span id="L15" class="LineNr">15 </span> <span class="Comment"># prolog</span> +<span id="L16" class="LineNr">16 </span> 55/push-EBP +<span id="L17" class="LineNr">17 </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="L18" class="LineNr">18 </span> <span class="Comment"># save registers</span> +<span id="L19" class="LineNr">19 </span> 50/push-EAX +<span id="L20" class="LineNr">20 </span> 51/push-ECX +<span id="L21" class="LineNr">21 </span> 52/push-EDX +<span id="L22" class="LineNr">22 </span> 53/push-EBX +<span id="L23" class="LineNr">23 </span> <span class="Comment"># syscall(write, fd, (data) s+4, (size) *s)</span> +<span id="L24" class="LineNr">24 </span> <span class="Comment"># fd : EBX</span> +<span id="L25" class="LineNr">25 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EBX</span> +<span id="L26" class="LineNr">26 </span> <span class="Comment"># data : ECX = s+4</span> +<span id="L27" class="LineNr">27 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ECX</span> +<span id="L28" class="LineNr">28 </span> 81 0/subop/add 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ECX</span> +<span id="L29" class="LineNr">29 </span> <span class="Comment"># size : EDX = *s</span> +<span id="L30" class="LineNr">30 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> +<span id="L31" class="LineNr">31 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> +<span id="L32" class="LineNr">32 </span> <span class="Comment"># syscall</span> +<span id="L33" class="LineNr">33 </span> b8/copy-to-EAX 4/imm32/write +<span id="L34" class="LineNr">34 </span> cd/syscall 0x80/imm8 +<span id="L35" class="LineNr">35 </span> <span class="Comment"># restore registers</span> +<span id="L36" class="LineNr">36 </span> 5b/pop-to-EBX +<span id="L37" class="LineNr">37 </span> 5a/pop-to-EDX +<span id="L38" class="LineNr">38 </span> 59/pop-to-ECX +<span id="L39" class="LineNr">39 </span> 58/pop-to-EAX +<span id="L40" class="LineNr">40 </span> <span class="Comment"># epilog</span> +<span id="L41" class="LineNr">41 </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="L42" class="LineNr">42 </span> 5d/pop-to-EBP +<span id="L43" class="LineNr">43 </span> c3/return +<span id="L44" class="LineNr">44 </span> +<span id="L45" class="LineNr">45 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/051test.subx.html b/html/subx/051test.subx.html index 6e616a8a..724ddbdd 100644 --- a/html/subx/051test.subx.html +++ b/html/subx/051test.subx.html @@ -17,6 +17,8 @@ a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } .Delimiter { color: #800080; } +.Constant { color: #00a0a0; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } --> @@ -56,89 +58,88 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment"># Rudimentary test harness</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span>== code -<span id="L4" class="LineNr"> 4 </span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L7" class="LineNr"> 7 </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> -<span id="L8" class="LineNr"> 8 </span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L10" class="LineNr">10 </span> <span class="Comment"># check-ints-equal(34, 34)</span> -<span id="L11" class="LineNr">11 </span> 68/push "error in check-ints-equal"/imm32 +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L6" class="LineNr"> 6 </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> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Comment"># check-ints-equal(34, 34)</span> +<span id="L10" class="LineNr">10 </span> 68/push <span class="Constant">"error in check-ints-equal"</span>/imm32 +<span id="L11" class="LineNr">11 </span> 68/push 34/imm32 <span id="L12" class="LineNr">12 </span> 68/push 34/imm32 -<span id="L13" class="LineNr">13 </span> 68/push 34/imm32 -<span id="L14" class="LineNr">14 </span> e8/call check-ints-equal/disp32 -<span id="L15" class="LineNr">15 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L16" class="LineNr">16 </span> <span class="Comment"># syscall(exit, 0)</span> -<span id="L17" class="LineNr">17 </span> bb/copy-to-EBX 0/imm32 -<span id="L18" class="LineNr">18 </span> b8/copy-to-EAX 1/imm32 -<span id="L19" class="LineNr">19 </span> cd/syscall 0x80/imm8 -<span id="L20" class="LineNr">20 </span> -<span id="L21" class="LineNr">21 </span><span class="Comment"># print msg to stderr if a != b, otherwise print "."</span> -<span id="L22" class="LineNr">22 </span>check-ints-equal: <span class="Comment"># (a : int, b : int, msg : (address array byte)) -> boolean</span> -<span id="L23" class="LineNr">23 </span> <span class="Comment"># prolog</span> -<span id="L24" class="LineNr">24 </span> 55/push-EBP -<span id="L25" class="LineNr">25 </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="L26" class="LineNr">26 </span> <span class="Comment"># save registers</span> -<span id="L27" class="LineNr">27 </span> 51/push-ECX -<span id="L28" class="LineNr">28 </span> 53/push-EBX -<span id="L29" class="LineNr">29 </span> <span class="Comment"># load first 2 args into EAX and EBX</span> -<span id="L30" class="LineNr">30 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> -<span id="L31" class="LineNr">31 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EBX</span> -<span id="L32" class="LineNr">32 </span> <span class="Comment"># if EAX == b/EBX</span> -<span id="L33" class="LineNr">33 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX and EBX</span> -<span id="L34" class="LineNr">34 </span> 75/jump-if-unequal $check-ints-equal:else/disp8 -<span id="L35" class="LineNr">35 </span> <span class="Comment"># _write(2/stderr, '.')</span> -<span id="L36" class="LineNr">36 </span> <span class="Comment"># push args</span> -<span id="L37" class="LineNr">37 </span> 68/push "."/imm32 -<span id="L38" class="LineNr">38 </span> 68/push 2/imm32/stderr -<span id="L39" class="LineNr">39 </span> <span class="Comment"># call</span> -<span id="L40" class="LineNr">40 </span> e8/call _write/disp32 -<span id="L41" class="LineNr">41 </span> <span class="Comment"># discard args</span> -<span id="L42" class="LineNr">42 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L43" class="LineNr">43 </span> <span class="Comment"># return</span> -<span id="L44" class="LineNr">44 </span> eb/jump $check-ints-equal:end/disp8 -<span id="L45" class="LineNr">45 </span> <span class="Comment"># else:</span> -<span id="L46" class="LineNr">46 </span>$check-ints-equal:else: -<span id="L47" class="LineNr">47 </span> <span class="Comment"># _write(2/stderr, msg)</span> -<span id="L48" class="LineNr">48 </span> <span class="Comment"># push args</span> -<span id="L49" class="LineNr">49 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to ECX</span> -<span id="L50" class="LineNr">50 </span> 51/push-ECX -<span id="L51" class="LineNr">51 </span> 68/push 2/imm32/stderr -<span id="L52" class="LineNr">52 </span> <span class="Comment"># call</span> -<span id="L53" class="LineNr">53 </span> e8/call _write/disp32 -<span id="L54" class="LineNr">54 </span> <span class="Comment"># discard args</span> -<span id="L55" class="LineNr">55 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L56" class="LineNr">56 </span> <span class="Comment"># _write(2/stderr, Newline)</span> -<span id="L57" class="LineNr">57 </span> <span class="Comment"># push args</span> -<span id="L58" class="LineNr">58 </span> 68/push Newline/imm32 -<span id="L59" class="LineNr">59 </span> 68/push 2/imm32/stderr -<span id="L60" class="LineNr">60 </span> <span class="Comment"># call</span> -<span id="L61" class="LineNr">61 </span> e8/call _write/disp32 -<span id="L62" class="LineNr">62 </span> <span class="Comment"># discard args</span> -<span id="L63" class="LineNr">63 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L64" class="LineNr">64 </span> <span class="Comment"># increment Num-test-failures</span> -<span id="L65" class="LineNr">65 </span> ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> Num-test-failures/disp32 <span class="Comment"># increment *Num-test-failures</span> -<span id="L66" class="LineNr">66 </span>$check-ints-equal:end: -<span id="L67" class="LineNr">67 </span> <span class="Comment"># restore registers</span> -<span id="L68" class="LineNr">68 </span> 5b/pop-to-EBX -<span id="L69" class="LineNr">69 </span> 59/pop-to-ECX -<span id="L70" class="LineNr">70 </span> <span class="Comment"># epilog</span> -<span id="L71" class="LineNr">71 </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="L72" class="LineNr">72 </span> 5d/pop-to-EBP -<span id="L73" class="LineNr">73 </span> c3/return -<span id="L74" class="LineNr">74 </span> -<span id="L75" class="LineNr">75 </span>== data -<span id="L76" class="LineNr">76 </span> -<span id="L77" class="LineNr">77 </span>Newline: -<span id="L78" class="LineNr">78 </span> <span class="Comment"># size</span> -<span id="L79" class="LineNr">79 </span> 01 00 00 00 -<span id="L80" class="LineNr">80 </span> <span class="Comment"># data</span> -<span id="L81" class="LineNr">81 </span> 0a/newline -<span id="L82" class="LineNr">82 </span> -<span id="L83" class="LineNr">83 </span>Num-test-failures: -<span id="L84" class="LineNr">84 </span> 00 00 00 00 -<span id="L85" class="LineNr">85 </span> -<span id="L86" class="LineNr">86 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L13" class="LineNr">13 </span> e8/call check-ints-equal/disp32 +<span id="L14" class="LineNr">14 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L15" class="LineNr">15 </span> <span class="Comment"># syscall(exit, 0)</span> +<span id="L16" class="LineNr">16 </span> bb/copy-to-EBX 0/imm32 +<span id="L17" class="LineNr">17 </span> b8/copy-to-EAX 1/imm32 +<span id="L18" class="LineNr">18 </span> cd/syscall 0x80/imm8 +<span id="L19" class="LineNr">19 </span> +<span id="L20" class="LineNr">20 </span><span class="Comment"># print msg to stderr if a != b, otherwise print "."</span> +<span id="L21" class="LineNr">21 </span>check-ints-equal: <span class="Comment"># (a : int, b : int, msg : (address array byte)) -> boolean</span> +<span id="L22" class="LineNr">22 </span> <span class="Comment"># prolog</span> +<span id="L23" class="LineNr">23 </span> 55/push-EBP +<span id="L24" class="LineNr">24 </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="L25" class="LineNr">25 </span> <span class="Comment"># save registers</span> +<span id="L26" class="LineNr">26 </span> 51/push-ECX +<span id="L27" class="LineNr">27 </span> 53/push-EBX +<span id="L28" class="LineNr">28 </span> <span class="Comment"># load first 2 args into EAX and EBX</span> +<span id="L29" class="LineNr">29 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> +<span id="L30" class="LineNr">30 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EBX</span> +<span id="L31" class="LineNr">31 </span> <span class="Comment"># if EAX == b/EBX</span> +<span id="L32" class="LineNr">32 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX and EBX</span> +<span id="L33" class="LineNr">33 </span> 75/jump-if-unequal $check-ints-equal:else/disp8 +<span id="L34" class="LineNr">34 </span> <span class="Comment"># _write(2/stderr, '.')</span> +<span id="L35" class="LineNr">35 </span> <span class="Comment"># push args</span> +<span id="L36" class="LineNr">36 </span> 68/push <span class="Constant">"."</span>/imm32 +<span id="L37" class="LineNr">37 </span> 68/push 2/imm32/stderr +<span id="L38" class="LineNr">38 </span> <span class="Comment"># call</span> +<span id="L39" class="LineNr">39 </span> e8/call _write/disp32 +<span id="L40" class="LineNr">40 </span> <span class="Comment"># discard args</span> +<span id="L41" class="LineNr">41 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L42" class="LineNr">42 </span> <span class="Comment"># return</span> +<span id="L43" class="LineNr">43 </span> eb/jump $check-ints-equal:end/disp8 +<span id="L44" class="LineNr">44 </span> <span class="Comment"># else:</span> +<span id="L45" class="LineNr">45 </span>$check-ints-equal:else: +<span id="L46" class="LineNr">46 </span> <span class="Comment"># _write(2/stderr, msg)</span> +<span id="L47" class="LineNr">47 </span> <span class="Comment"># push args</span> +<span id="L48" class="LineNr">48 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to ECX</span> +<span id="L49" class="LineNr">49 </span> 51/push-ECX +<span id="L50" class="LineNr">50 </span> 68/push 2/imm32/stderr +<span id="L51" class="LineNr">51 </span> <span class="Comment"># call</span> +<span id="L52" class="LineNr">52 </span> e8/call _write/disp32 +<span id="L53" class="LineNr">53 </span> <span class="Comment"># discard args</span> +<span id="L54" class="LineNr">54 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L55" class="LineNr">55 </span> <span class="Comment"># _write(2/stderr, Newline)</span> +<span id="L56" class="LineNr">56 </span> <span class="Comment"># push args</span> +<span id="L57" class="LineNr">57 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L58" class="LineNr">58 </span> 68/push 2/imm32/stderr +<span id="L59" class="LineNr">59 </span> <span class="Comment"># call</span> +<span id="L60" class="LineNr">60 </span> e8/call _write/disp32 +<span id="L61" class="LineNr">61 </span> <span class="Comment"># discard args</span> +<span id="L62" class="LineNr">62 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L63" class="LineNr">63 </span> <span class="Comment"># increment Num-test-failures</span> +<span id="L64" class="LineNr">64 </span> ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># increment *Num-test-failures</span> +<span id="L65" class="LineNr">65 </span>$check-ints-equal:end: +<span id="L66" class="LineNr">66 </span> <span class="Comment"># restore registers</span> +<span id="L67" class="LineNr">67 </span> 5b/pop-to-EBX +<span id="L68" class="LineNr">68 </span> 59/pop-to-ECX +<span id="L69" class="LineNr">69 </span> <span class="Comment"># epilog</span> +<span id="L70" class="LineNr">70 </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="L71" class="LineNr">71 </span> 5d/pop-to-EBP +<span id="L72" class="LineNr">72 </span> c3/return +<span id="L73" class="LineNr">73 </span> +<span id="L74" class="LineNr">74 </span>== data +<span id="L75" class="LineNr">75 </span> +<span id="L76" class="LineNr">76 </span><span class="Special">Newline</span>: +<span id="L77" class="LineNr">77 </span> <span class="Comment"># size</span> +<span id="L78" class="LineNr">78 </span> 01 00 00 00 +<span id="L79" class="LineNr">79 </span> <span class="Comment"># data</span> +<span id="L80" class="LineNr">80 </span> 0a/newline +<span id="L81" class="LineNr">81 </span> +<span id="L82" class="LineNr">82 </span><span class="Special">Num-test-failures</span>: +<span id="L83" class="LineNr">83 </span> 00 00 00 00 +<span id="L84" class="LineNr">84 </span> +<span id="L85" class="LineNr">85 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/052kernel_string_equal.subx.html b/html/subx/052kernel_string_equal.subx.html index 5322761d..35dd393c 100644 --- a/html/subx/052kernel_string_equal.subx.html +++ b/html/subx/052kernel_string_equal.subx.html @@ -16,7 +16,9 @@ a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -71,251 +73,250 @@ if ('onhashchange' in window) { <span id="L15" class="LineNr"> 15 </span><span class="Comment"># would cause tests to not run, rather than to fail as we'd like.)</span> <span id="L16" class="LineNr"> 16 </span> <span id="L17" class="LineNr"> 17 </span>== code -<span id="L18" class="LineNr"> 18 </span> -<span id="L19" class="LineNr"> 19 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L20" class="LineNr"> 20 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L21" class="LineNr"> 21 </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> -<span id="L22" class="LineNr"> 22 </span> -<span id="L23" class="LineNr"> 23 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L24" class="LineNr"> 24 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> -<span id="L25" class="LineNr"> 25 </span> <span class="Comment"># exit(Num-test-failures)</span> -<span id="L26" class="LineNr"> 26 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX Num-test-failures/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> -<span id="L27" class="LineNr"> 27 </span> b8/copy-to-EAX 1/imm32 -<span id="L28" class="LineNr"> 28 </span> cd/syscall 0x80/imm8 -<span id="L29" class="LineNr"> 29 </span> -<span id="L30" class="LineNr"> 30 </span><span class="Comment"># compare a null-terminated ascii string with a more idiomatic length-prefixed byte array</span> -<span id="L31" class="LineNr"> 31 </span><span class="Comment"># reason for the name: the only place we should have null-terminated ascii strings is from commandline args</span> -<span id="L32" class="LineNr"> 32 </span>kernel-string-equal: <span class="Comment"># s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean</span> -<span id="L33" class="LineNr"> 33 </span> <span class="Comment"># prolog</span> -<span id="L34" class="LineNr"> 34 </span> 55/push-EBP -<span id="L35" class="LineNr"> 35 </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="L36" class="LineNr"> 36 </span> <span class="Comment"># save registers</span> -<span id="L37" class="LineNr"> 37 </span> 51/push-ECX -<span id="L38" class="LineNr"> 38 </span> 52/push-EDX -<span id="L39" class="LineNr"> 39 </span> 53/push-EBX -<span id="L40" class="LineNr"> 40 </span> 56/push-ESI -<span id="L41" class="LineNr"> 41 </span> 57/push-EDI -<span id="L42" class="LineNr"> 42 </span> -<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># pseudocode:</span> -<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># initialize n = b.length</span> -<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># initialize s1 = s</span> -<span id="L46" class="LineNr"> 46 </span> <span class="Comment"># initialize s2 = b.data</span> -<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># i = 0</span> -<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># for (i = 0; i < n; ++n)</span> -<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># c1 = *s1</span> -<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># c2 = *s2</span> -<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># if c1 == 0</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># return false</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># if c1 != c2</span> -<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># return false</span> -<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># return *s1 == 0</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Comment">#</span> -<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># initialize s into EDI</span> -<span id="L58" class="LineNr"> 58 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># initialize benchmark length n into EDX</span> -<span id="L60" class="LineNr"> 60 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> -<span id="L61" class="LineNr"> 61 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> -<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># initialize benchmark data into ESI</span> -<span id="L63" class="LineNr"> 63 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> -<span id="L64" class="LineNr"> 64 </span> 81 0/subop/add 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESI</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Comment"># initialize loop counter i into ECX</span> -<span id="L66" class="LineNr"> 66 </span> b9/copy-to-ECX 0/imm32/exit -<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># while (i/ECX < n/EDX)</span> -<span id="L68" class="LineNr"> 68 </span>$kernel-string-equal:loop: -<span id="L69" class="LineNr"> 69 </span> 39/compare 3/mod/direct 1/rm32/ECX <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"># compare ECX with EDX</span> -<span id="L70" class="LineNr"> 70 </span> 74/jump-if-equal $kernel-string-equal:break/disp8 -<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># c1/EAX, c2/EBX = *s, *benchmark</span> -<span id="L72" class="LineNr"> 72 </span> b8/copy-to-EAX 0/imm32 -<span id="L73" class="LineNr"> 73 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> -<span id="L74" class="LineNr"> 74 </span> bb/copy-to-EBX 0/imm32 -<span id="L75" class="LineNr"> 75 </span> 8a/copy 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *ESI to lower byte of EBX</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Comment"># if (c1 == 0) return false</span> -<span id="L77" class="LineNr"> 77 </span> 3d/compare-EAX 0/imm32 -<span id="L78" class="LineNr"> 78 </span> 74/jump-if-equal $kernel-string-equal:false/disp8 -<span id="L79" class="LineNr"> 79 </span> <span class="Comment"># if (c1 != c2) return false</span> -<span id="L80" class="LineNr"> 80 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with EBX</span> -<span id="L81" class="LineNr"> 81 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 -<span id="L82" class="LineNr"> 82 </span> <span class="Comment"># ++s1, ++s2, ++i</span> -<span id="L83" class="LineNr"> 83 </span> 41/inc-ECX -<span id="L84" class="LineNr"> 84 </span> 46/inc-ESI -<span id="L85" class="LineNr"> 85 </span> 47/inc-EDI -<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># end while</span> -<span id="L87" class="LineNr"> 87 </span> eb/jump $kernel-string-equal:loop/disp8 -<span id="L88" class="LineNr"> 88 </span>$kernel-string-equal:break: -<span id="L89" class="LineNr"> 89 </span> <span class="Comment"># if (*s/EDI == 0) return true</span> -<span id="L90" class="LineNr"> 90 </span> b8/copy-to-EAX 0/imm32 -<span id="L91" class="LineNr"> 91 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> -<span id="L92" class="LineNr"> 92 </span> 3d/compare-EAX 0/imm32 -<span id="L93" class="LineNr"> 93 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 -<span id="L94" class="LineNr"> 94 </span>$kernel-string-equal:true: -<span id="L95" class="LineNr"> 95 </span> b8/copy-to-EAX 1/imm32 -<span id="L96" class="LineNr"> 96 </span> eb/jump $kernel-string-equal:end/disp8 -<span id="L97" class="LineNr"> 97 </span> <span class="Comment"># return false</span> -<span id="L98" class="LineNr"> 98 </span>$kernel-string-equal:false: -<span id="L99" class="LineNr"> 99 </span> b8/copy-to-EAX 0/imm32 -<span id="L100" class="LineNr">100 </span> -<span id="L101" class="LineNr">101 </span>$kernel-string-equal:end: -<span id="L102" class="LineNr">102 </span> <span class="Comment"># restore registers</span> -<span id="L103" class="LineNr">103 </span> 5f/pop-to-EDI -<span id="L104" class="LineNr">104 </span> 5e/pop-to-ESI -<span id="L105" class="LineNr">105 </span> 5b/pop-to-EBX -<span id="L106" class="LineNr">106 </span> 5a/pop-to-EDX -<span id="L107" class="LineNr">107 </span> 59/pop-to-ECX -<span id="L108" class="LineNr">108 </span> <span class="Comment"># epilog</span> -<span id="L109" class="LineNr">109 </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="L110" class="LineNr">110 </span> 5d/pop-to-EBP -<span id="L111" class="LineNr">111 </span> c3/return -<span id="L112" class="LineNr">112 </span> -<span id="L113" class="LineNr">113 </span><span class="SalientComment">## tests</span> -<span id="L114" class="LineNr">114 </span> -<span id="L115" class="LineNr">115 </span>test-compare-null-kernel-string-with-empty-array: -<span id="L116" class="LineNr">116 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "")</span> -<span id="L117" class="LineNr">117 </span> <span class="Comment"># push args</span> -<span id="L118" class="LineNr">118 </span> 68/push ""/imm32 -<span id="L119" class="LineNr">119 </span> 68/push Null-kernel-string/imm32 -<span id="L120" class="LineNr">120 </span> <span class="Comment"># call</span> -<span id="L121" class="LineNr">121 </span> e8/call kernel-string-equal/disp32 -<span id="L122" class="LineNr">122 </span> <span class="Comment"># discard args</span> -<span id="L123" class="LineNr">123 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L124" class="LineNr">124 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> -<span id="L125" class="LineNr">125 </span> <span class="Comment"># push args</span> -<span id="L126" class="LineNr">126 </span> 68/push "F - test-compare-null-kernel-string-with-empty-array"/imm32 -<span id="L127" class="LineNr">127 </span> 68/push 1/imm32/true -<span id="L128" class="LineNr">128 </span> 50/push-EAX -<span id="L129" class="LineNr">129 </span> <span class="Comment"># call</span> -<span id="L130" class="LineNr">130 </span> e8/call check-ints-equal/disp32 -<span id="L131" class="LineNr">131 </span> <span class="Comment"># discard args</span> -<span id="L132" class="LineNr">132 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L133" class="LineNr">133 </span> c3/return -<span id="L134" class="LineNr">134 </span> -<span id="L135" class="LineNr">135 </span>test-compare-null-kernel-string-with-non-empty-array: -<span id="L136" class="LineNr">136 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "Abc")</span> -<span id="L137" class="LineNr">137 </span> <span class="Comment"># push args</span> -<span id="L138" class="LineNr">138 </span> 68/push "Abc"/imm32 -<span id="L139" class="LineNr">139 </span> 68/push Null-kernel-string/imm32 -<span id="L140" class="LineNr">140 </span> <span class="Comment"># call</span> -<span id="L141" class="LineNr">141 </span> e8/call kernel-string-equal/disp32 -<span id="L142" class="LineNr">142 </span> <span class="Comment"># discard args</span> -<span id="L143" class="LineNr">143 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L144" class="LineNr">144 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> -<span id="L145" class="LineNr">145 </span> <span class="Comment"># push args</span> -<span id="L146" class="LineNr">146 </span> 68/push "F - test-compare-null-kernel-string-with-non-empty-array"/imm32 -<span id="L147" class="LineNr">147 </span> 68/push 0/imm32/false -<span id="L148" class="LineNr">148 </span> 50/push-EAX -<span id="L149" class="LineNr">149 </span> <span class="Comment"># call</span> -<span id="L150" class="LineNr">150 </span> e8/call check-ints-equal/disp32 -<span id="L151" class="LineNr">151 </span> <span class="Comment"># discard args</span> -<span id="L152" class="LineNr">152 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L153" class="LineNr">153 </span> c3/return -<span id="L154" class="LineNr">154 </span> -<span id="L155" class="LineNr">155 </span>test-compare-kernel-string-with-equal-array: -<span id="L156" class="LineNr">156 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abc")</span> -<span id="L157" class="LineNr">157 </span> <span class="Comment"># push args</span> -<span id="L158" class="LineNr">158 </span> 68/push "Abc"/imm32 -<span id="L159" class="LineNr">159 </span> 68/push Abc-kernel-string/imm32 -<span id="L160" class="LineNr">160 </span> <span class="Comment"># call</span> -<span id="L161" class="LineNr">161 </span> e8/call kernel-string-equal/disp32 -<span id="L162" class="LineNr">162 </span> <span class="Comment"># discard args</span> -<span id="L163" class="LineNr">163 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L164" class="LineNr">164 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> -<span id="L165" class="LineNr">165 </span> <span class="Comment"># push args</span> -<span id="L166" class="LineNr">166 </span> 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 -<span id="L167" class="LineNr">167 </span> 68/push 1/imm32/true -<span id="L168" class="LineNr">168 </span> 50/push-EAX -<span id="L169" class="LineNr">169 </span> <span class="Comment"># call</span> -<span id="L170" class="LineNr">170 </span> e8/call check-ints-equal/disp32 -<span id="L171" class="LineNr">171 </span> <span class="Comment"># discard args</span> -<span id="L172" class="LineNr">172 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L173" class="LineNr">173 </span> c3/return -<span id="L174" class="LineNr">174 </span> -<span id="L175" class="LineNr">175 </span>test-compare-kernel-string-with-inequal-array: -<span id="L176" class="LineNr">176 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Adc")</span> -<span id="L177" class="LineNr">177 </span> <span class="Comment"># push args</span> -<span id="L178" class="LineNr">178 </span> 68/push "Adc"/imm32 -<span id="L179" class="LineNr">179 </span> 68/push Abc-kernel-string/imm32 -<span id="L180" class="LineNr">180 </span> <span class="Comment"># call</span> -<span id="L181" class="LineNr">181 </span> e8/call kernel-string-equal/disp32 -<span id="L182" class="LineNr">182 </span> <span class="Comment"># discard args</span> -<span id="L183" class="LineNr">183 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L184" class="LineNr">184 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> -<span id="L185" class="LineNr">185 </span> <span class="Comment"># push args</span> -<span id="L186" class="LineNr">186 </span> 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 -<span id="L187" class="LineNr">187 </span> 68/push 0/imm32/false -<span id="L188" class="LineNr">188 </span> 50/push-EAX -<span id="L189" class="LineNr">189 </span> <span class="Comment"># call</span> -<span id="L190" class="LineNr">190 </span> e8/call check-ints-equal/disp32 -<span id="L191" class="LineNr">191 </span> <span class="Comment"># discard args</span> -<span id="L192" class="LineNr">192 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L193" class="LineNr">193 </span> c3/return -<span id="L194" class="LineNr">194 </span> -<span id="L195" class="LineNr">195 </span>test-compare-kernel-string-with-empty-array: -<span id="L196" class="LineNr">196 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "")</span> -<span id="L197" class="LineNr">197 </span> <span class="Comment"># push args</span> -<span id="L198" class="LineNr">198 </span> 68/push ""/imm32 -<span id="L199" class="LineNr">199 </span> 68/push Abc-kernel-string/imm32 -<span id="L200" class="LineNr">200 </span> <span class="Comment"># call</span> -<span id="L201" class="LineNr">201 </span> e8/call kernel-string-equal/disp32 -<span id="L202" class="LineNr">202 </span> <span class="Comment"># discard args</span> -<span id="L203" class="LineNr">203 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L204" class="LineNr">204 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> -<span id="L205" class="LineNr">205 </span> <span class="Comment"># push args</span> -<span id="L206" class="LineNr">206 </span> 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 -<span id="L207" class="LineNr">207 </span> 68/push 0/imm32/false -<span id="L208" class="LineNr">208 </span> 50/push-EAX -<span id="L209" class="LineNr">209 </span> <span class="Comment"># call</span> -<span id="L210" class="LineNr">210 </span> e8/call check-ints-equal/disp32 -<span id="L211" class="LineNr">211 </span> <span class="Comment"># discard args</span> -<span id="L212" class="LineNr">212 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L213" class="LineNr">213 </span> c3/return -<span id="L214" class="LineNr">214 </span> -<span id="L215" class="LineNr">215 </span>test-compare-kernel-string-with-shorter-array: -<span id="L216" class="LineNr">216 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Ab")</span> -<span id="L217" class="LineNr">217 </span> <span class="Comment"># push args</span> -<span id="L218" class="LineNr">218 </span> 68/push "Ab"/imm32 -<span id="L219" class="LineNr">219 </span> 68/push Abc-kernel-string/imm32 -<span id="L220" class="LineNr">220 </span> <span class="Comment"># call</span> -<span id="L221" class="LineNr">221 </span> e8/call kernel-string-equal/disp32 -<span id="L222" class="LineNr">222 </span> <span class="Comment"># discard args</span> -<span id="L223" class="LineNr">223 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L224" class="LineNr">224 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> -<span id="L225" class="LineNr">225 </span> <span class="Comment"># push args</span> -<span id="L226" class="LineNr">226 </span> 68/push "F - test-compare-kernel-string-with-shorter-array"/imm32 -<span id="L227" class="LineNr">227 </span> 68/push 0/imm32/false -<span id="L228" class="LineNr">228 </span> 50/push-EAX -<span id="L229" class="LineNr">229 </span> <span class="Comment"># call</span> -<span id="L230" class="LineNr">230 </span> e8/call check-ints-equal/disp32 -<span id="L231" class="LineNr">231 </span> <span class="Comment"># discard args</span> -<span id="L232" class="LineNr">232 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L233" class="LineNr">233 </span> c3/return -<span id="L234" class="LineNr">234 </span> -<span id="L235" class="LineNr">235 </span>test-compare-kernel-string-with-longer-array: -<span id="L236" class="LineNr">236 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abcd")</span> -<span id="L237" class="LineNr">237 </span> <span class="Comment"># push args</span> -<span id="L238" class="LineNr">238 </span> 68/push "Abcd"/imm32 -<span id="L239" class="LineNr">239 </span> 68/push Abc-kernel-string/imm32 -<span id="L240" class="LineNr">240 </span> <span class="Comment"># call</span> -<span id="L241" class="LineNr">241 </span> e8/call kernel-string-equal/disp32 -<span id="L242" class="LineNr">242 </span> <span class="Comment"># discard args</span> -<span id="L243" class="LineNr">243 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L244" class="LineNr">244 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> -<span id="L245" class="LineNr">245 </span> <span class="Comment"># push args</span> -<span id="L246" class="LineNr">246 </span> 68/push "F - test-compare-kernel-string-with-longer-array"/imm32 -<span id="L247" class="LineNr">247 </span> 68/push 0/imm32/false -<span id="L248" class="LineNr">248 </span> 50/push-EAX -<span id="L249" class="LineNr">249 </span> <span class="Comment"># call</span> -<span id="L250" class="LineNr">250 </span> e8/call check-ints-equal/disp32 -<span id="L251" class="LineNr">251 </span> <span class="Comment"># discard args</span> -<span id="L252" class="LineNr">252 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L253" class="LineNr">253 </span> c3/return -<span id="L254" class="LineNr">254 </span> -<span id="L255" class="LineNr">255 </span>== data -<span id="L256" class="LineNr">256 </span> -<span id="L257" class="LineNr">257 </span>Null-kernel-string: -<span id="L258" class="LineNr">258 </span> 00/null -<span id="L259" class="LineNr">259 </span>Abc-kernel-string: -<span id="L260" class="LineNr">260 </span> 41/A 62/b 63/c 00/null -<span id="L261" class="LineNr">261 </span> -<span id="L262" class="LineNr">262 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L18" class="LineNr"> 18 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L20" class="LineNr"> 20 </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> +<span id="L21" class="LineNr"> 21 </span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment"># main:</span> +<span id="L23" class="LineNr"> 23 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># exit(Num-test-failures)</span> +<span id="L25" class="LineNr"> 25 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L26" class="LineNr"> 26 </span> b8/copy-to-EAX 1/imm32 +<span id="L27" class="LineNr"> 27 </span> cd/syscall 0x80/imm8 +<span id="L28" class="LineNr"> 28 </span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment"># compare a null-terminated ascii string with a more idiomatic length-prefixed byte array</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment"># reason for the name: the only place we should have null-terminated ascii strings is from commandline args</span> +<span id="L31" class="LineNr"> 31 </span>kernel-string-equal: <span class="Comment"># s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Comment"># prolog</span> +<span id="L33" class="LineNr"> 33 </span> 55/push-EBP +<span id="L34" class="LineNr"> 34 </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="L35" class="LineNr"> 35 </span> <span class="Comment"># save registers</span> +<span id="L36" class="LineNr"> 36 </span> 51/push-ECX +<span id="L37" class="LineNr"> 37 </span> 52/push-EDX +<span id="L38" class="LineNr"> 38 </span> 53/push-EBX +<span id="L39" class="LineNr"> 39 </span> 56/push-ESI +<span id="L40" class="LineNr"> 40 </span> 57/push-EDI +<span id="L41" class="LineNr"> 41 </span> +<span id="L42" class="LineNr"> 42 </span> <span class="Comment"># pseudocode:</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># initialize n = b.length</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># initialize s1 = s</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># initialize s2 = b.data</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment"># i = 0</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># for (i = 0; i < n; ++n)</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># c1 = *s1</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># c2 = *s2</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># if c1 == 0</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># return false</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># if c1 != c2</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># return false</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># return *s1 == 0</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Comment">#</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># initialize s into EDI</span> +<span id="L57" class="LineNr"> 57 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># initialize benchmark length n into EDX</span> +<span id="L59" class="LineNr"> 59 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> +<span id="L60" class="LineNr"> 60 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># initialize benchmark data into ESI</span> +<span id="L62" class="LineNr"> 62 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> +<span id="L63" class="LineNr"> 63 </span> 81 0/subop/add 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESI</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># initialize loop counter i into ECX</span> +<span id="L65" class="LineNr"> 65 </span> b9/copy-to-ECX 0/imm32/exit +<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># while (i/ECX < n/EDX)</span> +<span id="L67" class="LineNr"> 67 </span>$kernel-string-equal:loop: +<span id="L68" class="LineNr"> 68 </span> 39/compare 3/mod/direct 1/rm32/ECX <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"># compare ECX with EDX</span> +<span id="L69" class="LineNr"> 69 </span> 74/jump-if-equal $kernel-string-equal:break/disp8 +<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># c1/EAX, c2/EBX = *s, *benchmark</span> +<span id="L71" class="LineNr"> 71 </span> b8/copy-to-EAX 0/imm32 +<span id="L72" class="LineNr"> 72 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> +<span id="L73" class="LineNr"> 73 </span> bb/copy-to-EBX 0/imm32 +<span id="L74" class="LineNr"> 74 </span> 8a/copy 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *ESI to lower byte of EBX</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Comment"># if (c1 == 0) return false</span> +<span id="L76" class="LineNr"> 76 </span> 3d/compare-EAX 0/imm32 +<span id="L77" class="LineNr"> 77 </span> 74/jump-if-equal $kernel-string-equal:false/disp8 +<span id="L78" class="LineNr"> 78 </span> <span class="Comment"># if (c1 != c2) return false</span> +<span id="L79" class="LineNr"> 79 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with EBX</span> +<span id="L80" class="LineNr"> 80 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 +<span id="L81" class="LineNr"> 81 </span> <span class="Comment"># ++s1, ++s2, ++i</span> +<span id="L82" class="LineNr"> 82 </span> 41/inc-ECX +<span id="L83" class="LineNr"> 83 </span> 46/inc-ESI +<span id="L84" class="LineNr"> 84 </span> 47/inc-EDI +<span id="L85" class="LineNr"> 85 </span> <span class="Comment"># end while</span> +<span id="L86" class="LineNr"> 86 </span> eb/jump $kernel-string-equal:loop/disp8 +<span id="L87" class="LineNr"> 87 </span>$kernel-string-equal:break: +<span id="L88" class="LineNr"> 88 </span> <span class="Comment"># if (*s/EDI == 0) return true</span> +<span id="L89" class="LineNr"> 89 </span> b8/copy-to-EAX 0/imm32 +<span id="L90" class="LineNr"> 90 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> +<span id="L91" class="LineNr"> 91 </span> 3d/compare-EAX 0/imm32 +<span id="L92" class="LineNr"> 92 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 +<span id="L93" class="LineNr"> 93 </span>$kernel-string-equal:true: +<span id="L94" class="LineNr"> 94 </span> b8/copy-to-EAX 1/imm32 +<span id="L95" class="LineNr"> 95 </span> eb/jump $kernel-string-equal:end/disp8 +<span id="L96" class="LineNr"> 96 </span> <span class="Comment"># return false</span> +<span id="L97" class="LineNr"> 97 </span>$kernel-string-equal:false: +<span id="L98" class="LineNr"> 98 </span> b8/copy-to-EAX 0/imm32 +<span id="L99" class="LineNr"> 99 </span> +<span id="L100" class="LineNr">100 </span>$kernel-string-equal:end: +<span id="L101" class="LineNr">101 </span> <span class="Comment"># restore registers</span> +<span id="L102" class="LineNr">102 </span> 5f/pop-to-EDI +<span id="L103" class="LineNr">103 </span> 5e/pop-to-ESI +<span id="L104" class="LineNr">104 </span> 5b/pop-to-EBX +<span id="L105" class="LineNr">105 </span> 5a/pop-to-EDX +<span id="L106" class="LineNr">106 </span> 59/pop-to-ECX +<span id="L107" class="LineNr">107 </span> <span class="Comment"># epilog</span> +<span id="L108" class="LineNr">108 </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="L109" class="LineNr">109 </span> 5d/pop-to-EBP +<span id="L110" class="LineNr">110 </span> c3/return +<span id="L111" class="LineNr">111 </span> +<span id="L112" class="LineNr">112 </span><span class="SalientComment">## tests</span> +<span id="L113" class="LineNr">113 </span> +<span id="L114" class="LineNr">114 </span>test-compare-null-kernel-string-with-empty-array: +<span id="L115" class="LineNr">115 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "")</span> +<span id="L116" class="LineNr">116 </span> <span class="Comment"># push args</span> +<span id="L117" class="LineNr">117 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L118" class="LineNr">118 </span> 68/push <span class="Special">Null-kernel-string</span>/imm32 +<span id="L119" class="LineNr">119 </span> <span class="Comment"># call</span> +<span id="L120" class="LineNr">120 </span> e8/call kernel-string-equal/disp32 +<span id="L121" class="LineNr">121 </span> <span class="Comment"># discard args</span> +<span id="L122" class="LineNr">122 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L123" class="LineNr">123 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> +<span id="L124" class="LineNr">124 </span> <span class="Comment"># push args</span> +<span id="L125" class="LineNr">125 </span> 68/push <span class="Constant">"F - test-compare-null-kernel-string-with-empty-array"</span>/imm32 +<span id="L126" class="LineNr">126 </span> 68/push 1/imm32/true +<span id="L127" class="LineNr">127 </span> 50/push-EAX +<span id="L128" class="LineNr">128 </span> <span class="Comment"># call</span> +<span id="L129" class="LineNr">129 </span> e8/call check-ints-equal/disp32 +<span id="L130" class="LineNr">130 </span> <span class="Comment"># discard args</span> +<span id="L131" class="LineNr">131 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L132" class="LineNr">132 </span> c3/return +<span id="L133" class="LineNr">133 </span> +<span id="L134" class="LineNr">134 </span>test-compare-null-kernel-string-with-non-empty-array: +<span id="L135" class="LineNr">135 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "Abc")</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment"># push args</span> +<span id="L137" class="LineNr">137 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L138" class="LineNr">138 </span> 68/push <span class="Special">Null-kernel-string</span>/imm32 +<span id="L139" class="LineNr">139 </span> <span class="Comment"># call</span> +<span id="L140" class="LineNr">140 </span> e8/call kernel-string-equal/disp32 +<span id="L141" class="LineNr">141 </span> <span class="Comment"># discard args</span> +<span id="L142" class="LineNr">142 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> +<span id="L144" class="LineNr">144 </span> <span class="Comment"># push args</span> +<span id="L145" class="LineNr">145 </span> 68/push <span class="Constant">"F - test-compare-null-kernel-string-with-non-empty-array"</span>/imm32 +<span id="L146" class="LineNr">146 </span> 68/push 0/imm32/false +<span id="L147" class="LineNr">147 </span> 50/push-EAX +<span id="L148" class="LineNr">148 </span> <span class="Comment"># call</span> +<span id="L149" class="LineNr">149 </span> e8/call check-ints-equal/disp32 +<span id="L150" class="LineNr">150 </span> <span class="Comment"># discard args</span> +<span id="L151" class="LineNr">151 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L152" class="LineNr">152 </span> c3/return +<span id="L153" class="LineNr">153 </span> +<span id="L154" class="LineNr">154 </span>test-compare-kernel-string-with-equal-array: +<span id="L155" class="LineNr">155 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abc")</span> +<span id="L156" class="LineNr">156 </span> <span class="Comment"># push args</span> +<span id="L157" class="LineNr">157 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L158" class="LineNr">158 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L159" class="LineNr">159 </span> <span class="Comment"># call</span> +<span id="L160" class="LineNr">160 </span> e8/call kernel-string-equal/disp32 +<span id="L161" class="LineNr">161 </span> <span class="Comment"># discard args</span> +<span id="L162" class="LineNr">162 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> +<span id="L164" class="LineNr">164 </span> <span class="Comment"># push args</span> +<span id="L165" class="LineNr">165 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-equal-array"</span>/imm32 +<span id="L166" class="LineNr">166 </span> 68/push 1/imm32/true +<span id="L167" class="LineNr">167 </span> 50/push-EAX +<span id="L168" class="LineNr">168 </span> <span class="Comment"># call</span> +<span id="L169" class="LineNr">169 </span> e8/call check-ints-equal/disp32 +<span id="L170" class="LineNr">170 </span> <span class="Comment"># discard args</span> +<span id="L171" class="LineNr">171 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L172" class="LineNr">172 </span> c3/return +<span id="L173" class="LineNr">173 </span> +<span id="L174" class="LineNr">174 </span>test-compare-kernel-string-with-inequal-array: +<span id="L175" class="LineNr">175 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Adc")</span> +<span id="L176" class="LineNr">176 </span> <span class="Comment"># push args</span> +<span id="L177" class="LineNr">177 </span> 68/push <span class="Constant">"Adc"</span>/imm32 +<span id="L178" class="LineNr">178 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L179" class="LineNr">179 </span> <span class="Comment"># call</span> +<span id="L180" class="LineNr">180 </span> e8/call kernel-string-equal/disp32 +<span id="L181" class="LineNr">181 </span> <span class="Comment"># discard args</span> +<span id="L182" class="LineNr">182 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L183" class="LineNr">183 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> +<span id="L184" class="LineNr">184 </span> <span class="Comment"># push args</span> +<span id="L185" class="LineNr">185 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-equal-array"</span>/imm32 +<span id="L186" class="LineNr">186 </span> 68/push 0/imm32/false +<span id="L187" class="LineNr">187 </span> 50/push-EAX +<span id="L188" class="LineNr">188 </span> <span class="Comment"># call</span> +<span id="L189" class="LineNr">189 </span> e8/call check-ints-equal/disp32 +<span id="L190" class="LineNr">190 </span> <span class="Comment"># discard args</span> +<span id="L191" class="LineNr">191 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L192" class="LineNr">192 </span> c3/return +<span id="L193" class="LineNr">193 </span> +<span id="L194" class="LineNr">194 </span>test-compare-kernel-string-with-empty-array: +<span id="L195" class="LineNr">195 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "")</span> +<span id="L196" class="LineNr">196 </span> <span class="Comment"># push args</span> +<span id="L197" class="LineNr">197 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L198" class="LineNr">198 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L199" class="LineNr">199 </span> <span class="Comment"># call</span> +<span id="L200" class="LineNr">200 </span> e8/call kernel-string-equal/disp32 +<span id="L201" class="LineNr">201 </span> <span class="Comment"># discard args</span> +<span id="L202" class="LineNr">202 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L203" class="LineNr">203 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> +<span id="L204" class="LineNr">204 </span> <span class="Comment"># push args</span> +<span id="L205" class="LineNr">205 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-equal-array"</span>/imm32 +<span id="L206" class="LineNr">206 </span> 68/push 0/imm32/false +<span id="L207" class="LineNr">207 </span> 50/push-EAX +<span id="L208" class="LineNr">208 </span> <span class="Comment"># call</span> +<span id="L209" class="LineNr">209 </span> e8/call check-ints-equal/disp32 +<span id="L210" class="LineNr">210 </span> <span class="Comment"># discard args</span> +<span id="L211" class="LineNr">211 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L212" class="LineNr">212 </span> c3/return +<span id="L213" class="LineNr">213 </span> +<span id="L214" class="LineNr">214 </span>test-compare-kernel-string-with-shorter-array: +<span id="L215" class="LineNr">215 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Ab")</span> +<span id="L216" class="LineNr">216 </span> <span class="Comment"># push args</span> +<span id="L217" class="LineNr">217 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L218" class="LineNr">218 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L219" class="LineNr">219 </span> <span class="Comment"># call</span> +<span id="L220" class="LineNr">220 </span> e8/call kernel-string-equal/disp32 +<span id="L221" class="LineNr">221 </span> <span class="Comment"># discard args</span> +<span id="L222" class="LineNr">222 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L223" class="LineNr">223 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> +<span id="L224" class="LineNr">224 </span> <span class="Comment"># push args</span> +<span id="L225" class="LineNr">225 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-shorter-array"</span>/imm32 +<span id="L226" class="LineNr">226 </span> 68/push 0/imm32/false +<span id="L227" class="LineNr">227 </span> 50/push-EAX +<span id="L228" class="LineNr">228 </span> <span class="Comment"># call</span> +<span id="L229" class="LineNr">229 </span> e8/call check-ints-equal/disp32 +<span id="L230" class="LineNr">230 </span> <span class="Comment"># discard args</span> +<span id="L231" class="LineNr">231 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L232" class="LineNr">232 </span> c3/return +<span id="L233" class="LineNr">233 </span> +<span id="L234" class="LineNr">234 </span>test-compare-kernel-string-with-longer-array: +<span id="L235" class="LineNr">235 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abcd")</span> +<span id="L236" class="LineNr">236 </span> <span class="Comment"># push args</span> +<span id="L237" class="LineNr">237 </span> 68/push <span class="Constant">"Abcd"</span>/imm32 +<span id="L238" class="LineNr">238 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L239" class="LineNr">239 </span> <span class="Comment"># call</span> +<span id="L240" class="LineNr">240 </span> e8/call kernel-string-equal/disp32 +<span id="L241" class="LineNr">241 </span> <span class="Comment"># discard args</span> +<span id="L242" class="LineNr">242 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L243" class="LineNr">243 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> +<span id="L244" class="LineNr">244 </span> <span class="Comment"># push args</span> +<span id="L245" class="LineNr">245 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-longer-array"</span>/imm32 +<span id="L246" class="LineNr">246 </span> 68/push 0/imm32/false +<span id="L247" class="LineNr">247 </span> 50/push-EAX +<span id="L248" class="LineNr">248 </span> <span class="Comment"># call</span> +<span id="L249" class="LineNr">249 </span> e8/call check-ints-equal/disp32 +<span id="L250" class="LineNr">250 </span> <span class="Comment"># discard args</span> +<span id="L251" class="LineNr">251 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L252" class="LineNr">252 </span> c3/return +<span id="L253" class="LineNr">253 </span> +<span id="L254" class="LineNr">254 </span>== data +<span id="L255" class="LineNr">255 </span> +<span id="L256" class="LineNr">256 </span><span class="Special">Null-kernel-string</span>: +<span id="L257" class="LineNr">257 </span> 00/null +<span id="L258" class="LineNr">258 </span><span class="Special">Abc-kernel-string</span>: +<span id="L259" class="LineNr">259 </span> 41/<span class="Special">A</span> 62/b 63/c 00/null +<span id="L260" class="LineNr">260 </span> +<span id="L261" class="LineNr">261 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/053new_segment.subx.html b/html/subx/053new_segment.subx.html index 81d31ac9..a36b1738 100644 --- a/html/subx/053new_segment.subx.html +++ b/html/subx/053new_segment.subx.html @@ -56,49 +56,49 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment"># Create a new segment (for data) using mmap().</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span>== code -<span id="L4" class="LineNr"> 4 </span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L7" class="LineNr"> 7 </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> -<span id="L8" class="LineNr"> 8 </span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L10" class="LineNr">10 </span> <span class="Comment"># EAX = new-segment(0x1000)</span> -<span id="L11" class="LineNr">11 </span> <span class="Comment"># push args</span> -<span id="L12" class="LineNr">12 </span> 68/push 0x1000/imm32 -<span id="L13" class="LineNr">13 </span> <span class="Comment"># call</span> -<span id="L14" class="LineNr">14 </span> e8/call new-segment/disp32 -<span id="L15" class="LineNr">15 </span> <span class="Comment"># discard args</span> -<span id="L16" class="LineNr">16 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L17" class="LineNr">17 </span> -<span id="L18" class="LineNr">18 </span> <span class="Comment"># store to *EAX</span> -<span id="L19" class="LineNr">19 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x34/imm32 <span class="Comment"># copy to *EAX</span> -<span id="L20" class="LineNr">20 </span> -<span id="L21" class="LineNr">21 </span> <span class="Comment"># exit(EAX)</span> -<span id="L22" class="LineNr">22 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> -<span id="L23" class="LineNr">23 </span> b8/copy-to-EAX 1/imm32/exit -<span id="L24" class="LineNr">24 </span> cd/syscall 0x80/imm8 -<span id="L25" class="LineNr">25 </span> -<span id="L26" class="LineNr">26 </span>new-segment: <span class="Comment"># len : int -> address</span> -<span id="L27" class="LineNr">27 </span> <span class="Comment"># prolog</span> -<span id="L28" class="LineNr">28 </span> 55/push-EBP -<span id="L29" class="LineNr">29 </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="L30" class="LineNr">30 </span> 53/push-EBX -<span id="L31" class="LineNr">31 </span> <span class="Comment"># copy len to mmap-new-segment.len</span> -<span id="L32" class="LineNr">32 </span> <span class="Comment"># TODO: compute mmap-new-segment+4 before runtime</span> -<span id="L33" class="LineNr">33 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> -<span id="L34" class="LineNr">34 </span> bb/copy-to-EBX mmap-new-segment/imm32 -<span id="L35" class="LineNr">35 </span> 89/copy 1/mod/*+disp8 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX to *(EBX+4)</span> -<span id="L36" class="LineNr">36 </span> <span class="Comment"># mmap(mmap-new-segment)</span> -<span id="L37" class="LineNr">37 </span> bb/copy-to-EBX mmap-new-segment/imm32 -<span id="L38" class="LineNr">38 </span> b8/copy-to-EAX 0x5a/imm32/mmap -<span id="L39" class="LineNr">39 </span> cd/syscall 0x80/imm8 -<span id="L40" class="LineNr">40 </span> <span class="Comment"># epilog</span> -<span id="L41" class="LineNr">41 </span> 5b/pop-to-EBX -<span id="L42" class="LineNr">42 </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="L43" class="LineNr">43 </span> 5d/pop-to-EBP -<span id="L44" class="LineNr">44 </span> c3/return -<span id="L45" class="LineNr">45 </span> -<span id="L46" class="LineNr">46 </span>== data +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L6" class="LineNr"> 6 </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> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Comment"># EAX = new-segment(0x1000)</span> +<span id="L10" class="LineNr">10 </span> <span class="Comment"># push args</span> +<span id="L11" class="LineNr">11 </span> 68/push 0x1000/imm32 +<span id="L12" class="LineNr">12 </span> <span class="Comment"># call</span> +<span id="L13" class="LineNr">13 </span> e8/call new-segment/disp32 +<span id="L14" class="LineNr">14 </span> <span class="Comment"># discard args</span> +<span id="L15" class="LineNr">15 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L16" class="LineNr">16 </span> +<span id="L17" class="LineNr">17 </span> <span class="Comment"># store to *EAX</span> +<span id="L18" class="LineNr">18 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x34/imm32 <span class="Comment"># copy to *EAX</span> +<span id="L19" class="LineNr">19 </span> +<span id="L20" class="LineNr">20 </span> <span class="Comment"># exit(EAX)</span> +<span id="L21" class="LineNr">21 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> +<span id="L22" class="LineNr">22 </span> b8/copy-to-EAX 1/imm32/exit +<span id="L23" class="LineNr">23 </span> cd/syscall 0x80/imm8 +<span id="L24" class="LineNr">24 </span> +<span id="L25" class="LineNr">25 </span>new-segment: <span class="Comment"># len : int -> address</span> +<span id="L26" class="LineNr">26 </span> <span class="Comment"># prolog</span> +<span id="L27" class="LineNr">27 </span> 55/push-EBP +<span id="L28" class="LineNr">28 </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="L29" class="LineNr">29 </span> 53/push-EBX +<span id="L30" class="LineNr">30 </span> <span class="Comment"># copy len to mmap-new-segment.len</span> +<span id="L31" class="LineNr">31 </span> <span class="Comment"># TODO: compute mmap-new-segment+4 before runtime</span> +<span id="L32" class="LineNr">32 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> +<span id="L33" class="LineNr">33 </span> bb/copy-to-EBX mmap-new-segment/imm32 +<span id="L34" class="LineNr">34 </span> 89/copy 1/mod/*+disp8 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX to *(EBX+4)</span> +<span id="L35" class="LineNr">35 </span> <span class="Comment"># mmap(mmap-new-segment)</span> +<span id="L36" class="LineNr">36 </span> bb/copy-to-EBX mmap-new-segment/imm32 +<span id="L37" class="LineNr">37 </span> b8/copy-to-EAX 0x5a/imm32/mmap +<span id="L38" class="LineNr">38 </span> cd/syscall 0x80/imm8 +<span id="L39" class="LineNr">39 </span> <span class="Comment"># epilog</span> +<span id="L40" class="LineNr">40 </span> 5b/pop-to-EBX +<span id="L41" class="LineNr">41 </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="L42" class="LineNr">42 </span> 5d/pop-to-EBP +<span id="L43" class="LineNr">43 </span> c3/return +<span id="L44" class="LineNr">44 </span> +<span id="L45" class="LineNr">45 </span>== data +<span id="L46" class="LineNr">46 </span> <span id="L47" class="LineNr">47 </span><span class="Comment"># various constants used here were found in the Linux sources (search for file mman-common.h)</span> <span id="L48" class="LineNr">48 </span>mmap-new-segment: <span class="Comment"># type mmap_arg_struct</span> <span id="L49" class="LineNr">49 </span> <span class="Comment"># addr</span> diff --git a/html/subx/054string_equal.subx.html b/html/subx/054string_equal.subx.html index 044da332..b0e53c9b 100644 --- a/html/subx/054string_equal.subx.html +++ b/html/subx/054string_equal.subx.html @@ -16,7 +16,9 @@ a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -57,173 +59,172 @@ if ('onhashchange' in window) { <span id="L1" class="LineNr"> 1 </span><span class="Comment"># Comparing 'regular' length-prefixed strings.</span> <span id="L2" class="LineNr"> 2 </span> <span id="L3" class="LineNr"> 3 </span>== code -<span id="L4" class="LineNr"> 4 </span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L7" class="LineNr"> 7 </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> -<span id="L8" class="LineNr"> 8 </span> -<span id="L9" class="LineNr"> 9 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L10" class="LineNr"> 10 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> -<span id="L11" class="LineNr"> 11 </span> <span class="Comment"># exit(Num-test-failures)</span> -<span id="L12" class="LineNr"> 12 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX Num-test-failures/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> -<span id="L13" class="LineNr"> 13 </span> b8/copy-to-EAX 1/imm32 -<span id="L14" class="LineNr"> 14 </span> cd/syscall 0x80/imm8 -<span id="L15" class="LineNr"> 15 </span> -<span id="L16" class="LineNr"> 16 </span>string-equal: <span class="Comment"># s : string, benchmark : string -> EAX : boolean</span> -<span id="L17" class="LineNr"> 17 </span> <span class="Comment"># prolog</span> -<span id="L18" class="LineNr"> 18 </span> 55/push-EBP -<span id="L19" class="LineNr"> 19 </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="L20" class="LineNr"> 20 </span> <span class="Comment"># save registers</span> -<span id="L21" class="LineNr"> 21 </span> 51/push-ECX -<span id="L22" class="LineNr"> 22 </span> 52/push-EDX -<span id="L23" class="LineNr"> 23 </span> 53/push-EBX -<span id="L24" class="LineNr"> 24 </span> 56/push-ESI -<span id="L25" class="LineNr"> 25 </span> <span class="Comment"># pseudocode:</span> -<span id="L26" class="LineNr"> 26 </span> <span class="Comment"># if s.length != b.length return false</span> -<span id="L27" class="LineNr"> 27 </span> <span class="Comment"># for i = 0; i < s.length; ++i</span> -<span id="L28" class="LineNr"> 28 </span> <span class="Comment"># if s[i] != b[i] return false</span> -<span id="L29" class="LineNr"> 29 </span> <span class="Comment"># return true</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Comment"># registers:</span> -<span id="L31" class="LineNr"> 31 </span> <span class="Comment"># i: ECX</span> -<span id="L32" class="LineNr"> 32 </span> <span class="Comment"># s.length: EDX</span> -<span id="L33" class="LineNr"> 33 </span> <span class="Comment"># b.length: EBX</span> -<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># b[i]: EBX</span> -<span id="L35" class="LineNr"> 35 </span> <span class="Comment"># s[i]: EAX</span> -<span id="L36" class="LineNr"> 36 </span> <span class="Comment">#</span> -<span id="L37" class="LineNr"> 37 </span> <span class="Comment"># var s/EAX : (address array byte)</span> -<span id="L38" class="LineNr"> 38 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> -<span id="L39" class="LineNr"> 39 </span> <span class="Comment"># var benchmark/EBX : (address array byte)</span> -<span id="L40" class="LineNr"> 40 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EBX</span> -<span id="L41" class="LineNr"> 41 </span> <span class="Comment"># if s.length != b.length return false</span> -<span id="L42" class="LineNr"> 42 </span> <span class="Comment"># EDX = s.length</span> -<span id="L43" class="LineNr"> 43 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <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 *EAX to EDX</span> -<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># compare s.length and b.length</span> -<span id="L45" class="LineNr"> 45 </span> 39/compare 0/mod/indirect 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"># compare *EBX with EDX</span> -<span id="L46" class="LineNr"> 46 </span> 75/jump-if-not-equal $string-equal:false/disp8 -<span id="L47" class="LineNr"> 47 </span>$string-equal:lengths: -<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># var i/ECX : int = 0</span> -<span id="L49" class="LineNr"> 49 </span> b9/copy-to-ECX 0/imm32 -<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># EBX = &b[i]</span> -<span id="L51" class="LineNr"> 51 </span> 43/inc-EBX -<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># EAX = &s[i]</span> -<span id="L53" class="LineNr"> 53 </span> 40/inc-EAX -<span id="L54" class="LineNr"> 54 </span>$string-equal:loop: -<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># if i >= s.length return true</span> -<span id="L56" class="LineNr"> 56 </span> 39/compare 3/mod/direct 1/rm32/ECX <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"># compare ECX with EDX</span> -<span id="L57" class="LineNr"> 57 </span> 7d/jump-if-greater-or-equal $string-equal:true/disp8 -<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># if b[i] != s[i] return false</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># ESI = s[i]</span> -<span id="L60" class="LineNr"> 60 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 6/r32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EAX to ESI</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># compare b[i] with ESI</span> -<span id="L62" class="LineNr"> 62 </span> 39/compare 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 6/r32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare *EBX with ESI</span> -<span id="L63" class="LineNr"> 63 </span> 75/jump-if-not-equal $string-equal:false/disp8 -<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># ++i</span> -<span id="L65" class="LineNr"> 65 </span> 41/inc-ECX -<span id="L66" class="LineNr"> 66 </span> 40/inc-EAX -<span id="L67" class="LineNr"> 67 </span> 43/inc-EBX -<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># loop</span> -<span id="L69" class="LineNr"> 69 </span> eb/jump $string-equal:loop/disp8 -<span id="L70" class="LineNr"> 70 </span>$string-equal:true: -<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># return true</span> -<span id="L72" class="LineNr"> 72 </span> b8/copy-to-EAX 1/imm32 -<span id="L73" class="LineNr"> 73 </span> eb/jump $string-equal:end/disp8 -<span id="L74" class="LineNr"> 74 </span>$string-equal:false: -<span id="L75" class="LineNr"> 75 </span> <span class="Comment"># return false</span> -<span id="L76" class="LineNr"> 76 </span> b8/copy-to-EAX 0/imm32 -<span id="L77" class="LineNr"> 77 </span>$string-equal:end: -<span id="L78" class="LineNr"> 78 </span> <span class="Comment"># restore registers</span> -<span id="L79" class="LineNr"> 79 </span> 5e/pop-to-ESI -<span id="L80" class="LineNr"> 80 </span> 5b/pop-to-EBX -<span id="L81" class="LineNr"> 81 </span> 5a/pop-to-EDX -<span id="L82" class="LineNr"> 82 </span> 59/pop-to-ECX -<span id="L83" class="LineNr"> 83 </span> <span class="Comment"># epilog</span> -<span id="L84" class="LineNr"> 84 </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="L85" class="LineNr"> 85 </span> 5d/pop-to-EBP -<span id="L86" class="LineNr"> 86 </span> c3/return -<span id="L87" class="LineNr"> 87 </span> -<span id="L88" class="LineNr"> 88 </span><span class="SalientComment">## tests</span> -<span id="L89" class="LineNr"> 89 </span> -<span id="L90" class="LineNr"> 90 </span>test-compare-empty-with-empty-string: -<span id="L91" class="LineNr"> 91 </span> <span class="Comment"># EAX = string-equal("", "")</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># push args</span> -<span id="L93" class="LineNr"> 93 </span> 68/push ""/imm32 -<span id="L94" class="LineNr"> 94 </span> 68/push ""/imm32 -<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># call</span> -<span id="L96" class="LineNr"> 96 </span> e8/call string-equal/disp32 -<span id="L97" class="LineNr"> 97 </span> <span class="Comment"># discard args</span> -<span id="L98" class="LineNr"> 98 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L99" class="LineNr"> 99 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> -<span id="L100" class="LineNr">100 </span> <span class="Comment"># push args</span> -<span id="L101" class="LineNr">101 </span> 68/push "F - test-compare-empty-with-empty-string"/imm32 -<span id="L102" class="LineNr">102 </span> 68/push 1/imm32/true -<span id="L103" class="LineNr">103 </span> 50/push-EAX -<span id="L104" class="LineNr">104 </span> <span class="Comment"># call</span> -<span id="L105" class="LineNr">105 </span> e8/call check-ints-equal/disp32 -<span id="L106" class="LineNr">106 </span> <span class="Comment"># discard args</span> -<span id="L107" class="LineNr">107 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L108" class="LineNr">108 </span> c3/return -<span id="L109" class="LineNr">109 </span> -<span id="L110" class="LineNr">110 </span>test-compare-empty-with-non-empty-string: <span class="Comment"># also checks length-mismatch code path</span> -<span id="L111" class="LineNr">111 </span> <span class="Comment"># EAX = string-equal("", "Abc")</span> -<span id="L112" class="LineNr">112 </span> <span class="Comment"># push args</span> -<span id="L113" class="LineNr">113 </span> 68/push "Abc"/imm32 -<span id="L114" class="LineNr">114 </span> 68/push ""/imm32 -<span id="L115" class="LineNr">115 </span> <span class="Comment"># call</span> -<span id="L116" class="LineNr">116 </span> e8/call string-equal/disp32 -<span id="L117" class="LineNr">117 </span> <span class="Comment"># discard args</span> -<span id="L118" class="LineNr">118 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L119" class="LineNr">119 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> -<span id="L120" class="LineNr">120 </span> <span class="Comment"># push args</span> -<span id="L121" class="LineNr">121 </span> 68/push "F - test-compare-empty-with-non-empty-string"/imm32 -<span id="L122" class="LineNr">122 </span> 68/push 0/imm32/false -<span id="L123" class="LineNr">123 </span> 50/push-EAX -<span id="L124" class="LineNr">124 </span> <span class="Comment"># call</span> -<span id="L125" class="LineNr">125 </span> e8/call check-ints-equal/disp32 -<span id="L126" class="LineNr">126 </span> <span class="Comment"># discard args</span> -<span id="L127" class="LineNr">127 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L128" class="LineNr">128 </span> c3/return -<span id="L129" class="LineNr">129 </span> -<span id="L130" class="LineNr">130 </span>test-compare-equal-strings: -<span id="L131" class="LineNr">131 </span> <span class="Comment"># EAX = string-equal("Abc", "Abc")</span> -<span id="L132" class="LineNr">132 </span> <span class="Comment"># push args</span> -<span id="L133" class="LineNr">133 </span> 68/push "Abc"/imm32 -<span id="L134" class="LineNr">134 </span> 68/push "Abc"/imm32 -<span id="L135" class="LineNr">135 </span> <span class="Comment"># call</span> -<span id="L136" class="LineNr">136 </span> e8/call string-equal/disp32 -<span id="L137" class="LineNr">137 </span> <span class="Comment"># discard args</span> -<span id="L138" class="LineNr">138 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L139" class="LineNr">139 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> -<span id="L140" class="LineNr">140 </span> <span class="Comment"># push args</span> -<span id="L141" class="LineNr">141 </span> 68/push "F - test-compare-equal-strings"/imm32 -<span id="L142" class="LineNr">142 </span> 68/push 1/imm32/true -<span id="L143" class="LineNr">143 </span> 50/push-EAX -<span id="L144" class="LineNr">144 </span> <span class="Comment"># call</span> -<span id="L145" class="LineNr">145 </span> e8/call check-ints-equal/disp32 -<span id="L146" class="LineNr">146 </span> <span class="Comment"># discard args</span> -<span id="L147" class="LineNr">147 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L148" class="LineNr">148 </span> c3/return -<span id="L149" class="LineNr">149 </span> -<span id="L150" class="LineNr">150 </span>test-compare-inequal-strings-equal-lengths: -<span id="L151" class="LineNr">151 </span> <span class="Comment"># EAX = string-equal("Abc", "Adc")</span> -<span id="L152" class="LineNr">152 </span> <span class="Comment"># push args</span> -<span id="L153" class="LineNr">153 </span> 68/push "Adc"/imm32 -<span id="L154" class="LineNr">154 </span> 68/push "Abc"/imm32 -<span id="L155" class="LineNr">155 </span> <span class="Comment"># call</span> -<span id="L156" class="LineNr">156 </span> e8/call string-equal/disp32 -<span id="L157" class="LineNr">157 </span> <span class="Comment"># discard args</span> -<span id="L158" class="LineNr">158 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L159" class="LineNr">159 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> -<span id="L160" class="LineNr">160 </span> <span class="Comment"># push args</span> -<span id="L161" class="LineNr">161 </span> 68/push "F - test-compare-inequal-strings-equal-lengths"/imm32 -<span id="L162" class="LineNr">162 </span> 68/push 0/imm32/false -<span id="L163" class="LineNr">163 </span> 50/push-EAX -<span id="L164" class="LineNr">164 </span> <span class="Comment"># call</span> -<span id="L165" class="LineNr">165 </span> e8/call check-ints-equal/disp32 -<span id="L166" class="LineNr">166 </span> <span class="Comment"># discard args</span> -<span id="L167" class="LineNr">167 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L168" class="LineNr">168 </span> c3/return -<span id="L169" class="LineNr">169 </span> -<span id="L170" class="LineNr">170 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L6" class="LineNr"> 6 </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> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># main:</span> +<span id="L9" class="LineNr"> 9 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L10" class="LineNr"> 10 </span> <span class="Comment"># exit(Num-test-failures)</span> +<span id="L11" class="LineNr"> 11 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L12" class="LineNr"> 12 </span> b8/copy-to-EAX 1/imm32 +<span id="L13" class="LineNr"> 13 </span> cd/syscall 0x80/imm8 +<span id="L14" class="LineNr"> 14 </span> +<span id="L15" class="LineNr"> 15 </span>string-equal: <span class="Comment"># s : string, benchmark : string -> EAX : boolean</span> +<span id="L16" class="LineNr"> 16 </span> <span class="Comment"># prolog</span> +<span id="L17" class="LineNr"> 17 </span> 55/push-EBP +<span id="L18" class="LineNr"> 18 </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="L19" class="LineNr"> 19 </span> <span class="Comment"># save registers</span> +<span id="L20" class="LineNr"> 20 </span> 51/push-ECX +<span id="L21" class="LineNr"> 21 </span> 52/push-EDX +<span id="L22" class="LineNr"> 22 </span> 53/push-EBX +<span id="L23" class="LineNr"> 23 </span> 56/push-ESI +<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># pseudocode:</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Comment"># if s.length != b.length return false</span> +<span id="L26" class="LineNr"> 26 </span> <span class="Comment"># for i = 0; i < s.length; ++i</span> +<span id="L27" class="LineNr"> 27 </span> <span class="Comment"># if s[i] != b[i] return false</span> +<span id="L28" class="LineNr"> 28 </span> <span class="Comment"># return true</span> +<span id="L29" class="LineNr"> 29 </span> <span class="Comment"># registers:</span> +<span id="L30" class="LineNr"> 30 </span> <span class="Comment"># i: ECX</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Comment"># s.length: EDX</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Comment"># b.length: EBX</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Comment"># b[i]: EBX</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># s[i]: EAX</span> +<span id="L35" class="LineNr"> 35 </span> <span class="Comment">#</span> +<span id="L36" class="LineNr"> 36 </span> <span class="Comment"># var s/EAX : (address array byte)</span> +<span id="L37" class="LineNr"> 37 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> +<span id="L38" class="LineNr"> 38 </span> <span class="Comment"># var benchmark/EBX : (address array byte)</span> +<span id="L39" class="LineNr"> 39 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EBX</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Comment"># if s.length != b.length return false</span> +<span id="L41" class="LineNr"> 41 </span> <span class="Comment"># EDX = s.length</span> +<span id="L42" class="LineNr"> 42 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <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 *EAX to EDX</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># compare s.length and b.length</span> +<span id="L44" class="LineNr"> 44 </span> 39/compare 0/mod/indirect 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"># compare *EBX with EDX</span> +<span id="L45" class="LineNr"> 45 </span> 75/jump-if-not-equal $string-equal:false/disp8 +<span id="L46" class="LineNr"> 46 </span>$string-equal:lengths: +<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># var i/ECX : int = 0</span> +<span id="L48" class="LineNr"> 48 </span> b9/copy-to-ECX 0/imm32 +<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># EBX = &b[i]</span> +<span id="L50" class="LineNr"> 50 </span> 43/inc-EBX +<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># EAX = &s[i]</span> +<span id="L52" class="LineNr"> 52 </span> 40/inc-EAX +<span id="L53" class="LineNr"> 53 </span>$string-equal:loop: +<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># if i >= s.length return true</span> +<span id="L55" class="LineNr"> 55 </span> 39/compare 3/mod/direct 1/rm32/ECX <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"># compare ECX with EDX</span> +<span id="L56" class="LineNr"> 56 </span> 7d/jump-if-greater-or-equal $string-equal:true/disp8 +<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># if b[i] != s[i] return false</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># ESI = s[i]</span> +<span id="L59" class="LineNr"> 59 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 6/r32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EAX to ESI</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># compare b[i] with ESI</span> +<span id="L61" class="LineNr"> 61 </span> 39/compare 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 6/r32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare *EBX with ESI</span> +<span id="L62" class="LineNr"> 62 </span> 75/jump-if-not-equal $string-equal:false/disp8 +<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># ++i</span> +<span id="L64" class="LineNr"> 64 </span> 41/inc-ECX +<span id="L65" class="LineNr"> 65 </span> 40/inc-EAX +<span id="L66" class="LineNr"> 66 </span> 43/inc-EBX +<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># loop</span> +<span id="L68" class="LineNr"> 68 </span> eb/jump $string-equal:loop/disp8 +<span id="L69" class="LineNr"> 69 </span>$string-equal:true: +<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># return true</span> +<span id="L71" class="LineNr"> 71 </span> b8/copy-to-EAX 1/imm32 +<span id="L72" class="LineNr"> 72 </span> eb/jump $string-equal:end/disp8 +<span id="L73" class="LineNr"> 73 </span>$string-equal:false: +<span id="L74" class="LineNr"> 74 </span> <span class="Comment"># return false</span> +<span id="L75" class="LineNr"> 75 </span> b8/copy-to-EAX 0/imm32 +<span id="L76" class="LineNr"> 76 </span>$string-equal:end: +<span id="L77" class="LineNr"> 77 </span> <span class="Comment"># restore registers</span> +<span id="L78" class="LineNr"> 78 </span> 5e/pop-to-ESI +<span id="L79" class="LineNr"> 79 </span> 5b/pop-to-EBX +<span id="L80" class="LineNr"> 80 </span> 5a/pop-to-EDX +<span id="L81" class="LineNr"> 81 </span> 59/pop-to-ECX +<span id="L82" class="LineNr"> 82 </span> <span class="Comment"># epilog</span> +<span id="L83" class="LineNr"> 83 </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="L84" class="LineNr"> 84 </span> 5d/pop-to-EBP +<span id="L85" class="LineNr"> 85 </span> c3/return +<span id="L86" class="LineNr"> 86 </span> +<span id="L87" class="LineNr"> 87 </span><span class="SalientComment">## tests</span> +<span id="L88" class="LineNr"> 88 </span> +<span id="L89" class="LineNr"> 89 </span>test-compare-empty-with-empty-string: +<span id="L90" class="LineNr"> 90 </span> <span class="Comment"># EAX = string-equal("", "")</span> +<span id="L91" class="LineNr"> 91 </span> <span class="Comment"># push args</span> +<span id="L92" class="LineNr"> 92 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L93" class="LineNr"> 93 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L94" class="LineNr"> 94 </span> <span class="Comment"># call</span> +<span id="L95" class="LineNr"> 95 </span> e8/call string-equal/disp32 +<span id="L96" class="LineNr"> 96 </span> <span class="Comment"># discard args</span> +<span id="L97" class="LineNr"> 97 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Comment"># push args</span> +<span id="L100" class="LineNr">100 </span> 68/push <span class="Constant">"F - test-compare-empty-with-empty-string"</span>/imm32 +<span id="L101" class="LineNr">101 </span> 68/push 1/imm32/true +<span id="L102" class="LineNr">102 </span> 50/push-EAX +<span id="L103" class="LineNr">103 </span> <span class="Comment"># call</span> +<span id="L104" class="LineNr">104 </span> e8/call check-ints-equal/disp32 +<span id="L105" class="LineNr">105 </span> <span class="Comment"># discard args</span> +<span id="L106" class="LineNr">106 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L107" class="LineNr">107 </span> c3/return +<span id="L108" class="LineNr">108 </span> +<span id="L109" class="LineNr">109 </span>test-compare-empty-with-non-empty-string: <span class="Comment"># also checks length-mismatch code path</span> +<span id="L110" class="LineNr">110 </span> <span class="Comment"># EAX = string-equal("", "Abc")</span> +<span id="L111" class="LineNr">111 </span> <span class="Comment"># push args</span> +<span id="L112" class="LineNr">112 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L113" class="LineNr">113 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L114" class="LineNr">114 </span> <span class="Comment"># call</span> +<span id="L115" class="LineNr">115 </span> e8/call string-equal/disp32 +<span id="L116" class="LineNr">116 </span> <span class="Comment"># discard args</span> +<span id="L117" class="LineNr">117 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L118" class="LineNr">118 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> +<span id="L119" class="LineNr">119 </span> <span class="Comment"># push args</span> +<span id="L120" class="LineNr">120 </span> 68/push <span class="Constant">"F - test-compare-empty-with-non-empty-string"</span>/imm32 +<span id="L121" class="LineNr">121 </span> 68/push 0/imm32/false +<span id="L122" class="LineNr">122 </span> 50/push-EAX +<span id="L123" class="LineNr">123 </span> <span class="Comment"># call</span> +<span id="L124" class="LineNr">124 </span> e8/call check-ints-equal/disp32 +<span id="L125" class="LineNr">125 </span> <span class="Comment"># discard args</span> +<span id="L126" class="LineNr">126 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L127" class="LineNr">127 </span> c3/return +<span id="L128" class="LineNr">128 </span> +<span id="L129" class="LineNr">129 </span>test-compare-equal-strings: +<span id="L130" class="LineNr">130 </span> <span class="Comment"># EAX = string-equal("Abc", "Abc")</span> +<span id="L131" class="LineNr">131 </span> <span class="Comment"># push args</span> +<span id="L132" class="LineNr">132 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L133" class="LineNr">133 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L134" class="LineNr">134 </span> <span class="Comment"># call</span> +<span id="L135" class="LineNr">135 </span> e8/call string-equal/disp32 +<span id="L136" class="LineNr">136 </span> <span class="Comment"># discard args</span> +<span id="L137" class="LineNr">137 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L138" class="LineNr">138 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> +<span id="L139" class="LineNr">139 </span> <span class="Comment"># push args</span> +<span id="L140" class="LineNr">140 </span> 68/push <span class="Constant">"F - test-compare-equal-strings"</span>/imm32 +<span id="L141" class="LineNr">141 </span> 68/push 1/imm32/true +<span id="L142" class="LineNr">142 </span> 50/push-EAX +<span id="L143" class="LineNr">143 </span> <span class="Comment"># call</span> +<span id="L144" class="LineNr">144 </span> e8/call check-ints-equal/disp32 +<span id="L145" class="LineNr">145 </span> <span class="Comment"># discard args</span> +<span id="L146" class="LineNr">146 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L147" class="LineNr">147 </span> c3/return +<span id="L148" class="LineNr">148 </span> +<span id="L149" class="LineNr">149 </span>test-compare-inequal-strings-equal-lengths: +<span id="L150" class="LineNr">150 </span> <span class="Comment"># EAX = string-equal("Abc", "Adc")</span> +<span id="L151" class="LineNr">151 </span> <span class="Comment"># push args</span> +<span id="L152" class="LineNr">152 </span> 68/push <span class="Constant">"Adc"</span>/imm32 +<span id="L153" class="LineNr">153 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L154" class="LineNr">154 </span> <span class="Comment"># call</span> +<span id="L155" class="LineNr">155 </span> e8/call string-equal/disp32 +<span id="L156" class="LineNr">156 </span> <span class="Comment"># discard args</span> +<span id="L157" class="LineNr">157 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L158" class="LineNr">158 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> +<span id="L159" class="LineNr">159 </span> <span class="Comment"># push args</span> +<span id="L160" class="LineNr">160 </span> 68/push <span class="Constant">"F - test-compare-inequal-strings-equal-lengths"</span>/imm32 +<span id="L161" class="LineNr">161 </span> 68/push 0/imm32/false +<span id="L162" class="LineNr">162 </span> 50/push-EAX +<span id="L163" class="LineNr">163 </span> <span class="Comment"># call</span> +<span id="L164" class="LineNr">164 </span> e8/call check-ints-equal/disp32 +<span id="L165" class="LineNr">165 </span> <span class="Comment"># discard args</span> +<span id="L166" class="LineNr">166 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L167" class="LineNr">167 </span> c3/return +<span id="L168" class="LineNr">168 </span> +<span id="L169" class="LineNr">169 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/055trace.subx.html b/html/subx/055trace.subx.html index 1719cd50..e6ff58a3 100644 --- a/html/subx/055trace.subx.html +++ b/html/subx/055trace.subx.html @@ -16,9 +16,12 @@ a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } +.SalientComment { color: #00ffff; } --> </style> @@ -53,7 +56,7 @@ if ('onhashchange' in window) { </head> <body onload='JumpToLine();'> <pre id='vimCodeElement'> -<span id="L1" class="LineNr"> 1 </span><span class="Comment"># helpers for emitting traces to a trace stream, and for tests to check the trace stream</span> +<span id="L1" class="LineNr"> 1 </span><span class="Comment"># primitives for emitting traces to a trace stream, and for tests to check the trace stream</span> <span id="L2" class="LineNr"> 2 </span><span class="Comment">#</span> <span id="L3" class="LineNr"> 3 </span><span class="Comment"># A trace stream looks like this:</span> <span id="L4" class="LineNr"> 4 </span><span class="Comment"># read : int # index that we've read until</span> @@ -77,12 +80,12 @@ if ('onhashchange' in window) { <span id="L22" class="LineNr"> 22 </span>== data <span id="L23" class="LineNr"> 23 </span> <span id="L24" class="LineNr"> 24 </span><span class="Comment"># We'll save the address of the trace segment here.</span> -<span id="L25" class="LineNr"> 25 </span>Trace-stream: +<span id="L25" class="LineNr"> 25 </span><span class="Special">Trace-stream</span>: <span id="L26" class="LineNr"> 26 </span> 00 00 00 00 <span id="L27" class="LineNr"> 27 </span> <span id="L28" class="LineNr"> 28 </span><span class="Comment"># Fake trace-stream for tests.</span> <span id="L29" class="LineNr"> 29 </span><span class="Comment"># Also illustrates the layout of the real trace-stream (segment).</span> -<span id="L30" class="LineNr"> 30 </span>Test-trace-stream: +<span id="L30" class="LineNr"> 30 </span>_test-trace-stream: <span id="L31" class="LineNr"> 31 </span> <span class="Comment"># current write index</span> <span id="L32" class="LineNr"> 32 </span> 00 00 00 00 <span id="L33" class="LineNr"> 33 </span> <span class="Comment"># current read index</span> @@ -93,35 +96,35 @@ if ('onhashchange' in window) { <span id="L38" class="LineNr"> 38 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> <span id="L39" class="LineNr"> 39 </span> <span id="L40" class="LineNr"> 40 </span>== code -<span id="L41" class="LineNr"> 41 </span> -<span id="L42" class="LineNr"> 42 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L43" class="LineNr"> 43 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L44" class="LineNr"> 44 </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> -<span id="L45" class="LineNr"> 45 </span> -<span id="L46" class="LineNr"> 46 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L47" class="LineNr"> 47 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> -<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> -<span id="L49" class="LineNr"> 49 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/EBX Num-test-failures/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> -<span id="L50" class="LineNr"> 50 </span> b8/copy-to-EAX 1/imm32 -<span id="L51" class="LineNr"> 51 </span> cd/syscall 0x80/imm8 -<span id="L52" class="LineNr"> 52 </span> -<span id="L53" class="LineNr"> 53 </span><span class="Comment"># Allocate a new segment for the trace stream, initialize its length, and save its address to Trace-stream.</span> -<span id="L54" class="LineNr"> 54 </span><span class="Comment"># The Trace-stream segment will consist of variable-length lines separated by newlines (0x0a)</span> -<span id="L55" class="LineNr"> 55 </span>initialize-trace-stream: -<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># EAX = new-segment(0x1000)</span> -<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># push args</span> -<span id="L58" class="LineNr"> 58 </span> 68/push 0x1000/imm32/N -<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># call</span> -<span id="L60" class="LineNr"> 60 </span> e8/call new-segment/disp32 -<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># discard args</span> -<span id="L62" class="LineNr"> 62 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># copy EAX to *Trace-stream</span> -<span id="L64" class="LineNr"> 64 </span> 89/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX Trace-stream/disp32 <span class="Comment"># copy EAX to *Trace-stream</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Comment"># Trace-stream.length = 0x1000/N - 12</span> -<span id="L66" class="LineNr"> 66 </span> c7 0/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 0xff4/imm32 <span class="Comment"># copy 0xff4 to *(EAX+8)</span> -<span id="L67" class="LineNr"> 67 </span> c3/return -<span id="L68" class="LineNr"> 68 </span> -<span id="L69" class="LineNr"> 69 </span><span class="Comment"># Append to the given trace stream.</span> +<span id="L41" class="LineNr"> 41 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L42" class="LineNr"> 42 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L43" class="LineNr"> 43 </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> +<span id="L44" class="LineNr"> 44 </span> +<span id="L45" class="LineNr"> 45 </span><span class="Comment"># main:</span> +<span id="L46" class="LineNr"> 46 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> +<span id="L48" class="LineNr"> 48 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L49" class="LineNr"> 49 </span> b8/copy-to-EAX 1/imm32 +<span id="L50" class="LineNr"> 50 </span> cd/syscall 0x80/imm8 +<span id="L51" class="LineNr"> 51 </span> +<span id="L52" class="LineNr"> 52 </span><span class="Comment"># Allocate a new segment for the trace stream, initialize its length, and save its address to Trace-stream.</span> +<span id="L53" class="LineNr"> 53 </span><span class="Comment"># The Trace-stream segment will consist of variable-length lines separated by newlines (0x0a)</span> +<span id="L54" class="LineNr"> 54 </span>initialize-trace-stream: +<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># EAX = new-segment(0x1000)</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># push args</span> +<span id="L57" class="LineNr"> 57 </span> 68/push 0x1000/imm32/<span class="Special">N</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># call</span> +<span id="L59" class="LineNr"> 59 </span> e8/call new-segment/disp32 +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># discard args</span> +<span id="L61" class="LineNr"> 61 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># copy EAX to *Trace-stream</span> +<span id="L63" class="LineNr"> 63 </span> 89/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX <span class="Special">Trace-stream</span>/disp32 <span class="Comment"># copy EAX to *Trace-stream</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># Trace-stream.length = 0x1000/N - 12</span> +<span id="L65" class="LineNr"> 65 </span> c7 0/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 0xff4/imm32 <span class="Comment"># copy 0xff4 to *(EAX+8)</span> +<span id="L66" class="LineNr"> 66 </span> c3/return +<span id="L67" class="LineNr"> 67 </span> +<span id="L68" class="LineNr"> 68 </span><span class="Comment"># Append a string to the given trace stream.</span> +<span id="L69" class="LineNr"> 69 </span><span class="Comment"># Silently give up if it's already full. Or truncate the string if there isn't enough room.</span> <span id="L70" class="LineNr"> 70 </span>trace: <span class="Comment"># t : (address trace-stream), line : string</span> <span id="L71" class="LineNr"> 71 </span> <span class="Comment"># prolog</span> <span id="L72" class="LineNr"> 72 </span> 55/push-EBP @@ -137,44 +140,44 @@ if ('onhashchange' in window) { <span id="L82" class="LineNr"> 82 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 7/r32/EDI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> <span id="L83" class="LineNr"> 83 </span> <span class="Comment"># ESI = line</span> <span id="L84" class="LineNr"> 84 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> -<span id="L85" class="LineNr"> 85 </span> <span class="Comment"># ECX = t.write</span> +<span id="L85" class="LineNr"> 85 </span> <span class="Comment"># ECX = t->write</span> <span id="L86" class="LineNr"> 86 </span> 8b/copy 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EDI to ECX</span> -<span id="L87" class="LineNr"> 87 </span> <span class="Comment"># EDX = t.length</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Comment"># EDX = t->length</span> <span id="L88" class="LineNr"> 88 </span> 8b/copy 1/mod/*+disp8 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 2/r32/EDX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EDI+8) to EDX</span> -<span id="L89" class="LineNr"> 89 </span> <span class="Comment"># EAX = _append(&t.data[t.write], &t.data[t.length], line)</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Comment"># EAX = _append-3(&t->data[t->write], &t->data[t->length], line)</span> <span id="L90" class="LineNr"> 90 </span> <span class="Comment"># push line</span> <span id="L91" class="LineNr"> 91 </span> 56/push-ESI -<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># push &t.data[t.length]</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># push &t->data[t->length]</span> <span id="L93" class="LineNr"> 93 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 2/index/EDX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+EDX+12 to EBX</span> <span id="L94" class="LineNr"> 94 </span> 53/push-EBX -<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># push &t.data[t.write]</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># push &t->data[t->write]</span> <span id="L96" class="LineNr"> 96 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+ECX+12 to EBX</span> <span id="L97" class="LineNr"> 97 </span> 53/push-EBX <span id="L98" class="LineNr"> 98 </span> <span class="Comment"># call</span> -<span id="L99" class="LineNr"> 99 </span> e8/call _append/disp32 +<span id="L99" class="LineNr"> 99 </span> e8/call _append-3/disp32 <span id="L100" class="LineNr">100 </span> <span class="Comment"># discard args</span> <span id="L101" class="LineNr">101 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> <span id="L102" class="LineNr">102 </span> <span class="Comment"># if EAX == 0 return</span> <span id="L103" class="LineNr">103 </span> 81 7/subop/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare EDX</span> <span id="L104" class="LineNr">104 </span> 74/jump-if-equal $trace:end/disp8 -<span id="L105" class="LineNr">105 </span> <span class="Comment"># t.write += EAX</span> +<span id="L105" class="LineNr">105 </span> <span class="Comment"># t->write += EAX</span> <span id="L106" class="LineNr">106 </span> 01/add 0/mod/indirect 7/rm32/EDI <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"># add EAX to *EDI</span> -<span id="L107" class="LineNr">107 </span> <span class="Comment"># refresh ECX = t.write</span> +<span id="L107" class="LineNr">107 </span> <span class="Comment"># refresh ECX = t->write</span> <span id="L108" class="LineNr">108 </span> 8b/copy 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EDI to ECX</span> -<span id="L109" class="LineNr">109 </span> <span class="Comment"># EAX = _append(&t.data[t.write], &t.data[t.length], line)</span> +<span id="L109" class="LineNr">109 </span> <span class="Comment"># EAX = _append-3(&t->data[t->write], &t->data[t->length], line)</span> <span id="L110" class="LineNr">110 </span> <span class="Comment"># push line</span> -<span id="L111" class="LineNr">111 </span> 68/push Newline/imm32 -<span id="L112" class="LineNr">112 </span> <span class="Comment"># push &t.data[t.length]</span> +<span id="L111" class="LineNr">111 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L112" class="LineNr">112 </span> <span class="Comment"># push &t->data[t->length]</span> <span id="L113" class="LineNr">113 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 2/index/EDX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+EDX+12 to EBX</span> <span id="L114" class="LineNr">114 </span> 53/push-EBX -<span id="L115" class="LineNr">115 </span> <span class="Comment"># push &t.data[t.write]</span> +<span id="L115" class="LineNr">115 </span> <span class="Comment"># push &t->data[t->write]</span> <span id="L116" class="LineNr">116 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+ECX+12 to EBX</span> <span id="L117" class="LineNr">117 </span> 53/push-EBX <span id="L118" class="LineNr">118 </span> <span class="Comment"># call</span> -<span id="L119" class="LineNr">119 </span> e8/call _append/disp32 +<span id="L119" class="LineNr">119 </span> e8/call _append-3/disp32 <span id="L120" class="LineNr">120 </span> <span class="Comment"># discard args</span> <span id="L121" class="LineNr">121 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L122" class="LineNr">122 </span> <span class="Comment"># t.write += EAX</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment"># t->write += EAX</span> <span id="L123" class="LineNr">123 </span> 01/add 0/mod/indirect 7/rm32/EDI <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"># add EAX to *EDI</span> <span id="L124" class="LineNr">124 </span>$trace:end: <span id="L125" class="LineNr">125 </span> <span class="Comment"># restore registers</span> @@ -189,194 +192,229 @@ if ('onhashchange' in window) { <span id="L134" class="LineNr">134 </span> 5d/pop-to-EBP <span id="L135" class="LineNr">135 </span> c3/return <span id="L136" class="LineNr">136 </span> -<span id="L137" class="LineNr">137 </span>_append: <span class="Comment"># out : address, outend : address, s : (array byte) -> num_bytes_appended/EAX</span> +<span id="L137" class="LineNr">137 </span>clear-trace-stream: <span class="Comment"># t : (address trace-stream)</span> <span id="L138" class="LineNr">138 </span> <span class="Comment"># prolog</span> <span id="L139" class="LineNr">139 </span> 55/push-EBP <span id="L140" class="LineNr">140 </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="L141" class="LineNr">141 </span> <span class="Comment"># save registers</span> -<span id="L142" class="LineNr">142 </span> 51/push-ECX -<span id="L143" class="LineNr">143 </span> 52/push-EDX -<span id="L144" class="LineNr">144 </span> 53/push-EBX -<span id="L145" class="LineNr">145 </span> 56/push-ESI -<span id="L146" class="LineNr">146 </span> 57/push-EDI -<span id="L147" class="LineNr">147 </span> <span class="Comment"># EAX/num_bytes_appended = 0</span> -<span id="L148" class="LineNr">148 </span> b8/copy-to-EAX 0/imm32 -<span id="L149" class="LineNr">149 </span> <span class="Comment"># EDI = out</span> -<span id="L150" class="LineNr">150 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 7/r32/EDI 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> -<span id="L151" class="LineNr">151 </span> <span class="Comment"># EDX = outend</span> -<span id="L152" class="LineNr">152 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> -<span id="L153" class="LineNr">153 </span> <span class="Comment"># ESI = s</span> -<span id="L154" class="LineNr">154 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 6/r32/ESI 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to ESI</span> -<span id="L155" class="LineNr">155 </span> <span class="Comment"># ECX = line.length</span> -<span id="L156" class="LineNr">156 </span> 8b/copy 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *ESI to ECX</span> -<span id="L157" class="LineNr">157 </span> <span class="Comment"># ECX/srcend = &line.data[line.length]</span> -<span id="L158" class="LineNr">158 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+ECX+4 to ECX</span> -<span id="L159" class="LineNr">159 </span> <span class="Comment"># ESI/src = &line.data[0]</span> -<span id="L160" class="LineNr">160 </span> 81 0/subop/add 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESI</span> -<span id="L161" class="LineNr">161 </span>$_append:loop: -<span id="L162" class="LineNr">162 </span> <span class="Comment"># if ESI/src >= ECX/srcend break</span> -<span id="L163" class="LineNr">163 </span> 39/compare 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare ESI with ECX</span> -<span id="L164" class="LineNr">164 </span> 7d/jump-if-greater-or-equal $_append:end/disp8 -<span id="L165" class="LineNr">165 </span> <span class="Comment"># if EDI/out >= EDX/outend break (for now silently ignore filled up trace buffer)</span> -<span id="L166" class="LineNr">166 </span> 39/compare 3/mod/direct 7/rm32/EDI <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"># compare EDI with EDX</span> -<span id="L167" class="LineNr">167 </span> 7d/jump-if-greater-or-equal $_append:end/disp8 -<span id="L168" class="LineNr">168 </span> <span class="Comment"># copy one byte from ESI/src to EDI/out</span> -<span id="L169" class="LineNr">169 </span> 8a/copy-byte 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/BL <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *ESI to BL</span> -<span id="L170" class="LineNr">170 </span> 88/copy-byte 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/BL <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at BL to *EDI</span> -<span id="L171" class="LineNr">171 </span> <span class="Comment"># updates</span> -<span id="L172" class="LineNr">172 </span> 40/increment-EAX -<span id="L173" class="LineNr">173 </span> 46/increment-ESI -<span id="L174" class="LineNr">174 </span> 47/increment-EDI -<span id="L175" class="LineNr">175 </span> eb/jump $_append:loop/disp8 -<span id="L176" class="LineNr">176 </span>$_append:end: -<span id="L177" class="LineNr">177 </span> <span class="Comment"># restore registers</span> -<span id="L178" class="LineNr">178 </span> 5f/pop-to-EDI -<span id="L179" class="LineNr">179 </span> 5e/pop-to-ESI -<span id="L180" class="LineNr">180 </span> 5b/pop-to-EBX -<span id="L181" class="LineNr">181 </span> 5a/pop-to-EDX -<span id="L182" class="LineNr">182 </span> 59/pop-to-ECX -<span id="L183" class="LineNr">183 </span> <span class="Comment"># epilog</span> -<span id="L184" class="LineNr">184 </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="L185" class="LineNr">185 </span> 5d/pop-to-EBP -<span id="L186" class="LineNr">186 </span> c3/return -<span id="L187" class="LineNr">187 </span> -<span id="L188" class="LineNr">188 </span>clear-trace-stream: <span class="Comment"># t : (address trace-stream)</span> -<span id="L189" class="LineNr">189 </span> <span class="Comment"># prolog</span> -<span id="L190" class="LineNr">190 </span> 55/push-EBP -<span id="L191" class="LineNr">191 </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="L192" class="LineNr">192 </span> <span class="Comment"># save registers</span> -<span id="L193" class="LineNr">193 </span> 50/push-EAX -<span id="L194" class="LineNr">194 </span> 51/push-ECX -<span id="L195" class="LineNr">195 </span> <span class="Comment"># EAX = t</span> -<span id="L196" class="LineNr">196 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> -<span id="L197" class="LineNr">197 </span> <span class="Comment"># ECX = t.length</span> -<span id="L198" class="LineNr">198 </span> 8b/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EAX+8) to ECX</span> -<span id="L199" class="LineNr">199 </span> <span class="Comment"># ECX = &t.data[t.length]</span> -<span id="L200" class="LineNr">200 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX+ECX+12 to ECX</span> -<span id="L201" class="LineNr">201 </span> <span class="Comment"># t.write = 0</span> -<span id="L202" class="LineNr">202 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> -<span id="L203" class="LineNr">203 </span> <span class="Comment"># t.read = 0</span> -<span id="L204" class="LineNr">204 </span> c7/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 0/imm32 <span class="Comment"># copy to *(EAX+4)</span> -<span id="L205" class="LineNr">205 </span> <span class="Comment"># EAX = t.data</span> -<span id="L206" class="LineNr">206 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to EAX</span> -<span id="L207" class="LineNr">207 </span> <span class="Comment"># while (true)</span> -<span id="L208" class="LineNr">208 </span>$clear-trace-stream:loop: -<span id="L209" class="LineNr">209 </span> <span class="Comment"># if EAX >= ECX break</span> -<span id="L210" class="LineNr">210 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with ECX</span> -<span id="L211" class="LineNr">211 </span> 7d/jump-if-greater-or-equal $clear-trace-stream:end/disp8 -<span id="L212" class="LineNr">212 </span> <span class="Comment"># *EAX = 0</span> -<span id="L213" class="LineNr">213 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> -<span id="L214" class="LineNr">214 </span> <span class="Comment"># EAX += 4</span> -<span id="L215" class="LineNr">215 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to EAX</span> -<span id="L216" class="LineNr">216 </span> eb/jump $clear-trace-stream:loop/disp8 -<span id="L217" class="LineNr">217 </span>$clear-trace-stream:end: -<span id="L218" class="LineNr">218 </span> <span class="Comment"># restore registers</span> -<span id="L219" class="LineNr">219 </span> 59/pop-to-ECX -<span id="L220" class="LineNr">220 </span> 58/pop-to-EAX -<span id="L221" class="LineNr">221 </span> <span class="Comment"># epilog</span> -<span id="L222" class="LineNr">222 </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="L223" class="LineNr">223 </span> 5d/pop-to-EBP -<span id="L224" class="LineNr">224 </span> c3/return -<span id="L225" class="LineNr">225 </span> -<span id="L226" class="LineNr">226 </span>test-trace-single: -<span id="L227" class="LineNr">227 </span> <span class="Comment"># clear-trace-stream(Test-trace-stream)</span> -<span id="L228" class="LineNr">228 </span> <span class="Comment"># push args</span> -<span id="L229" class="LineNr">229 </span> 68/push Test-trace-stream/imm32 -<span id="L230" class="LineNr">230 </span> <span class="Comment"># call</span> -<span id="L231" class="LineNr">231 </span> e8/call clear-trace-stream/disp32 -<span id="L232" class="LineNr">232 </span> <span class="Comment"># discard args</span> -<span id="L233" class="LineNr">233 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L234" class="LineNr">234 </span> <span class="Comment"># trace(Test-trace-stream, "Ab")</span> -<span id="L235" class="LineNr">235 </span> <span class="Comment"># push args</span> -<span id="L236" class="LineNr">236 </span> 68/push "Ab"/imm32 -<span id="L237" class="LineNr">237 </span> 68/push Test-trace-stream/imm32 +<span id="L142" class="LineNr">142 </span> 50/push-EAX +<span id="L143" class="LineNr">143 </span> 51/push-ECX +<span id="L144" class="LineNr">144 </span> <span class="Comment"># EAX = t</span> +<span id="L145" class="LineNr">145 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> +<span id="L146" class="LineNr">146 </span> <span class="Comment"># ECX = t->length</span> +<span id="L147" class="LineNr">147 </span> 8b/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EAX+8) to ECX</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment"># ECX = &t->data[t->length]</span> +<span id="L149" class="LineNr">149 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX+ECX+12 to ECX</span> +<span id="L150" class="LineNr">150 </span> <span class="Comment"># t->write = 0</span> +<span id="L151" class="LineNr">151 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> +<span id="L152" class="LineNr">152 </span> <span class="Comment"># t->read = 0</span> +<span id="L153" class="LineNr">153 </span> c7/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 0/imm32 <span class="Comment"># copy to *(EAX+4)</span> +<span id="L154" class="LineNr">154 </span> <span class="Comment"># EAX = t->data</span> +<span id="L155" class="LineNr">155 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to EAX</span> +<span id="L156" class="LineNr">156 </span> <span class="Comment"># while (true)</span> +<span id="L157" class="LineNr">157 </span>$clear-trace-stream:loop: +<span id="L158" class="LineNr">158 </span> <span class="Comment"># if EAX >= ECX break</span> +<span id="L159" class="LineNr">159 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with ECX</span> +<span id="L160" class="LineNr">160 </span> 7d/jump-if-greater-or-equal $clear-trace-stream:end/disp8 +<span id="L161" class="LineNr">161 </span> <span class="Comment"># *EAX = 0</span> +<span id="L162" class="LineNr">162 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># EAX += 4</span> +<span id="L164" class="LineNr">164 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to EAX</span> +<span id="L165" class="LineNr">165 </span> eb/jump $clear-trace-stream:loop/disp8 +<span id="L166" class="LineNr">166 </span>$clear-trace-stream:end: +<span id="L167" class="LineNr">167 </span> <span class="Comment"># restore registers</span> +<span id="L168" class="LineNr">168 </span> 59/pop-to-ECX +<span id="L169" class="LineNr">169 </span> 58/pop-to-EAX +<span id="L170" class="LineNr">170 </span> <span class="Comment"># epilog</span> +<span id="L171" class="LineNr">171 </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="L172" class="LineNr">172 </span> 5d/pop-to-EBP +<span id="L173" class="LineNr">173 </span> c3/return +<span id="L174" class="LineNr">174 </span> +<span id="L175" class="LineNr">175 </span><span class="SalientComment">## tests</span> +<span id="L176" class="LineNr">176 </span> +<span id="L177" class="LineNr">177 </span>test-trace-single: +<span id="L178" class="LineNr">178 </span> <span class="Comment"># clear-trace-stream(_test-trace-stream)</span> +<span id="L179" class="LineNr">179 </span> <span class="Comment"># push args</span> +<span id="L180" class="LineNr">180 </span> 68/push _test-trace-stream/imm32 +<span id="L181" class="LineNr">181 </span> <span class="Comment"># call</span> +<span id="L182" class="LineNr">182 </span> e8/call clear-trace-stream/disp32 +<span id="L183" class="LineNr">183 </span> <span class="Comment"># discard args</span> +<span id="L184" class="LineNr">184 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L185" class="LineNr">185 </span> <span class="Comment"># trace(_test-trace-stream, "Ab")</span> +<span id="L186" class="LineNr">186 </span> <span class="Comment"># push args</span> +<span id="L187" class="LineNr">187 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L188" class="LineNr">188 </span> 68/push _test-trace-stream/imm32 +<span id="L189" class="LineNr">189 </span> <span class="Comment"># call</span> +<span id="L190" class="LineNr">190 </span> e8/call trace/disp32 +<span id="L191" class="LineNr">191 </span> <span class="Comment"># discard args</span> +<span id="L192" class="LineNr">192 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L193" class="LineNr">193 </span> <span class="Comment"># check-ints-equal(*_test-trace-stream.data, 41/A 62/b 0a/newline 00, msg)</span> +<span id="L194" class="LineNr">194 </span> <span class="Comment"># push args</span> +<span id="L195" class="LineNr">195 </span> 68/push <span class="Constant">"F - test-trace-single"</span>/imm32 +<span id="L196" class="LineNr">196 </span> 68/push 0x0a6241/imm32/<span class="Special">Ab-newline</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment"># push *_test-trace-stream.data</span> +<span id="L198" class="LineNr">198 </span> b8/copy-to-EAX _test-trace-stream/imm32 +<span id="L199" class="LineNr">199 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L200" class="LineNr">200 </span> <span class="Comment"># call</span> +<span id="L201" class="LineNr">201 </span> e8/call check-ints-equal/disp32 +<span id="L202" class="LineNr">202 </span> <span class="Comment"># discard args</span> +<span id="L203" class="LineNr">203 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L204" class="LineNr">204 </span> <span class="Comment"># end</span> +<span id="L205" class="LineNr">205 </span> c3/return +<span id="L206" class="LineNr">206 </span> +<span id="L207" class="LineNr">207 </span>test-trace-appends: +<span id="L208" class="LineNr">208 </span> <span class="Comment"># clear-trace-stream(_test-trace-stream)</span> +<span id="L209" class="LineNr">209 </span> <span class="Comment"># push args</span> +<span id="L210" class="LineNr">210 </span> 68/push _test-trace-stream/imm32 +<span id="L211" class="LineNr">211 </span> <span class="Comment"># call</span> +<span id="L212" class="LineNr">212 </span> e8/call clear-trace-stream/disp32 +<span id="L213" class="LineNr">213 </span> <span class="Comment"># discard args</span> +<span id="L214" class="LineNr">214 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L215" class="LineNr">215 </span> <span class="Comment"># trace(_test-trace-stream, "C")</span> +<span id="L216" class="LineNr">216 </span> <span class="Comment"># push args</span> +<span id="L217" class="LineNr">217 </span> 68/push <span class="Constant">"C"</span>/imm32 +<span id="L218" class="LineNr">218 </span> 68/push _test-trace-stream/imm32 +<span id="L219" class="LineNr">219 </span> <span class="Comment"># call</span> +<span id="L220" class="LineNr">220 </span> e8/call trace/disp32 +<span id="L221" class="LineNr">221 </span> <span class="Comment"># discard args</span> +<span id="L222" class="LineNr">222 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L223" class="LineNr">223 </span> <span class="Comment"># trace(_test-trace-stream, "D")</span> +<span id="L224" class="LineNr">224 </span> <span class="Comment"># push args</span> +<span id="L225" class="LineNr">225 </span> 68/push <span class="Constant">"D"</span>/imm32 +<span id="L226" class="LineNr">226 </span> 68/push _test-trace-stream/imm32 +<span id="L227" class="LineNr">227 </span> <span class="Comment"># call</span> +<span id="L228" class="LineNr">228 </span> e8/call trace/disp32 +<span id="L229" class="LineNr">229 </span> <span class="Comment"># discard args</span> +<span id="L230" class="LineNr">230 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L231" class="LineNr">231 </span> <span class="Comment"># check-ints-equal(*_test-trace-stream.data, 43/C 0a/newline 44/D 0a/newline, msg)</span> +<span id="L232" class="LineNr">232 </span> <span class="Comment"># push args</span> +<span id="L233" class="LineNr">233 </span> 68/push <span class="Constant">"F - test-trace-appends"</span>/imm32 +<span id="L234" class="LineNr">234 </span> 68/push 0x0a440a43/imm32/C-newline-D-newline +<span id="L235" class="LineNr">235 </span> <span class="Comment"># push *_test-trace-stream.data</span> +<span id="L236" class="LineNr">236 </span> b8/copy-to-EAX _test-trace-stream/imm32 +<span id="L237" class="LineNr">237 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> <span id="L238" class="LineNr">238 </span> <span class="Comment"># call</span> -<span id="L239" class="LineNr">239 </span> e8/call trace/disp32 +<span id="L239" class="LineNr">239 </span> e8/call check-ints-equal/disp32 <span id="L240" class="LineNr">240 </span> <span class="Comment"># discard args</span> -<span id="L241" class="LineNr">241 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L242" class="LineNr">242 </span> <span class="Comment"># check-ints-equal(*Test-trace-stream.data, 41/A 62/b 0a/newline 00, msg)</span> -<span id="L243" class="LineNr">243 </span> <span class="Comment"># push args</span> -<span id="L244" class="LineNr">244 </span> 68/push "F - test-trace-single"/imm32 -<span id="L245" class="LineNr">245 </span> 68/push 0x0a6241/imm32/Ab-newline -<span id="L246" class="LineNr">246 </span> <span class="Comment"># push *Test-trace-stream.data</span> -<span id="L247" class="LineNr">247 </span> b8/copy-to-EAX Test-trace-stream/imm32 -<span id="L248" class="LineNr">248 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L241" class="LineNr">241 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L242" class="LineNr">242 </span> <span class="Comment"># end</span> +<span id="L243" class="LineNr">243 </span> c3/return +<span id="L244" class="LineNr">244 </span> +<span id="L245" class="LineNr">245 </span>test-trace-empty-line: +<span id="L246" class="LineNr">246 </span> <span class="Comment"># clear-trace-stream(_test-trace-stream)</span> +<span id="L247" class="LineNr">247 </span> <span class="Comment"># push args</span> +<span id="L248" class="LineNr">248 </span> 68/push _test-trace-stream/imm32 <span id="L249" class="LineNr">249 </span> <span class="Comment"># call</span> -<span id="L250" class="LineNr">250 </span> e8/call check-ints-equal/disp32 +<span id="L250" class="LineNr">250 </span> e8/call clear-trace-stream/disp32 <span id="L251" class="LineNr">251 </span> <span class="Comment"># discard args</span> -<span id="L252" class="LineNr">252 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L253" class="LineNr">253 </span> <span class="Comment"># end</span> -<span id="L254" class="LineNr">254 </span> c3/return -<span id="L255" class="LineNr">255 </span> -<span id="L256" class="LineNr">256 </span>test-trace-appends: -<span id="L257" class="LineNr">257 </span> <span class="Comment"># clear-trace-stream(Test-trace-stream)</span> -<span id="L258" class="LineNr">258 </span> <span class="Comment"># push args</span> -<span id="L259" class="LineNr">259 </span> 68/push Test-trace-stream/imm32 -<span id="L260" class="LineNr">260 </span> <span class="Comment"># call</span> -<span id="L261" class="LineNr">261 </span> e8/call clear-trace-stream/disp32 -<span id="L262" class="LineNr">262 </span> <span class="Comment"># discard args</span> -<span id="L263" class="LineNr">263 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L264" class="LineNr">264 </span> <span class="Comment"># trace(Test-trace-stream, "C")</span> -<span id="L265" class="LineNr">265 </span> <span class="Comment"># push args</span> -<span id="L266" class="LineNr">266 </span> 68/push "C"/imm32 -<span id="L267" class="LineNr">267 </span> 68/push Test-trace-stream/imm32 +<span id="L252" class="LineNr">252 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L253" class="LineNr">253 </span> <span class="Comment"># trace(_test-trace-stream, "")</span> +<span id="L254" class="LineNr">254 </span> <span class="Comment"># push args</span> +<span id="L255" class="LineNr">255 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L256" class="LineNr">256 </span> 68/push _test-trace-stream/imm32 +<span id="L257" class="LineNr">257 </span> <span class="Comment"># call</span> +<span id="L258" class="LineNr">258 </span> e8/call trace/disp32 +<span id="L259" class="LineNr">259 </span> <span class="Comment"># discard args</span> +<span id="L260" class="LineNr">260 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L261" class="LineNr">261 </span> <span class="Comment"># check-ints-equal(*_test-trace-stream.data, 0, msg)</span> +<span id="L262" class="LineNr">262 </span> <span class="Comment"># push args</span> +<span id="L263" class="LineNr">263 </span> 68/push <span class="Constant">"F - test-trace-empty-line"</span>/imm32 +<span id="L264" class="LineNr">264 </span> 68/push 0/imm32 +<span id="L265" class="LineNr">265 </span> <span class="Comment"># push *_test-trace-stream.data</span> +<span id="L266" class="LineNr">266 </span> b8/copy-to-EAX _test-trace-stream/imm32 +<span id="L267" class="LineNr">267 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> <span id="L268" class="LineNr">268 </span> <span class="Comment"># call</span> -<span id="L269" class="LineNr">269 </span> e8/call trace/disp32 +<span id="L269" class="LineNr">269 </span> e8/call check-ints-equal/disp32 <span id="L270" class="LineNr">270 </span> <span class="Comment"># discard args</span> -<span id="L271" class="LineNr">271 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L272" class="LineNr">272 </span> <span class="Comment"># trace(Test-trace-stream, "D")</span> -<span id="L273" class="LineNr">273 </span> <span class="Comment"># push args</span> -<span id="L274" class="LineNr">274 </span> 68/push "D"/imm32 -<span id="L275" class="LineNr">275 </span> 68/push Test-trace-stream/imm32 -<span id="L276" class="LineNr">276 </span> <span class="Comment"># call</span> -<span id="L277" class="LineNr">277 </span> e8/call trace/disp32 -<span id="L278" class="LineNr">278 </span> <span class="Comment"># discard args</span> -<span id="L279" class="LineNr">279 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L280" class="LineNr">280 </span> <span class="Comment"># check-ints-equal(*Test-trace-stream.data, 43/C 0a/newline 44/D 0a/newline, msg)</span> -<span id="L281" class="LineNr">281 </span> <span class="Comment"># push args</span> -<span id="L282" class="LineNr">282 </span> 68/push "F - test-trace-appends"/imm32 -<span id="L283" class="LineNr">283 </span> 68/push 0x0a440a43/imm32/C-newline-D-newline -<span id="L284" class="LineNr">284 </span> <span class="Comment"># push *Test-trace-stream.data</span> -<span id="L285" class="LineNr">285 </span> b8/copy-to-EAX Test-trace-stream/imm32 -<span id="L286" class="LineNr">286 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> -<span id="L287" class="LineNr">287 </span> <span class="Comment"># call</span> -<span id="L288" class="LineNr">288 </span> e8/call check-ints-equal/disp32 -<span id="L289" class="LineNr">289 </span> <span class="Comment"># discard args</span> -<span id="L290" class="LineNr">290 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L291" class="LineNr">291 </span> <span class="Comment"># end</span> -<span id="L292" class="LineNr">292 </span> c3/return -<span id="L293" class="LineNr">293 </span> -<span id="L294" class="LineNr">294 </span>test-trace-empty-line: -<span id="L295" class="LineNr">295 </span> <span class="Comment"># clear-trace-stream(Test-trace-stream)</span> -<span id="L296" class="LineNr">296 </span> <span class="Comment"># push args</span> -<span id="L297" class="LineNr">297 </span> 68/push Test-trace-stream/imm32 -<span id="L298" class="LineNr">298 </span> <span class="Comment"># call</span> -<span id="L299" class="LineNr">299 </span> e8/call clear-trace-stream/disp32 -<span id="L300" class="LineNr">300 </span> <span class="Comment"># discard args</span> -<span id="L301" class="LineNr">301 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L302" class="LineNr">302 </span> <span class="Comment"># trace(Test-trace-stream, "")</span> -<span id="L303" class="LineNr">303 </span> <span class="Comment"># push args</span> -<span id="L304" class="LineNr">304 </span> 68/push ""/imm32 -<span id="L305" class="LineNr">305 </span> 68/push Test-trace-stream/imm32 -<span id="L306" class="LineNr">306 </span> <span class="Comment"># call</span> -<span id="L307" class="LineNr">307 </span> e8/call trace/disp32 -<span id="L308" class="LineNr">308 </span> <span class="Comment"># discard args</span> -<span id="L309" class="LineNr">309 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L310" class="LineNr">310 </span> <span class="Comment"># check-ints-equal(*Test-trace-stream.data, 0, msg)</span> -<span id="L311" class="LineNr">311 </span> <span class="Comment"># push args</span> -<span id="L312" class="LineNr">312 </span> 68/push "F - test-trace-empty-line"/imm32 -<span id="L313" class="LineNr">313 </span> 68/push 0/imm32 -<span id="L314" class="LineNr">314 </span> <span class="Comment"># push *Test-trace-stream.data</span> -<span id="L315" class="LineNr">315 </span> b8/copy-to-EAX Test-trace-stream/imm32 -<span id="L316" class="LineNr">316 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> -<span id="L317" class="LineNr">317 </span> <span class="Comment"># call</span> -<span id="L318" class="LineNr">318 </span> e8/call check-ints-equal/disp32 -<span id="L319" class="LineNr">319 </span> <span class="Comment"># discard args</span> -<span id="L320" class="LineNr">320 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L321" class="LineNr">321 </span> <span class="Comment"># end</span> -<span id="L322" class="LineNr">322 </span> c3/return -<span id="L323" class="LineNr">323 </span> -<span id="L324" class="LineNr">324 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L271" class="LineNr">271 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L272" class="LineNr">272 </span> <span class="Comment"># end</span> +<span id="L273" class="LineNr">273 </span> c3/return +<span id="L274" class="LineNr">274 </span> +<span id="L275" class="LineNr">275 </span><span class="SalientComment">## helpers</span> +<span id="L276" class="LineNr">276 </span> +<span id="L277" class="LineNr">277 </span><span class="Comment"># 3-argument variant of _append</span> +<span id="L278" class="LineNr">278 </span>_append-3: <span class="Comment"># out : address, outend : address, s : (array byte) -> num_bytes_appended/EAX</span> +<span id="L279" class="LineNr">279 </span> <span class="Comment"># prolog</span> +<span id="L280" class="LineNr">280 </span> 55/push-EBP +<span id="L281" class="LineNr">281 </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="L282" class="LineNr">282 </span> <span class="Comment"># save registers</span> +<span id="L283" class="LineNr">283 </span> 51/push-ECX +<span id="L284" class="LineNr">284 </span> <span class="Comment"># _append-4(out, outend, &s.data[0], &s.data[s.length]) -> num_bytes_appended/EAX</span> +<span id="L285" class="LineNr">285 </span> <span class="Comment"># push &s.data[s.length]</span> +<span id="L286" class="LineNr">286 </span> <span class="Comment"># EAX = s</span> +<span id="L287" class="LineNr">287 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to EAX</span> +<span id="L288" class="LineNr">288 </span> <span class="Comment"># ECX = s.length</span> +<span id="L289" class="LineNr">289 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EAX to ECX</span> +<span id="L290" class="LineNr">290 </span> <span class="Comment"># ECX = &s.data[s.length]</span> +<span id="L291" class="LineNr">291 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX+ECX+4 to ECX</span> +<span id="L292" class="LineNr">292 </span> 51/push-ECX +<span id="L293" class="LineNr">293 </span> <span class="Comment"># push &s.data[0]</span> +<span id="L294" class="LineNr">294 </span> 8d/copy-address 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX+4 to ECX</span> +<span id="L295" class="LineNr">295 </span> 51/push-ECX +<span id="L296" class="LineNr">296 </span> <span class="Comment"># push outend</span> +<span id="L297" class="LineNr">297 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L298" class="LineNr">298 </span> <span class="Comment"># push out</span> +<span id="L299" class="LineNr">299 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L300" class="LineNr">300 </span> <span class="Comment"># call</span> +<span id="L301" class="LineNr">301 </span> e8/call _append-4/disp32 +<span id="L302" class="LineNr">302 </span> <span class="Comment"># discard args</span> +<span id="L303" class="LineNr">303 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L304" class="LineNr">304 </span> <span class="Comment"># restore registers</span> +<span id="L305" class="LineNr">305 </span> 59/pop-to-ECX +<span id="L306" class="LineNr">306 </span> <span class="Comment"># epilog</span> +<span id="L307" class="LineNr">307 </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="L308" class="LineNr">308 </span> 5d/pop-to-EBP +<span id="L309" class="LineNr">309 </span> c3/return +<span id="L310" class="LineNr">310 </span> +<span id="L311" class="LineNr">311 </span><span class="Comment"># 4-argument variant of _append</span> +<span id="L312" class="LineNr">312 </span>_append-4: <span class="Comment"># out : address, outend : address, in : address, inend : address -> num_bytes_appended/EAX</span> +<span id="L313" class="LineNr">313 </span> <span class="Comment"># prolog</span> +<span id="L314" class="LineNr">314 </span> 55/push-EBP +<span id="L315" class="LineNr">315 </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="L316" class="LineNr">316 </span> <span class="Comment"># save registers</span> +<span id="L317" class="LineNr">317 </span> 51/push-ECX +<span id="L318" class="LineNr">318 </span> 52/push-EDX +<span id="L319" class="LineNr">319 </span> 53/push-EBX +<span id="L320" class="LineNr">320 </span> 56/push-ESI +<span id="L321" class="LineNr">321 </span> 57/push-EDI +<span id="L322" class="LineNr">322 </span> <span class="Comment"># EAX/num_bytes_appended = 0</span> +<span id="L323" class="LineNr">323 </span> b8/copy-to-EAX 0/imm32 +<span id="L324" class="LineNr">324 </span> <span class="Comment"># EDI = out</span> +<span id="L325" class="LineNr">325 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> +<span id="L326" class="LineNr">326 </span> <span class="Comment"># EDX = outend</span> +<span id="L327" class="LineNr">327 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> +<span id="L328" class="LineNr">328 </span> <span class="Comment"># ESI = in</span> +<span id="L329" class="LineNr">329 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to ESI</span> +<span id="L330" class="LineNr">330 </span> <span class="Comment"># ECX = inend</span> +<span id="L331" class="LineNr">331 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+20) to ECX</span> +<span id="L332" class="LineNr">332 </span>$_append-4:loop: +<span id="L333" class="LineNr">333 </span> <span class="Comment"># if ESI/src >= ECX/srcend break</span> +<span id="L334" class="LineNr">334 </span> 39/compare 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare ESI with ECX</span> +<span id="L335" class="LineNr">335 </span> 7d/jump-if-greater-or-equal $_append-4:end/disp8 +<span id="L336" class="LineNr">336 </span> <span class="Comment"># if EDI/out >= EDX/outend break (for now silently ignore filled up buffer)</span> +<span id="L337" class="LineNr">337 </span> 39/compare 3/mod/direct 7/rm32/EDI <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"># compare EDI with EDX</span> +<span id="L338" class="LineNr">338 </span> 7d/jump-if-greater-or-equal $_append-4:end/disp8 +<span id="L339" class="LineNr">339 </span> <span class="Comment"># copy one byte from ESI/src to EDI/out</span> +<span id="L340" class="LineNr">340 </span> 8a/copy-byte 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/BL <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *ESI to BL</span> +<span id="L341" class="LineNr">341 </span> 88/copy-byte 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/BL <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at BL to *EDI</span> +<span id="L342" class="LineNr">342 </span> <span class="Comment"># updates</span> +<span id="L343" class="LineNr">343 </span> 40/increment-EAX +<span id="L344" class="LineNr">344 </span> 46/increment-ESI +<span id="L345" class="LineNr">345 </span> 47/increment-EDI +<span id="L346" class="LineNr">346 </span> eb/jump $_append-4:loop/disp8 +<span id="L347" class="LineNr">347 </span>$_append-4:end: +<span id="L348" class="LineNr">348 </span> <span class="Comment"># restore registers</span> +<span id="L349" class="LineNr">349 </span> 5f/pop-to-EDI +<span id="L350" class="LineNr">350 </span> 5e/pop-to-ESI +<span id="L351" class="LineNr">351 </span> 5b/pop-to-EBX +<span id="L352" class="LineNr">352 </span> 5a/pop-to-EDX +<span id="L353" class="LineNr">353 </span> 59/pop-to-ECX +<span id="L354" class="LineNr">354 </span> <span class="Comment"># epilog</span> +<span id="L355" class="LineNr">355 </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="L356" class="LineNr">356 </span> 5d/pop-to-EBP +<span id="L357" class="LineNr">357 </span> c3/return +<span id="L358" class="LineNr">358 </span> +<span id="L359" class="LineNr">359 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/056write.subx.html b/html/subx/056write.subx.html index 83562c91..ab468415 100644 --- a/html/subx/056write.subx.html +++ b/html/subx/056write.subx.html @@ -6,17 +6,19 @@ <meta name="Generator" content="Vim/8.0"> <meta name="plugin-version" content="vim7.4_v2"> <meta name="syntax" content="none"> -<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> <meta name="colorscheme" content="minimal"> <style type="text/css"> <!-- -pre { white-space: pre-wrap; font-family: monospace; color: #aaaaaa; background-color: #080808; } +pre { font-family: monospace; color: #aaaaaa; background-color: #080808; } body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } --> @@ -53,160 +55,160 @@ if ('onhashchange' in window) { </head> <body onload='JumpToLine();'> <pre id='vimCodeElement'> -<span id="L1" class="LineNr"> 1 </span><span class="Comment"># write: like _write, but also support in-memory output streams (`ostream`s)</span> -<span id="L2" class="LineNr"> 2 </span><span class="Comment"># in addition to file descriptors.</span> +<span id="L1" class="LineNr"> 1 </span><span class="Comment"># write: like _write, but also support in-memory streams in addition to file</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment"># descriptors.</span> <span id="L3" class="LineNr"> 3 </span><span class="Comment">#</span> <span id="L4" class="LineNr"> 4 </span><span class="Comment"># Our first dependency-injected and testable primitive. We can pass it either</span> -<span id="L5" class="LineNr"> 5 </span><span class="Comment"># a file descriptor or an address to an output stream or ostream. If a file</span> -<span id="L6" class="LineNr"> 6 </span><span class="Comment"># descriptor is passed in, we _write to it using the right syscall. If a 'fake</span> -<span id="L7" class="LineNr"> 7 </span><span class="Comment"># file descriptor' or ostream is passed in, we append to the output stream.</span> -<span id="L8" class="LineNr"> 8 </span><span class="Comment"># This lets us redirect output in tests and check it later.</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># a file descriptor or an address to a stream. If a file descriptor is passed</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># in, we _write to it using the right syscall. If a 'fake file descriptor' or</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># stream is passed in, we append to the stream. This lets us redirect output</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># in tests and check it later.</span> <span id="L9" class="LineNr"> 9 </span><span class="Comment">#</span> <span id="L10" class="LineNr"> 10 </span><span class="Comment"># We assume our data segment will never begin at an address shorter than</span> <span id="L11" class="LineNr"> 11 </span><span class="Comment"># 0x08000000, so any smaller arguments are assumed to be real file descriptors.</span> <span id="L12" class="LineNr"> 12 </span><span class="Comment">#</span> -<span id="L13" class="LineNr"> 13 </span><span class="Comment"># An ostream looks like this:</span> -<span id="L14" class="LineNr"> 14 </span><span class="Comment"># write: int # index at which writes go</span> -<span id="L15" class="LineNr"> 15 </span><span class="Comment"># data: (array byte) # prefixed by length as usual</span> -<span id="L16" class="LineNr"> 16 </span> -<span id="L17" class="LineNr"> 17 </span>== data -<span id="L18" class="LineNr"> 18 </span> -<span id="L19" class="LineNr"> 19 </span><span class="Comment"># In-memory ostream for tests to write() to.</span> -<span id="L20" class="LineNr"> 20 </span><span class="Comment"># Also illustrates the layout of ostreams.</span> -<span id="L21" class="LineNr"> 21 </span>Test-ostream: -<span id="L22" class="LineNr"> 22 </span> <span class="Comment"># current write index</span> -<span id="L23" class="LineNr"> 23 </span> 00 00 00 00 -<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># length (= 8)</span> -<span id="L25" class="LineNr"> 25 </span> 08 00 00 00 -<span id="L26" class="LineNr"> 26 </span> <span class="Comment"># data</span> -<span id="L27" class="LineNr"> 27 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> -<span id="L28" class="LineNr"> 28 </span> -<span id="L29" class="LineNr"> 29 </span>== code -<span id="L30" class="LineNr"> 30 </span> -<span id="L31" class="LineNr"> 31 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L32" class="LineNr"> 32 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L33" class="LineNr"> 33 </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> -<span id="L34" class="LineNr"> 34 </span> -<span id="L35" class="LineNr"> 35 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> -<span id="L36" class="LineNr"> 36 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> -<span id="L37" class="LineNr"> 37 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> -<span id="L38" class="LineNr"> 38 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/EBX Num-test-failures/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> -<span id="L39" class="LineNr"> 39 </span> b8/copy-to-EAX 1/imm32 -<span id="L40" class="LineNr"> 40 </span> cd/syscall 0x80/imm8 -<span id="L41" class="LineNr"> 41 </span> -<span id="L42" class="LineNr"> 42 </span>write: <span class="Comment"># f : fd or (address stream), s : (address array byte) -> <void></span> -<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># prolog</span> -<span id="L44" class="LineNr"> 44 </span> 55/push-EBP -<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"># if (f < 0x08000000) _write(f, s), return # f can't be a user-mode address, so treat it as a kernel file descriptor</span> -<span id="L47" class="LineNr"> 47 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 0x08000000/imm32 <span class="Comment"># compare *(EBP+8)</span> -<span id="L48" class="LineNr"> 48 </span> 7f/jump-if-greater $write:fake/disp8 -<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># push args</span> -<span id="L50" class="LineNr"> 50 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L51" class="LineNr"> 51 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># call</span> -<span id="L53" class="LineNr"> 53 </span> e8/call _write/disp32 -<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># discard args</span> -<span id="L55" class="LineNr"> 55 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L56" class="LineNr"> 56 </span> eb/jump $write:end/disp8 -<span id="L57" class="LineNr"> 57 </span>$write:fake: -<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># otherwise, treat 'f' as a stream to append to</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># save registers</span> -<span id="L60" class="LineNr"> 60 </span> 50/push-EAX -<span id="L61" class="LineNr"> 61 </span> 51/push-ECX -<span id="L62" class="LineNr"> 62 </span> 52/push-EDX -<span id="L63" class="LineNr"> 63 </span> 53/push-EBX -<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># ECX = f</span> -<span id="L65" class="LineNr"> 65 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ECX</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># EDX = f.write</span> -<span id="L67" class="LineNr"> 67 </span> 8b/copy 0/mod/indirect 1/rm32/ECX <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 *ECX to EDX</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># EBX = f.length</span> -<span id="L69" class="LineNr"> 69 </span> 8b/copy 1/mod/*+disp8 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ECX+4) to EBX</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># EAX = _append(&f.data[f.write], &f.data[f.length], s)</span> -<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># push s</span> -<span id="L72" class="LineNr"> 72 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Comment"># push &f.data[f.length]</span> -<span id="L74" class="LineNr"> 74 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 3/index/EBX <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ECX+EBX+8 to EBX</span> -<span id="L75" class="LineNr"> 75 </span> 53/push-EBX -<span id="L76" class="LineNr"> 76 </span> <span class="Comment"># push &f.data[f.write]</span> -<span id="L77" class="LineNr"> 77 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 2/index/EDX <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ECX+EBX+8 to EBX</span> -<span id="L78" class="LineNr"> 78 </span> 53/push-EBX -<span id="L79" class="LineNr"> 79 </span> <span class="Comment"># call</span> -<span id="L80" class="LineNr"> 80 </span> e8/call _append/disp32 -<span id="L81" class="LineNr"> 81 </span> <span class="Comment"># discard args</span> -<span id="L82" class="LineNr"> 82 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L83" class="LineNr"> 83 </span> <span class="Comment"># f.write += EAX</span> -<span id="L84" class="LineNr"> 84 </span> 01/add 0/mod/indirect 1/rm32/ECX <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"># add EAX to *ECX</span> -<span id="L85" class="LineNr"> 85 </span> <span class="Comment"># restore registers</span> -<span id="L86" class="LineNr"> 86 </span> 5b/pop-to-EBX -<span id="L87" class="LineNr"> 87 </span> 5a/pop-to-EDX -<span id="L88" class="LineNr"> 88 </span> 59/pop-to-ECX -<span id="L89" class="LineNr"> 89 </span> 58/pop-to-EAX -<span id="L90" class="LineNr"> 90 </span>$write:end: -<span id="L91" class="LineNr"> 91 </span> <span class="Comment"># epilog</span> -<span id="L92" class="LineNr"> 92 </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="L93" class="LineNr"> 93 </span> 5d/pop-to-EBP -<span id="L94" class="LineNr"> 94 </span> c3/return -<span id="L95" class="LineNr"> 95 </span> -<span id="L96" class="LineNr"> 96 </span>clear-ostream: <span class="Comment"># f : (address ostream)</span> -<span id="L97" class="LineNr"> 97 </span> <span class="Comment"># prolog</span> -<span id="L98" class="LineNr"> 98 </span> 55/push-EBP -<span id="L99" class="LineNr"> 99 </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="L100" class="LineNr">100 </span> <span class="Comment"># save registers</span> -<span id="L101" class="LineNr">101 </span> 50/push-EAX -<span id="L102" class="LineNr">102 </span> 51/push-ECX -<span id="L103" class="LineNr">103 </span> <span class="Comment"># EAX = f</span> -<span id="L104" class="LineNr">104 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> -<span id="L105" class="LineNr">105 </span> <span class="Comment"># ECX = f.length</span> -<span id="L106" class="LineNr">106 </span> 8b/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EAX+4) to ECX</span> -<span id="L107" class="LineNr">107 </span> <span class="Comment"># ECX = &f.data[f.length]</span> -<span id="L108" class="LineNr">108 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX+ECX+8 to ECX</span> -<span id="L109" class="LineNr">109 </span> <span class="Comment"># f.write = 0</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment"># A stream looks like this:</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment"># read: int # index at which to read next</span> +<span id="L15" class="LineNr"> 15 </span><span class="Comment"># write: int # index at which writes go</span> +<span id="L16" class="LineNr"> 16 </span><span class="Comment"># data: (array byte) # prefixed by length as usual</span> +<span id="L17" class="LineNr"> 17 </span> +<span id="L18" class="LineNr"> 18 </span>== code +<span id="L19" class="LineNr"> 19 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L21" class="LineNr"> 21 </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> +<span id="L22" class="LineNr"> 22 </span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment"># main:</span> +<span id="L24" class="LineNr"> 24 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L25" class="LineNr"> 25 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> +<span id="L26" class="LineNr"> 26 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L27" class="LineNr"> 27 </span> b8/copy-to-EAX 1/imm32 +<span id="L28" class="LineNr"> 28 </span> cd/syscall 0x80/imm8 +<span id="L29" class="LineNr"> 29 </span> +<span id="L30" class="LineNr"> 30 </span>write: <span class="Comment"># f : fd or (address stream), s : (address array byte) -> bytes_written/EAX</span> +<span id="L31" class="LineNr"> 31 </span> <span class="Comment"># (If we ever leave the Linux kernel behind, it may be better to return</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Comment"># the number of bytes *not* written. Success would then be signaled by</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Comment"># returning 0.)</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># prolog</span> +<span id="L35" class="LineNr"> 35 </span> 55/push-EBP +<span id="L36" class="LineNr"> 36 </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="L37" class="LineNr"> 37 </span> <span class="Comment"># if (f < 0x08000000) _write(f, s), return # f can't be a user-mode address, so treat it as a kernel file descriptor</span> +<span id="L38" class="LineNr"> 38 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 0x08000000/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L39" class="LineNr"> 39 </span> 7d/jump-if-greater-or-equal $write:fake/disp8 +<span id="L40" class="LineNr"> 40 </span> <span class="Comment"># push args</span> +<span id="L41" class="LineNr"> 41 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L42" class="LineNr"> 42 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># call</span> +<span id="L44" class="LineNr"> 44 </span> e8/call _write/disp32 +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># discard args</span> +<span id="L46" class="LineNr"> 46 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L47" class="LineNr"> 47 </span> eb/jump $write:end/disp8 +<span id="L48" class="LineNr"> 48 </span>$write:fake: +<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># otherwise, treat 'f' as a stream to append to</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># save registers</span> +<span id="L51" class="LineNr"> 51 </span> 51/push-ECX +<span id="L52" class="LineNr"> 52 </span> 52/push-EDX +<span id="L53" class="LineNr"> 53 </span> 53/push-EBX +<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># ECX = f</span> +<span id="L55" class="LineNr"> 55 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ECX</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># EDX = f->write</span> +<span id="L57" class="LineNr"> 57 </span> 8b/copy 0/mod/indirect 1/rm32/ECX <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 *ECX to EDX</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># EBX = f->length</span> +<span id="L59" class="LineNr"> 59 </span> 8b/copy 1/mod/*+disp8 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ECX+8) to EBX</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># EAX = _append-3(&f->data[f->write], &f->data[f->length], s)</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># push s</span> +<span id="L62" class="LineNr"> 62 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># push &f->data[f->length]</span> +<span id="L64" class="LineNr"> 64 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 3/index/EBX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ECX+EBX+12 to EBX</span> +<span id="L65" class="LineNr"> 65 </span> 53/push-EBX +<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># push &f->data[f->write]</span> +<span id="L67" class="LineNr"> 67 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 1/base/ECX 2/index/EDX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ECX+EDX+12 to EBX</span> +<span id="L68" class="LineNr"> 68 </span> 53/push-EBX +<span id="L69" class="LineNr"> 69 </span> <span class="Comment"># call</span> +<span id="L70" class="LineNr"> 70 </span> e8/call _append-3/disp32 +<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># discard args</span> +<span id="L72" class="LineNr"> 72 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Comment"># f->write += EAX</span> +<span id="L74" class="LineNr"> 74 </span> 01/add 0/mod/indirect 1/rm32/ECX <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"># add EAX to *ECX</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Comment"># restore registers</span> +<span id="L76" class="LineNr"> 76 </span> 5b/pop-to-EBX +<span id="L77" class="LineNr"> 77 </span> 5a/pop-to-EDX +<span id="L78" class="LineNr"> 78 </span> 59/pop-to-ECX +<span id="L79" class="LineNr"> 79 </span>$write:end: +<span id="L80" class="LineNr"> 80 </span> <span class="Comment"># epilog</span> +<span id="L81" class="LineNr"> 81 </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="L82" class="LineNr"> 82 </span> 5d/pop-to-EBP +<span id="L83" class="LineNr"> 83 </span> c3/return +<span id="L84" class="LineNr"> 84 </span> +<span id="L85" class="LineNr"> 85 </span>clear-stream: <span class="Comment"># f : (address stream) -> <void></span> +<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># prolog</span> +<span id="L87" class="LineNr"> 87 </span> 55/push-EBP +<span id="L88" class="LineNr"> 88 </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="L89" class="LineNr"> 89 </span> <span class="Comment"># save registers</span> +<span id="L90" class="LineNr"> 90 </span> 50/push-EAX +<span id="L91" class="LineNr"> 91 </span> 51/push-ECX +<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># EAX = f</span> +<span id="L93" class="LineNr"> 93 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Comment"># ECX = f->length</span> +<span id="L95" class="LineNr"> 95 </span> 8b/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EAX+8) to ECX</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Comment"># ECX = &f->data[f->length]</span> +<span id="L97" class="LineNr"> 97 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 0/base/EAX 1/index/ECX <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX+ECX+12 to ECX</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Comment"># f->write = 0</span> +<span id="L99" class="LineNr"> 99 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> +<span id="L100" class="LineNr">100 </span> <span class="Comment"># f->read = 0</span> +<span id="L101" class="LineNr">101 </span> c7/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 0/imm32 <span class="Comment"># copy to *(EAX+4)</span> +<span id="L102" class="LineNr">102 </span> <span class="Comment"># EAX = f->data</span> +<span id="L103" class="LineNr">103 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to EAX</span> +<span id="L104" class="LineNr">104 </span> <span class="Comment"># while (true)</span> +<span id="L105" class="LineNr">105 </span>$clear-stream:loop: +<span id="L106" class="LineNr">106 </span> <span class="Comment"># if EAX >= ECX break</span> +<span id="L107" class="LineNr">107 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with ECX</span> +<span id="L108" class="LineNr">108 </span> 7d/jump-if-greater-or-equal $clear-stream:end/disp8 +<span id="L109" class="LineNr">109 </span> <span class="Comment"># *EAX = 0</span> <span id="L110" class="LineNr">110 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> -<span id="L111" class="LineNr">111 </span> <span class="Comment"># EAX = f.data</span> -<span id="L112" class="LineNr">112 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to EAX</span> -<span id="L113" class="LineNr">113 </span> <span class="Comment"># while (true)</span> -<span id="L114" class="LineNr">114 </span>$clear-ostream:loop: -<span id="L115" class="LineNr">115 </span> <span class="Comment"># if EAX >= ECX break</span> -<span id="L116" class="LineNr">116 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with ECX</span> -<span id="L117" class="LineNr">117 </span> 7d/jump-if-greater-or-equal $clear-ostream:end/disp8 -<span id="L118" class="LineNr">118 </span> <span class="Comment"># *EAX = 0</span> -<span id="L119" class="LineNr">119 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> -<span id="L120" class="LineNr">120 </span> <span class="Comment"># EAX += 4</span> -<span id="L121" class="LineNr">121 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to EAX</span> -<span id="L122" class="LineNr">122 </span> eb/jump $clear-ostream:loop/disp8 -<span id="L123" class="LineNr">123 </span>$clear-ostream:end: -<span id="L124" class="LineNr">124 </span> <span class="Comment"># restore registers</span> -<span id="L125" class="LineNr">125 </span> 59/pop-to-ECX -<span id="L126" class="LineNr">126 </span> 58/pop-to-EAX -<span id="L127" class="LineNr">127 </span> <span class="Comment"># epilog</span> -<span id="L128" class="LineNr">128 </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="L129" class="LineNr">129 </span> 5d/pop-to-EBP -<span id="L130" class="LineNr">130 </span> c3/return -<span id="L131" class="LineNr">131 </span> -<span id="L132" class="LineNr">132 </span>test-write-single: -<span id="L133" class="LineNr">133 </span> <span class="Comment"># clear-ostream(Test-ostream)</span> -<span id="L134" class="LineNr">134 </span> <span class="Comment"># push args</span> -<span id="L135" class="LineNr">135 </span> 68/push Test-ostream/imm32 -<span id="L136" class="LineNr">136 </span> <span class="Comment"># call</span> -<span id="L137" class="LineNr">137 </span> e8/call clear-ostream/disp32 -<span id="L138" class="LineNr">138 </span> <span class="Comment"># discard args</span> -<span id="L139" class="LineNr">139 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L140" class="LineNr">140 </span> <span class="Comment"># write(Test-ostream, "Ab")</span> -<span id="L141" class="LineNr">141 </span> <span class="Comment"># push args</span> -<span id="L142" class="LineNr">142 </span> 68/push "Ab"/imm32 -<span id="L143" class="LineNr">143 </span> 68/push Test-ostream/imm32 +<span id="L111" class="LineNr">111 </span> <span class="Comment"># EAX += 4</span> +<span id="L112" class="LineNr">112 </span> 81 0/subop/add 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to EAX</span> +<span id="L113" class="LineNr">113 </span> eb/jump $clear-stream:loop/disp8 +<span id="L114" class="LineNr">114 </span>$clear-stream:end: +<span id="L115" class="LineNr">115 </span> <span class="Comment"># restore registers</span> +<span id="L116" class="LineNr">116 </span> 59/pop-to-ECX +<span id="L117" class="LineNr">117 </span> 58/pop-to-EAX +<span id="L118" class="LineNr">118 </span> <span class="Comment"># epilog</span> +<span id="L119" class="LineNr">119 </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="L120" class="LineNr">120 </span> 5d/pop-to-EBP +<span id="L121" class="LineNr">121 </span> c3/return +<span id="L122" class="LineNr">122 </span> +<span id="L123" class="LineNr">123 </span>test-write-single: +<span id="L124" class="LineNr">124 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L125" class="LineNr">125 </span> <span class="Comment"># push args</span> +<span id="L126" class="LineNr">126 </span> 68/push _test-stream/imm32 +<span id="L127" class="LineNr">127 </span> <span class="Comment"># call</span> +<span id="L128" class="LineNr">128 </span> e8/call clear-stream/disp32 +<span id="L129" class="LineNr">129 </span> <span class="Comment"># discard args</span> +<span id="L130" class="LineNr">130 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L131" class="LineNr">131 </span> <span class="Comment"># write(_test-stream, "Ab")</span> +<span id="L132" class="LineNr">132 </span> <span class="Comment"># push args</span> +<span id="L133" class="LineNr">133 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L134" class="LineNr">134 </span> 68/push _test-stream/imm32 +<span id="L135" class="LineNr">135 </span> <span class="Comment"># call</span> +<span id="L136" class="LineNr">136 </span> e8/call write/disp32 +<span id="L137" class="LineNr">137 </span> <span class="Comment"># discard args</span> +<span id="L138" class="LineNr">138 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L139" class="LineNr">139 </span> <span class="Comment"># check-ints-equal(EAX, 2)</span> +<span id="L140" class="LineNr">140 </span> <span class="Comment"># push args</span> +<span id="L141" class="LineNr">141 </span> 68/push <span class="Constant">"F - test-read-single: return EAX"</span>/imm32 +<span id="L142" class="LineNr">142 </span> 68/push 2/imm32 +<span id="L143" class="LineNr">143 </span> 50/push-EAX <span id="L144" class="LineNr">144 </span> <span class="Comment"># call</span> -<span id="L145" class="LineNr">145 </span> e8/call write/disp32 +<span id="L145" class="LineNr">145 </span> e8/call check-ints-equal/disp32 <span id="L146" class="LineNr">146 </span> <span class="Comment"># discard args</span> -<span id="L147" class="LineNr">147 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L148" class="LineNr">148 </span> <span class="Comment"># check-ints-equal(*Test-ostream.data, 41/A 62/b 00 00, msg)</span> +<span id="L147" class="LineNr">147 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment"># check-ints-equal(*_test-stream->data, 41/A 62/b 00 00, msg)</span> <span id="L149" class="LineNr">149 </span> <span class="Comment"># push args</span> -<span id="L150" class="LineNr">150 </span> 68/push "F - test-write-single"/imm32 -<span id="L151" class="LineNr">151 </span> 68/push 0x006241/imm32/Ab -<span id="L152" class="LineNr">152 </span> <span class="Comment"># push *Test-ostream.data</span> -<span id="L153" class="LineNr">153 </span> b8/copy-to-EAX Test-ostream/imm32 -<span id="L154" class="LineNr">154 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+8)</span> +<span id="L150" class="LineNr">150 </span> 68/push <span class="Constant">"F - test-write-single"</span>/imm32 +<span id="L151" class="LineNr">151 </span> 68/push 0x006241/imm32/<span class="Special">Ab</span> +<span id="L152" class="LineNr">152 </span> <span class="Comment"># push *_test-stream->data</span> +<span id="L153" class="LineNr">153 </span> b8/copy-to-EAX _test-stream/imm32 +<span id="L154" class="LineNr">154 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> <span id="L155" class="LineNr">155 </span> <span class="Comment"># call</span> <span id="L156" class="LineNr">156 </span> e8/call check-ints-equal/disp32 <span id="L157" class="LineNr">157 </span> <span class="Comment"># discard args</span> @@ -215,42 +217,56 @@ if ('onhashchange' in window) { <span id="L160" class="LineNr">160 </span> c3/return <span id="L161" class="LineNr">161 </span> <span id="L162" class="LineNr">162 </span>test-write-appends: -<span id="L163" class="LineNr">163 </span> <span class="Comment"># clear-ostream(Test-ostream)</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># clear-stream(_test-stream)</span> <span id="L164" class="LineNr">164 </span> <span class="Comment"># push args</span> -<span id="L165" class="LineNr">165 </span> 68/push Test-ostream/imm32 +<span id="L165" class="LineNr">165 </span> 68/push _test-stream/imm32 <span id="L166" class="LineNr">166 </span> <span class="Comment"># call</span> -<span id="L167" class="LineNr">167 </span> e8/call clear-ostream/disp32 +<span id="L167" class="LineNr">167 </span> e8/call clear-stream/disp32 <span id="L168" class="LineNr">168 </span> <span class="Comment"># discard args</span> <span id="L169" class="LineNr">169 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L170" class="LineNr">170 </span> <span class="Comment"># write(Test-ostream, "C")</span> +<span id="L170" class="LineNr">170 </span> <span class="Comment"># write(_test-stream, "C")</span> <span id="L171" class="LineNr">171 </span> <span class="Comment"># push args</span> -<span id="L172" class="LineNr">172 </span> 68/push "C"/imm32 -<span id="L173" class="LineNr">173 </span> 68/push Test-ostream/imm32 +<span id="L172" class="LineNr">172 </span> 68/push <span class="Constant">"C"</span>/imm32 +<span id="L173" class="LineNr">173 </span> 68/push _test-stream/imm32 <span id="L174" class="LineNr">174 </span> <span class="Comment"># call</span> <span id="L175" class="LineNr">175 </span> e8/call write/disp32 <span id="L176" class="LineNr">176 </span> <span class="Comment"># discard args</span> <span id="L177" class="LineNr">177 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L178" class="LineNr">178 </span> <span class="Comment"># write(Test-ostream, "D")</span> +<span id="L178" class="LineNr">178 </span> <span class="Comment"># write(_test-stream, "D")</span> <span id="L179" class="LineNr">179 </span> <span class="Comment"># push args</span> -<span id="L180" class="LineNr">180 </span> 68/push "D"/imm32 -<span id="L181" class="LineNr">181 </span> 68/push Test-ostream/imm32 +<span id="L180" class="LineNr">180 </span> 68/push <span class="Constant">"D"</span>/imm32 +<span id="L181" class="LineNr">181 </span> 68/push _test-stream/imm32 <span id="L182" class="LineNr">182 </span> <span class="Comment"># call</span> <span id="L183" class="LineNr">183 </span> e8/call write/disp32 <span id="L184" class="LineNr">184 </span> <span class="Comment"># discard args</span> <span id="L185" class="LineNr">185 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L186" class="LineNr">186 </span> <span class="Comment"># check-ints-equal(*Test-ostream.data, 43/C 44/D 00 00, msg)</span> +<span id="L186" class="LineNr">186 </span> <span class="Comment"># check-ints-equal(*_test-stream->data, 43/C 44/D 00 00, msg)</span> <span id="L187" class="LineNr">187 </span> <span class="Comment"># push args</span> -<span id="L188" class="LineNr">188 </span> 68/push "F - test-write-appends"/imm32 +<span id="L188" class="LineNr">188 </span> 68/push <span class="Constant">"F - test-write-appends"</span>/imm32 <span id="L189" class="LineNr">189 </span> 68/push 0x00004443/imm32/C-D -<span id="L190" class="LineNr">190 </span> <span class="Comment"># push *Test-ostream.data</span> -<span id="L191" class="LineNr">191 </span> b8/copy-to-EAX Test-ostream/imm32 -<span id="L192" class="LineNr">192 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+8)</span> +<span id="L190" class="LineNr">190 </span> <span class="Comment"># push *_test-stream->data</span> +<span id="L191" class="LineNr">191 </span> b8/copy-to-EAX _test-stream/imm32 +<span id="L192" class="LineNr">192 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> <span id="L193" class="LineNr">193 </span> <span class="Comment"># call</span> <span id="L194" class="LineNr">194 </span> e8/call check-ints-equal/disp32 <span id="L195" class="LineNr">195 </span> <span class="Comment"># discard args</span> <span id="L196" class="LineNr">196 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> <span id="L197" class="LineNr">197 </span> <span class="Comment"># end</span> <span id="L198" class="LineNr">198 </span> c3/return +<span id="L199" class="LineNr">199 </span> +<span id="L200" class="LineNr">200 </span>== data +<span id="L201" class="LineNr">201 </span> +<span id="L202" class="LineNr">202 </span>_test-stream: +<span id="L203" class="LineNr">203 </span> <span class="Comment"># current write index</span> +<span id="L204" class="LineNr">204 </span> 00 00 00 00 +<span id="L205" class="LineNr">205 </span> <span class="Comment"># current read index</span> +<span id="L206" class="LineNr">206 </span> 00 00 00 00 +<span id="L207" class="LineNr">207 </span> <span class="Comment"># length (= 8)</span> +<span id="L208" class="LineNr">208 </span> 08 00 00 00 +<span id="L209" class="LineNr">209 </span> <span class="Comment"># data</span> +<span id="L210" class="LineNr">210 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L211" class="LineNr">211 </span> +<span id="L212" class="LineNr">212 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/057stop.subx.html b/html/subx/057stop.subx.html index a985e710..c926ace5 100644 --- a/html/subx/057stop.subx.html +++ b/html/subx/057stop.subx.html @@ -6,18 +6,20 @@ <meta name="Generator" content="Vim/8.0"> <meta name="plugin-version" content="vim7.4_v2"> <meta name="syntax" content="none"> -<meta name="settings" content="number_lines,use_css,pre_wrap,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> <meta name="colorscheme" content="minimal"> <style type="text/css"> <!-- -pre { white-space: pre-wrap; font-family: monospace; color: #aaaaaa; background-color: #080808; } +pre { font-family: monospace; color: #aaaaaa; background-color: #080808; } body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .CommentedCode { color: #6c6c6c; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -83,179 +85,180 @@ if ('onhashchange' in window) { <span id="L26" class="LineNr"> 26 </span><span class="Comment"># returns. (This is a poor man's setjmp/longjmp, if you know what that is.)</span> <span id="L27" class="LineNr"> 27 </span> <span id="L28" class="LineNr"> 28 </span>== code -<span id="L29" class="LineNr"> 29 </span> -<span id="L30" class="LineNr"> 30 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L31" class="LineNr"> 31 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L32" class="LineNr"> 32 </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> -<span id="L33" class="LineNr"> 33 </span> -<span id="L34" class="LineNr"> 34 </span><span class="Comment"># main: (manual test if this is the last file loaded)</span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L31" class="LineNr"> 31 </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> +<span id="L32" class="LineNr"> 32 </span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment"># main:</span> +<span id="L34" class="LineNr"> 34 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> <span id="L35" class="LineNr"> 35 </span><span class="CommentedCode">#? e8/call test-stop-skips-returns-on-exit/disp32</span> -<span id="L36" class="LineNr"> 36 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> -<span id="L37" class="LineNr"> 37 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> -<span id="L38" class="LineNr"> 38 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX Num-test-failures/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> -<span id="L39" class="LineNr"> 39 </span> b8/copy-to-EAX 1/imm32 -<span id="L40" class="LineNr"> 40 </span> cd/syscall 0x80/imm8 -<span id="L41" class="LineNr"> 41 </span> -<span id="L42" class="LineNr"> 42 </span><span class="Comment"># Configure an exit-descriptor for a call pushing 'nbytes' bytes of args to</span> -<span id="L43" class="LineNr"> 43 </span><span class="Comment"># the stack.</span> -<span id="L44" class="LineNr"> 44 </span><span class="Comment"># Ugly that we need to know the size of args, but so it goes.</span> -<span id="L45" class="LineNr"> 45 </span>tailor-exit-descriptor: <span class="Comment"># ed : (address exit-descriptor), nbytes : int -> ()</span> -<span id="L46" class="LineNr"> 46 </span> <span class="Comment"># prolog</span> -<span id="L47" class="LineNr"> 47 </span> 55/push-EBP -<span id="L48" class="LineNr"> 48 </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="L49" class="LineNr"> 49 </span> <span class="Comment"># save registers</span> -<span id="L50" class="LineNr"> 50 </span> 50/push-EAX -<span id="L51" class="LineNr"> 51 </span> 51/push-ECX -<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># EAX = nbytes</span> -<span id="L53" class="LineNr"> 53 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EAX</span> -<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># Let X be the value of ESP in the caller, before the call to tailor-exit-descriptor.</span> -<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># The return address for a call in the caller's body will be at:</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># X-8 if the caller takes 4 bytes of args for the exit-descriptor (add 4 bytes for the return address)</span> -<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># X-12 if the caller takes 8 bytes of args</span> -<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># ..and so on</span> -<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># That's the value we need to return: X-nbytes-4</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Comment">#</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># However, we also need to account for the perturbance to ESP caused by the</span> -<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># call to tailor-exit-descriptor. It pushes 8 bytes of args followed by 4</span> -<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># bytes for the return address and 4 bytes to push EBP above.</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># So EBP at this point is X-16.</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Comment">#</span> -<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># So the return address for the next call in the caller is:</span> -<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># EBP+8 if the caller takes 4 bytes of args</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># EBP+4 if the caller takes 8 bytes of args</span> -<span id="L69" class="LineNr"> 69 </span> <span class="Comment"># EBP if the caller takes 12 bytes of args</span> -<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># EBP-4 if the caller takes 16 bytes of args</span> -<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># ..and so on</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># That's EBP+12-nbytes.</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Comment"># option 1: 6 + 3 bytes</span> -<span id="L74" class="LineNr"> 74 </span><span class="CommentedCode">#? 2d/subtract 3/mod/direct 0/rm32/EAX . . . . . 8/imm32 # subtract from EAX</span> -<span id="L75" class="LineNr"> 75 </span><span class="CommentedCode">#? 8d/copy-address 0/mod/indirect 4/rm32/sib 5/base/EBP 0/index/EAX . 0/r32/EAX . . # copy EBP+EAX to EAX</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Comment"># option 2: 2 + 4 bytes</span> -<span id="L77" class="LineNr"> 77 </span> f7 3/subop/negate 3/mod/direct 0/rm32/EAX <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"># negate EAX</span> -<span id="L78" class="LineNr"> 78 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 5/base/EBP 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EBP+EAX+12 to EAX</span> -<span id="L79" class="LineNr"> 79 </span> <span class="Comment"># copy EAX to ed->target</span> -<span id="L80" class="LineNr"> 80 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ECX</span> -<span id="L81" class="LineNr"> 81 </span> 89/copy 0/mod/indirect 1/rm32/ECX <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"># copy EAX to *ECX</span> -<span id="L82" class="LineNr"> 82 </span> <span class="Comment"># initialize ed->value</span> -<span id="L83" class="LineNr"> 83 </span> c7/copy 1/mod/*+disp8 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 0/imm32 <span class="Comment"># copy to *(ECX+4)</span> -<span id="L84" class="LineNr"> 84 </span> <span class="Comment"># restore registers</span> -<span id="L85" class="LineNr"> 85 </span> 59/pop-to-ECX -<span id="L86" class="LineNr"> 86 </span> 58/pop-to-EAX -<span id="L87" class="LineNr"> 87 </span> <span class="Comment"># epilog</span> -<span id="L88" class="LineNr"> 88 </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="L89" class="LineNr"> 89 </span> 5d/pop-to-EBP -<span id="L90" class="LineNr"> 90 </span> c3/return -<span id="L91" class="LineNr"> 91 </span> -<span id="L92" class="LineNr"> 92 </span>stop: <span class="Comment"># ed : (address exit-descriptor), value : int</span> -<span id="L93" class="LineNr"> 93 </span> <span class="Comment"># no prolog; one way or another, we're going to clobber registers</span> -<span id="L94" class="LineNr"> 94 </span> <span class="Comment"># EAX = ed</span> -<span id="L95" class="LineNr"> 95 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+4) to EAX</span> -<span id="L96" class="LineNr"> 96 </span> <span class="Comment"># exit(value) if ed->target == 0</span> -<span id="L97" class="LineNr"> 97 </span> 81 7/subop/compare 0/mod/indirect 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare *EAX</span> -<span id="L98" class="LineNr"> 98 </span> 75/jump-if-not-equal $stop:fake/disp8 -<span id="L99" class="LineNr"> 99 </span> <span class="Comment"># syscall(exit, value)</span> -<span id="L100" class="LineNr">100 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+8) to EBX</span> -<span id="L101" class="LineNr">101 </span> b8/copy-to-EAX 1/imm32 -<span id="L102" class="LineNr">102 </span> cd/syscall 0x80/imm8 -<span id="L103" class="LineNr">103 </span>$stop:fake: -<span id="L104" class="LineNr">104 </span> <span class="Comment"># ed->value = value+1</span> -<span id="L105" class="LineNr">105 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+8) to ECX</span> -<span id="L106" class="LineNr">106 </span> 41/inc-ECX -<span id="L107" class="LineNr">107 </span> 89/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ECX to *(EAX+4)</span> -<span id="L108" class="LineNr">108 </span> <span class="Comment"># non-local jump to ed->target</span> -<span id="L109" class="LineNr">109 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <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 *EAX to ESP</span> -<span id="L110" class="LineNr">110 </span> c3/return <span class="Comment"># doesn't return to caller</span> -<span id="L111" class="LineNr">111 </span> -<span id="L112" class="LineNr">112 </span>test-stop-skips-returns-on-exit: -<span id="L113" class="LineNr">113 </span> <span class="Comment"># This looks like the standard prolog, but is here for different reasons.</span> -<span id="L114" class="LineNr">114 </span> <span class="Comment"># A function calling 'stop' can't rely on EBP persisting past the call.</span> -<span id="L115" class="LineNr">115 </span> <span class="Comment">#</span> -<span id="L116" class="LineNr">116 </span> <span class="Comment"># Use EBP here as a stable base to refer to locals and arguments from in the</span> -<span id="L117" class="LineNr">117 </span> <span class="Comment"># presence of push/pop/call instructions.</span> -<span id="L118" class="LineNr">118 </span> <span class="Comment"># *Don't* use EBP as a way to restore ESP.</span> -<span id="L119" class="LineNr">119 </span> 55/push-EBP -<span id="L120" class="LineNr">120 </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="L121" class="LineNr">121 </span> <span class="Comment"># Make room for an exit descriptor on the stack. That's almost always the</span> -<span id="L122" class="LineNr">122 </span> <span class="Comment"># right place for it, available only as long as it's legal to use. Once this</span> -<span id="L123" class="LineNr">123 </span> <span class="Comment"># containing function returns we'll need a new exit descriptor.</span> -<span id="L124" class="LineNr">124 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> -<span id="L125" class="LineNr">125 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> -<span id="L126" class="LineNr">126 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> -<span id="L127" class="LineNr">127 </span> <span class="Comment"># Size the exit-descriptor precisely for the next call below, to _test-stop-1.</span> -<span id="L128" class="LineNr">128 </span> <span class="Comment"># tailor-exit-descriptor(ed, 4)</span> -<span id="L129" class="LineNr">129 </span> <span class="Comment"># push args</span> -<span id="L130" class="LineNr">130 </span> 68/push 4/imm32/nbytes-of-args-for-_test-stop-1 -<span id="L131" class="LineNr">131 </span> 50/push-EAX -<span id="L132" class="LineNr">132 </span> <span class="Comment"># call</span> -<span id="L133" class="LineNr">133 </span> e8/call tailor-exit-descriptor/disp32 -<span id="L134" class="LineNr">134 </span> <span class="Comment"># discard args</span> -<span id="L135" class="LineNr">135 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L136" class="LineNr">136 </span> <span class="Comment"># call _test-stop-1(ed)</span> -<span id="L137" class="LineNr">137 </span> <span class="Comment"># push args</span> -<span id="L138" class="LineNr">138 </span> 50/push-EAX -<span id="L139" class="LineNr">139 </span> <span class="Comment"># call</span> -<span id="L140" class="LineNr">140 </span> e8/call _test-stop-1/disp32 -<span id="L141" class="LineNr">141 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> -<span id="L142" class="LineNr">142 </span> <span class="Comment"># restore args</span> -<span id="L143" class="LineNr">143 </span> 58/pop-to-EAX -<span id="L144" class="LineNr">144 </span> <span class="Comment"># check that _test-stop-1 tried to call exit(1)</span> -<span id="L145" class="LineNr">145 </span> <span class="Comment"># check-ints-equal(ed->value, 2, msg) # i.e. stop was called with value 1</span> -<span id="L146" class="LineNr">146 </span> <span class="Comment"># push args</span> -<span id="L147" class="LineNr">147 </span> 68/push "F - test-stop-skips-returns-on-exit"/imm32 -<span id="L148" class="LineNr">148 </span> 68/push 2/imm32 -<span id="L149" class="LineNr">149 </span> <span class="Comment"># push ed->value</span> -<span id="L150" class="LineNr">150 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+4)</span> -<span id="L151" class="LineNr">151 </span> <span class="Comment"># call</span> -<span id="L152" class="LineNr">152 </span> e8/call check-ints-equal/disp32 -<span id="L153" class="LineNr">153 </span> <span class="Comment"># discard args</span> -<span id="L154" class="LineNr">154 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L155" class="LineNr">155 </span> <span class="Comment"># epilog</span> -<span id="L156" class="LineNr">156 </span> 5d/pop-to-EBP -<span id="L157" class="LineNr">157 </span> <span class="Comment"># don't restore ESP from EBP; manually reclaim locals</span> -<span id="L158" class="LineNr">158 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L159" class="LineNr">159 </span> c3/return -<span id="L160" class="LineNr">160 </span> -<span id="L161" class="LineNr">161 </span>_test-stop-1: <span class="Comment"># ed : (address exit-descriptor)</span> -<span id="L162" class="LineNr">162 </span> <span class="Comment"># prolog</span> -<span id="L163" class="LineNr">163 </span> 55/push-EBP -<span id="L164" class="LineNr">164 </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="L165" class="LineNr">165 </span> <span class="Comment"># _test-stop-2(ed)</span> -<span id="L166" class="LineNr">166 </span> <span class="Comment"># push args</span> -<span id="L167" class="LineNr">167 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> -<span id="L168" class="LineNr">168 </span> <span class="Comment"># call</span> -<span id="L169" class="LineNr">169 </span> e8/call _test-stop-2/disp32 -<span id="L170" class="LineNr">170 </span> <span class="SalientComment">## should never get past this point</span> -<span id="L171" class="LineNr">171 </span> <span class="Comment"># discard args</span> -<span id="L172" class="LineNr">172 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L173" class="LineNr">173 </span> <span class="Comment"># signal test failed: check-ints-equal(1, 0, msg)</span> -<span id="L174" class="LineNr">174 </span> <span class="Comment"># push args</span> -<span id="L175" class="LineNr">175 </span> 68/push "F - test-stop-skips-returns-on-exit"/imm32 -<span id="L176" class="LineNr">176 </span> 68/push 0/imm32 -<span id="L177" class="LineNr">177 </span> 68/push 1/imm32 -<span id="L178" class="LineNr">178 </span> <span class="Comment"># call</span> -<span id="L179" class="LineNr">179 </span> e8/call check-ints-equal/disp32 -<span id="L180" class="LineNr">180 </span> <span class="Comment"># discard args</span> -<span id="L181" class="LineNr">181 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L182" class="LineNr">182 </span> <span class="Comment"># epilog</span> -<span id="L183" class="LineNr">183 </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="L184" class="LineNr">184 </span> 5d/pop-to-EBP -<span id="L185" class="LineNr">185 </span> c3/return -<span id="L186" class="LineNr">186 </span> -<span id="L187" class="LineNr">187 </span>_test-stop-2: <span class="Comment"># ed : (address exit-descriptor)</span> -<span id="L188" class="LineNr">188 </span> <span class="Comment"># prolog</span> -<span id="L189" class="LineNr">189 </span> 55/push-EBP -<span id="L190" class="LineNr">190 </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="L191" class="LineNr">191 </span> <span class="Comment"># call stop(ed, 1)</span> -<span id="L192" class="LineNr">192 </span> <span class="Comment"># push args</span> -<span id="L193" class="LineNr">193 </span> 68/push 1/imm32 -<span id="L194" class="LineNr">194 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> -<span id="L195" class="LineNr">195 </span> <span class="Comment"># call</span> -<span id="L196" class="LineNr">196 </span> e8/call stop/disp32 -<span id="L197" class="LineNr">197 </span> <span class="SalientComment">## should never get past this point</span> -<span id="L198" class="LineNr">198 </span> <span class="Comment"># epilog</span> -<span id="L199" class="LineNr">199 </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="L200" class="LineNr">200 </span> 5d/pop-to-EBP -<span id="L201" class="LineNr">201 </span> c3/return +<span id="L36" class="LineNr"> 36 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> +<span id="L37" class="LineNr"> 37 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L38" class="LineNr"> 38 </span> b8/copy-to-EAX 1/imm32 +<span id="L39" class="LineNr"> 39 </span> cd/syscall 0x80/imm8 +<span id="L40" class="LineNr"> 40 </span> +<span id="L41" class="LineNr"> 41 </span><span class="Comment"># Configure an exit-descriptor for a call pushing 'nbytes' bytes of args to</span> +<span id="L42" class="LineNr"> 42 </span><span class="Comment"># the stack.</span> +<span id="L43" class="LineNr"> 43 </span><span class="Comment"># Ugly that we need to know the size of args, but so it goes.</span> +<span id="L44" class="LineNr"> 44 </span>tailor-exit-descriptor: <span class="Comment"># ed : (address exit-descriptor), nbytes : int -> <void></span> +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># prolog</span> +<span id="L46" class="LineNr"> 46 </span> 55/push-EBP +<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"># save registers</span> +<span id="L49" class="LineNr"> 49 </span> 50/push-EAX +<span id="L50" class="LineNr"> 50 </span> 51/push-ECX +<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># EAX = nbytes</span> +<span id="L52" class="LineNr"> 52 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EAX</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># Let X be the value of ESP in the caller, before the call to tailor-exit-descriptor.</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># The return address for a call in the caller's body will be at:</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># X-8 if the caller takes 4 bytes of args for the exit-descriptor (add 4 bytes for the return address)</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># X-12 if the caller takes 8 bytes of args</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># ..and so on</span> +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># That's the value we need to return: X-nbytes-4</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Comment">#</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># However, we also need to account for the perturbance to ESP caused by the</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># call to tailor-exit-descriptor. It pushes 8 bytes of args followed by 4</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># bytes for the return address and 4 bytes to push EBP above.</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># So EBP at this point is X-16.</span> +<span id="L64" class="LineNr"> 64 </span> <span class="Comment">#</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Comment"># So the return address for the next call in the caller is:</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># EBP+8 if the caller takes 4 bytes of args</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># EBP+4 if the caller takes 8 bytes of args</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># EBP if the caller takes 12 bytes of args</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Comment"># EBP-4 if the caller takes 16 bytes of args</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># ..and so on</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># That's EBP+12-nbytes.</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># option 1: 6 + 3 bytes</span> +<span id="L73" class="LineNr"> 73 </span><span class="CommentedCode">#? 2d/subtract 3/mod/direct 0/rm32/EAX . . . . . 8/imm32 # subtract from EAX</span> +<span id="L74" class="LineNr"> 74 </span><span class="CommentedCode">#? 8d/copy-address 0/mod/indirect 4/rm32/sib 5/base/EBP 0/index/EAX . 0/r32/EAX . . # copy EBP+EAX to EAX</span> +<span id="L75" class="LineNr"> 75 </span> <span class="Comment"># option 2: 2 + 4 bytes</span> +<span id="L76" class="LineNr"> 76 </span> f7 3/subop/negate 3/mod/direct 0/rm32/EAX <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"># negate EAX</span> +<span id="L77" class="LineNr"> 77 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 5/base/EBP 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EBP+EAX+12 to EAX</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Comment"># copy EAX to ed->target</span> +<span id="L79" class="LineNr"> 79 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ECX</span> +<span id="L80" class="LineNr"> 80 </span> 89/copy 0/mod/indirect 1/rm32/ECX <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"># copy EAX to *ECX</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Comment"># initialize ed->value</span> +<span id="L82" class="LineNr"> 82 </span> c7/copy 1/mod/*+disp8 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 0/imm32 <span class="Comment"># copy to *(ECX+4)</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Comment"># restore registers</span> +<span id="L84" class="LineNr"> 84 </span> 59/pop-to-ECX +<span id="L85" class="LineNr"> 85 </span> 58/pop-to-EAX +<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># epilog</span> +<span id="L87" class="LineNr"> 87 </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="L88" class="LineNr"> 88 </span> 5d/pop-to-EBP +<span id="L89" class="LineNr"> 89 </span> c3/return +<span id="L90" class="LineNr"> 90 </span> +<span id="L91" class="LineNr"> 91 </span>stop: <span class="Comment"># ed : (address exit-descriptor), value : int</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># no prolog; one way or another, we're going to clobber registers</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Comment"># EAX = ed</span> +<span id="L94" class="LineNr"> 94 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+4) to EAX</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># exit(value) if ed->target == 0</span> +<span id="L96" class="LineNr"> 96 </span> 81 7/subop/compare 0/mod/indirect 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare *EAX</span> +<span id="L97" class="LineNr"> 97 </span> 75/jump-if-not-equal $stop:fake/disp8 +<span id="L98" class="LineNr"> 98 </span> <span class="Comment"># syscall(exit, value)</span> +<span id="L99" class="LineNr"> 99 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+8) to EBX</span> +<span id="L100" class="LineNr">100 </span> b8/copy-to-EAX 1/imm32 +<span id="L101" class="LineNr">101 </span> cd/syscall 0x80/imm8 +<span id="L102" class="LineNr">102 </span>$stop:fake: +<span id="L103" class="LineNr">103 </span> <span class="Comment"># ed->value = value+1</span> +<span id="L104" class="LineNr">104 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+8) to ECX</span> +<span id="L105" class="LineNr">105 </span> 41/inc-ECX +<span id="L106" class="LineNr">106 </span> 89/copy 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ECX to *(EAX+4)</span> +<span id="L107" class="LineNr">107 </span> <span class="Comment"># non-local jump to ed->target</span> +<span id="L108" class="LineNr">108 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <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 *EAX to ESP</span> +<span id="L109" class="LineNr">109 </span> c3/return <span class="Comment"># doesn't return to caller</span> +<span id="L110" class="LineNr">110 </span> +<span id="L111" class="LineNr">111 </span>test-stop-skips-returns-on-exit: +<span id="L112" class="LineNr">112 </span> <span class="Comment"># This looks like the standard prolog, but is here for different reasons.</span> +<span id="L113" class="LineNr">113 </span> <span class="Comment"># A function calling 'stop' can't rely on EBP persisting past the call.</span> +<span id="L114" class="LineNr">114 </span> <span class="Comment">#</span> +<span id="L115" class="LineNr">115 </span> <span class="Comment"># Use EBP here as a stable base to refer to locals and arguments from in the</span> +<span id="L116" class="LineNr">116 </span> <span class="Comment"># presence of push/pop/call instructions.</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment"># *Don't* use EBP as a way to restore ESP.</span> +<span id="L118" class="LineNr">118 </span> 55/push-EBP +<span id="L119" class="LineNr">119 </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="L120" class="LineNr">120 </span> <span class="Comment"># Make room for an exit descriptor on the stack. That's almost always the</span> +<span id="L121" class="LineNr">121 </span> <span class="Comment"># right place for it, available only as long as it's legal to use. Once this</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment"># containing function returns we'll need a new exit descriptor.</span> +<span id="L123" class="LineNr">123 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L124" class="LineNr">124 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L125" class="LineNr">125 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L126" class="LineNr">126 </span> <span class="Comment"># Size the exit-descriptor precisely for the next call below, to _test-stop-1.</span> +<span id="L127" class="LineNr">127 </span> <span class="Comment"># tailor-exit-descriptor(ed, 4)</span> +<span id="L128" class="LineNr">128 </span> <span class="Comment"># push args</span> +<span id="L129" class="LineNr">129 </span> 68/push 4/imm32/nbytes-of-args-for-_test-stop-1 +<span id="L130" class="LineNr">130 </span> 50/push-EAX +<span id="L131" class="LineNr">131 </span> <span class="Comment"># call</span> +<span id="L132" class="LineNr">132 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L133" class="LineNr">133 </span> <span class="Comment"># discard args</span> +<span id="L134" class="LineNr">134 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L135" class="LineNr">135 </span> <span class="Comment"># call _test-stop-1(ed)</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment"># push args</span> +<span id="L137" class="LineNr">137 </span> 50/push-EAX +<span id="L138" class="LineNr">138 </span> <span class="Comment"># call</span> +<span id="L139" class="LineNr">139 </span> e8/call _test-stop-1/disp32 +<span id="L140" class="LineNr">140 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment"># restore args</span> +<span id="L142" class="LineNr">142 </span> 58/pop-to-EAX +<span id="L143" class="LineNr">143 </span> <span class="Comment"># check that _test-stop-1 tried to call exit(1)</span> +<span id="L144" class="LineNr">144 </span> <span class="Comment"># check-ints-equal(ed->value, 2, msg) # i.e. stop was called with value 1</span> +<span id="L145" class="LineNr">145 </span> <span class="Comment"># push args</span> +<span id="L146" class="LineNr">146 </span> 68/push <span class="Constant">"F - test-stop-skips-returns-on-exit"</span>/imm32 +<span id="L147" class="LineNr">147 </span> 68/push 2/imm32 +<span id="L148" class="LineNr">148 </span> <span class="Comment"># push ed->value</span> +<span id="L149" class="LineNr">149 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+4)</span> +<span id="L150" class="LineNr">150 </span> <span class="Comment"># call</span> +<span id="L151" class="LineNr">151 </span> e8/call check-ints-equal/disp32 +<span id="L152" class="LineNr">152 </span> <span class="Comment"># discard args</span> +<span id="L153" class="LineNr">153 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L154" class="LineNr">154 </span> <span class="Comment"># epilog</span> +<span id="L155" class="LineNr">155 </span> 5d/pop-to-EBP +<span id="L156" class="LineNr">156 </span> <span class="Comment"># don't restore ESP from EBP; manually reclaim locals</span> +<span id="L157" class="LineNr">157 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L158" class="LineNr">158 </span> c3/return +<span id="L159" class="LineNr">159 </span> +<span id="L160" class="LineNr">160 </span>_test-stop-1: <span class="Comment"># ed : (address exit-descriptor)</span> +<span id="L161" class="LineNr">161 </span> <span class="Comment"># prolog</span> +<span id="L162" class="LineNr">162 </span> 55/push-EBP +<span id="L163" class="LineNr">163 </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="L164" class="LineNr">164 </span> <span class="Comment"># _test-stop-2(ed)</span> +<span id="L165" class="LineNr">165 </span> <span class="Comment"># push args</span> +<span id="L166" class="LineNr">166 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L167" class="LineNr">167 </span> <span class="Comment"># call</span> +<span id="L168" class="LineNr">168 </span> e8/call _test-stop-2/disp32 +<span id="L169" class="LineNr">169 </span> <span class="SalientComment">## should never get past this point</span> +<span id="L170" class="LineNr">170 </span> <span class="Comment"># discard args</span> +<span id="L171" class="LineNr">171 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L172" class="LineNr">172 </span> <span class="Comment"># signal test failed: check-ints-equal(1, 0, msg)</span> +<span id="L173" class="LineNr">173 </span> <span class="Comment"># push args</span> +<span id="L174" class="LineNr">174 </span> 68/push <span class="Constant">"F - test-stop-skips-returns-on-exit"</span>/imm32 +<span id="L175" class="LineNr">175 </span> 68/push 0/imm32 +<span id="L176" class="LineNr">176 </span> 68/push 1/imm32 +<span id="L177" class="LineNr">177 </span> <span class="Comment"># call</span> +<span id="L178" class="LineNr">178 </span> e8/call check-ints-equal/disp32 +<span id="L179" class="LineNr">179 </span> <span class="Comment"># discard args</span> +<span id="L180" class="LineNr">180 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L181" class="LineNr">181 </span> <span class="Comment"># epilog</span> +<span id="L182" class="LineNr">182 </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="L183" class="LineNr">183 </span> 5d/pop-to-EBP +<span id="L184" class="LineNr">184 </span> c3/return +<span id="L185" class="LineNr">185 </span> +<span id="L186" class="LineNr">186 </span>_test-stop-2: <span class="Comment"># ed : (address exit-descriptor)</span> +<span id="L187" class="LineNr">187 </span> <span class="Comment"># prolog</span> +<span id="L188" class="LineNr">188 </span> 55/push-EBP +<span id="L189" class="LineNr">189 </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="L190" class="LineNr">190 </span> <span class="Comment"># call stop(ed, 1)</span> +<span id="L191" class="LineNr">191 </span> <span class="Comment"># push args</span> +<span id="L192" class="LineNr">192 </span> 68/push 1/imm32 +<span id="L193" class="LineNr">193 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L194" class="LineNr">194 </span> <span class="Comment"># call</span> +<span id="L195" class="LineNr">195 </span> e8/call stop/disp32 +<span id="L196" class="LineNr">196 </span> <span class="SalientComment">## should never get past this point</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment"># epilog</span> +<span id="L198" class="LineNr">198 </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="L199" class="LineNr">199 </span> 5d/pop-to-EBP +<span id="L200" class="LineNr">200 </span> c3/return +<span id="L201" class="LineNr">201 </span> +<span id="L202" class="LineNr">202 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/058read.subx.html b/html/subx/058read.subx.html new file mode 100644 index 00000000..3bc489c9 --- /dev/null +++ b/html/subx/058read.subx.html @@ -0,0 +1,425 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - subx/058read.subx</title> +<meta name="Generator" content="Vim/8.0"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { font-family: monospace; color: #aaaaaa; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } +a { color:#eeeeee; text-decoration: none; } +a:hover { text-decoration: underline; } +* { font-size: 12pt; font-size: 1em; } +.LineNr { color: #444444; } +.Constant { color: #00a0a0; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Comment { color: #9090ff; } +.Comment a { color:#0000ee; text-decoration:underline; } +.SalientComment { color: #00ffff; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment"># read: analogously to write, support reading from in-memory streams in</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment"># addition to file descriptors.</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment">#</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># We can pass it either a file descriptor or an address to a stream. If a</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># file descriptor is passed in, we _read from it using the right syscall. If a</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># stream is passed in (a fake file descriptor), we read from it instead. This</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># lets us initialize input for tests.</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment">#</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># A little counter-intuitively, the output of 'read' ends up in.. a stream. So</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment"># tests end up doing a redundant copy. Why? Well, consider the alternatives:</span> +<span id="L11" class="LineNr"> 11 </span><span class="Comment">#</span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment"># a) Reading into a string, and returning a pointer to the end of the read</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment"># region, or a count of bytes written. Now this count or end pointer must be</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment"># managed separately by the caller, which can be error-prone.</span> +<span id="L15" class="LineNr"> 15 </span><span class="Comment">#</span> +<span id="L16" class="LineNr"> 16 </span><span class="Comment"># b) Having 'read' return a buffer that it allocates. But there's no way to</span> +<span id="L17" class="LineNr"> 17 </span><span class="Comment"># know in advance how large to make the buffer. If you read less than the</span> +<span id="L18" class="LineNr"> 18 </span><span class="Comment"># size of the buffer you again end up needing to manage initialized vs</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment"># uninitialized memory.</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment">#</span> +<span id="L21" class="LineNr"> 21 </span><span class="Comment"># c) Creating more helpful variants like 'read-byte' or 'read-until' which</span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment"># also can take a file descriptor or stream, just like 'write'. But such</span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment"># primitives don't exist in the Linux kernel, so we'd be implementing them</span> +<span id="L24" class="LineNr"> 24 </span><span class="Comment"># somehow, either with more internal buffering or by making multiple</span> +<span id="L25" class="LineNr"> 25 </span><span class="Comment"># syscalls.</span> +<span id="L26" class="LineNr"> 26 </span><span class="Comment">#</span> +<span id="L27" class="LineNr"> 27 </span><span class="Comment"># Reading into a stream avoids these problems. The buffer is externally</span> +<span id="L28" class="LineNr"> 28 </span><span class="Comment"># provided and the caller has control over where it's allocated, its lifetime,</span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment"># and so on. The buffer's read and write pointers are internal to it so it's</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment"># easier to keep in a consistent state. And it can now be passed directly to</span> +<span id="L31" class="LineNr"> 31 </span><span class="Comment"># helpers like 'read-byte' or 'read-until' that only need to support streams,</span> +<span id="L32" class="LineNr"> 32 </span><span class="Comment"># never file descriptors.</span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment">#</span> +<span id="L34" class="LineNr"> 34 </span><span class="Comment"># Like with 'write', we assume our data segment will never begin at an address</span> +<span id="L35" class="LineNr"> 35 </span><span class="Comment"># shorter than 0x08000000, so any smaller arguments are assumed to be real</span> +<span id="L36" class="LineNr"> 36 </span><span class="Comment"># file descriptors.</span> +<span id="L37" class="LineNr"> 37 </span><span class="Comment">#</span> +<span id="L38" class="LineNr"> 38 </span><span class="Comment"># As a reminder, a stream looks like this:</span> +<span id="L39" class="LineNr"> 39 </span><span class="Comment"># write: int # index at which to write to next</span> +<span id="L40" class="LineNr"> 40 </span><span class="Comment"># read: int # index at which to read next</span> +<span id="L41" class="LineNr"> 41 </span><span class="Comment"># data: (array byte) # prefixed by length as usual</span> +<span id="L42" class="LineNr"> 42 </span> +<span id="L43" class="LineNr"> 43 </span>== code +<span id="L44" class="LineNr"> 44 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L45" class="LineNr"> 45 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L46" class="LineNr"> 46 </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> +<span id="L47" class="LineNr"> 47 </span> +<span id="L48" class="LineNr"> 48 </span><span class="Comment"># main:</span> +<span id="L49" class="LineNr"> 49 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> +<span id="L51" class="LineNr"> 51 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L52" class="LineNr"> 52 </span> b8/copy-to-EAX 1/imm32 +<span id="L53" class="LineNr"> 53 </span> cd/syscall 0x80/imm8 +<span id="L54" class="LineNr"> 54 </span> +<span id="L55" class="LineNr"> 55 </span>read: <span class="Comment"># f : fd or (address stream), s : (address stream) -> num-bytes-read/EAX</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># prolog</span> +<span id="L57" class="LineNr"> 57 </span> 55/push-EBP +<span id="L58" class="LineNr"> 58 </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="L59" class="LineNr"> 59 </span> <span class="SalientComment">## if (f < 0x08000000) return _read(f, s) # f can't be a user-mode address, so treat it as a kernel file descriptor</span> +<span id="L60" class="LineNr"> 60 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 0x08000000/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L61" class="LineNr"> 61 </span> 7d/jump-if-greater-or-equal $read:fake/disp8 +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># push args</span> +<span id="L63" class="LineNr"> 63 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L64" class="LineNr"> 64 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L65" class="LineNr"> 65 </span> <span class="Comment"># call</span> +<span id="L66" class="LineNr"> 66 </span> e8/call _read/disp32 +<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># discard args</span> +<span id="L68" class="LineNr"> 68 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L69" class="LineNr"> 69 </span> <span class="Comment"># return</span> +<span id="L70" class="LineNr"> 70 </span> eb/jump $read:end/disp8 +<span id="L71" class="LineNr"> 71 </span>$read:fake: +<span id="L72" class="LineNr"> 72 </span> <span class="SalientComment">## otherwise, treat 'f' as a stream to scan from</span> +<span id="L73" class="LineNr"> 73 </span> <span class="Comment"># save registers</span> +<span id="L74" class="LineNr"> 74 </span> 56/push-ESI +<span id="L75" class="LineNr"> 75 </span> 57/push-EDI +<span id="L76" class="LineNr"> 76 </span> <span class="Comment"># ESI = f</span> +<span id="L77" class="LineNr"> 77 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ESI</span> +<span id="L78" class="LineNr"> 78 </span> <span class="Comment"># EDI = s</span> +<span id="L79" class="LineNr"> 79 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> +<span id="L80" class="LineNr"> 80 </span> <span class="Comment"># EAX = _append-4(out = &s->data[s->write], outend = &s->data[s->length],</span> +<span id="L81" class="LineNr"> 81 </span> <span class="Comment"># in = &f->data[f->read], inend = &f->data[f->write])</span> +<span id="L82" class="LineNr"> 82 </span> <span class="Comment"># push &f->data[f->write]</span> +<span id="L83" class="LineNr"> 83 </span> 8b/copy 0/mod/indirect 6/rm32/ESI <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"># copy *ESI to EAX</span> +<span id="L84" class="LineNr"> 84 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+EAX+12 to EAX</span> +<span id="L85" class="LineNr"> 85 </span> 50/push-EAX +<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># push &f->data[f->read]</span> +<span id="L87" class="LineNr"> 87 </span> 8b/copy 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESI+4) to EAX</span> +<span id="L88" class="LineNr"> 88 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+EAX+12 to EAX</span> +<span id="L89" class="LineNr"> 89 </span> 50/push-EAX +<span id="L90" class="LineNr"> 90 </span> <span class="Comment"># push &s->data[s->length]</span> +<span id="L91" class="LineNr"> 91 </span> 8b/copy 1/mod/*+disp8 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EDI+8) to EAX</span> +<span id="L92" class="LineNr"> 92 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+EAX+12 to EAX</span> +<span id="L93" class="LineNr"> 93 </span> 50/push-EAX +<span id="L94" class="LineNr"> 94 </span> <span class="Comment"># push &s->data[s->write]</span> +<span id="L95" class="LineNr"> 95 </span> 8b/copy 0/mod/indirect 7/rm32/EDI <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"># copy *EDI to EAX</span> +<span id="L96" class="LineNr"> 96 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+EAX+12 to EAX</span> +<span id="L97" class="LineNr"> 97 </span> 50/push-EAX +<span id="L98" class="LineNr"> 98 </span> <span class="Comment"># call</span> +<span id="L99" class="LineNr"> 99 </span> e8/call _append-4/disp32 +<span id="L100" class="LineNr">100 </span> <span class="Comment"># discard args</span> +<span id="L101" class="LineNr">101 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L102" class="LineNr">102 </span> <span class="Comment"># s->write += EAX</span> +<span id="L103" class="LineNr">103 </span> 01/add 0/mod/indirect 7/rm32/EDI <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"># add EAX to *EDI</span> +<span id="L104" class="LineNr">104 </span> <span class="Comment"># f.read += EAX</span> +<span id="L105" class="LineNr">105 </span> 01/add 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># add EAX to *(ESI+4)</span> +<span id="L106" class="LineNr">106 </span> <span class="Comment"># restore registers</span> +<span id="L107" class="LineNr">107 </span> 5f/pop-to-EDI +<span id="L108" class="LineNr">108 </span> 5e/pop-to-ESI +<span id="L109" class="LineNr">109 </span>$read:end: +<span id="L110" class="LineNr">110 </span> <span class="Comment"># epilog</span> +<span id="L111" class="LineNr">111 </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="L112" class="LineNr">112 </span> 5d/pop-to-EBP +<span id="L113" class="LineNr">113 </span> c3/return +<span id="L114" class="LineNr">114 </span> +<span id="L115" class="LineNr">115 </span><span class="SalientComment">## helpers</span> +<span id="L116" class="LineNr">116 </span> +<span id="L117" class="LineNr">117 </span><span class="Comment"># idea: a clear-if-empty method on streams that clears only if f.read == f.write</span> +<span id="L118" class="LineNr">118 </span><span class="Comment"># Unclear how I'd use it, though. Callers seem to need the check anyway.</span> +<span id="L119" class="LineNr">119 </span><span class="Comment"># Maybe a better helper would be 'empty-stream?'</span> +<span id="L120" class="LineNr">120 </span> +<span id="L121" class="LineNr">121 </span>_read: <span class="Comment"># fd : int, s : (address stream) -> num-bytes-read/EAX</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment"># prolog</span> +<span id="L123" class="LineNr">123 </span> 55/push-EBP +<span id="L124" class="LineNr">124 </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="L125" class="LineNr">125 </span> <span class="Comment"># save registers</span> +<span id="L126" class="LineNr">126 </span> 51/push-ECX +<span id="L127" class="LineNr">127 </span> 52/push-EDX +<span id="L128" class="LineNr">128 </span> 53/push-EBX +<span id="L129" class="LineNr">129 </span> 56/push-ESI +<span id="L130" class="LineNr">130 </span> <span class="Comment"># ESI = s</span> +<span id="L131" class="LineNr">131 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> +<span id="L132" class="LineNr">132 </span> <span class="Comment"># EAX = s->write</span> +<span id="L133" class="LineNr">133 </span> 8b/copy 0/mod/indirect 6/rm32/ESI <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"># copy *ESI to EAX</span> +<span id="L134" class="LineNr">134 </span> <span class="Comment"># EDX = s->length</span> +<span id="L135" class="LineNr">135 </span> 8b/copy 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 2/r32/EDX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESI+8) to EDX</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment"># syscall(read, fd, &s->data[s->write], s->length - s->write)</span> +<span id="L137" class="LineNr">137 </span> <span class="Comment"># fd : EBX</span> +<span id="L138" class="LineNr">138 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EBX</span> +<span id="L139" class="LineNr">139 </span> <span class="Comment"># data : ECX = &s->data[s->write]</span> +<span id="L140" class="LineNr">140 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+EAX+12 to ECX</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment"># size : EDX = s->length - s->write</span> +<span id="L142" class="LineNr">142 </span> 29/subtract 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"># subtract EAX from EDX</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment"># syscall</span> +<span id="L144" class="LineNr">144 </span> b8/copy-to-EAX 3/imm32/read +<span id="L145" class="LineNr">145 </span> cd/syscall 0x80/imm8 +<span id="L146" class="LineNr">146 </span> <span class="Comment"># add the result EAX to s->write</span> +<span id="L147" class="LineNr">147 </span> 01/add 0/mod/indirect 6/rm32/ESI <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"># add EAX to *ESI</span> +<span id="L148" class="LineNr">148 </span> <span class="Comment"># restore registers</span> +<span id="L149" class="LineNr">149 </span> 5e/pop-to-ESI +<span id="L150" class="LineNr">150 </span> 5b/pop-to-EBX +<span id="L151" class="LineNr">151 </span> 5a/pop-to-EDX +<span id="L152" class="LineNr">152 </span> 59/pop-to-ECX +<span id="L153" class="LineNr">153 </span> <span class="Comment"># epilog</span> +<span id="L154" class="LineNr">154 </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="L155" class="LineNr">155 </span> 5d/pop-to-EBP +<span id="L156" class="LineNr">156 </span> c3/return +<span id="L157" class="LineNr">157 </span> +<span id="L158" class="LineNr">158 </span> <span class="Comment"># Two options:</span> +<span id="L159" class="LineNr">159 </span> <span class="Comment"># 1 (what we have above):</span> +<span id="L160" class="LineNr">160 </span> <span class="Comment"># ECX = s</span> +<span id="L161" class="LineNr">161 </span> <span class="Comment"># EAX = s->write</span> +<span id="L162" class="LineNr">162 </span> <span class="Comment"># EDX = s->length</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># # syscall</span> +<span id="L164" class="LineNr">164 </span> <span class="Comment"># ECX = lea ECX+EAX+12</span> +<span id="L165" class="LineNr">165 </span> <span class="Comment"># EDX = sub EDX EAX</span> +<span id="L166" class="LineNr">166 </span> <span class="Comment">#</span> +<span id="L167" class="LineNr">167 </span> <span class="Comment"># 2:</span> +<span id="L168" class="LineNr">168 </span> <span class="Comment"># ECX = s</span> +<span id="L169" class="LineNr">169 </span> <span class="Comment"># EDX = s->length</span> +<span id="L170" class="LineNr">170 </span> <span class="Comment"># ECX = &s->data</span> +<span id="L171" class="LineNr">171 </span> <span class="Comment"># # syscall</span> +<span id="L172" class="LineNr">172 </span> <span class="Comment"># ECX = add ECX, s->write</span> +<span id="L173" class="LineNr">173 </span> <span class="Comment"># EDX = sub EDX, s->write</span> +<span id="L174" class="LineNr">174 </span> <span class="Comment">#</span> +<span id="L175" class="LineNr">175 </span> <span class="Comment"># Not much to choose between the two? Option 2 performs a duplicate load to</span> +<span id="L176" class="LineNr">176 </span> <span class="Comment"># use one less register, but doesn't increase the amount of spilling (ECX</span> +<span id="L177" class="LineNr">177 </span> <span class="Comment"># and EDX must be used, and EAX must be clobbered anyway).</span> +<span id="L178" class="LineNr">178 </span> +<span id="L179" class="LineNr">179 </span><span class="SalientComment">## tests</span> +<span id="L180" class="LineNr">180 </span> +<span id="L181" class="LineNr">181 </span>test-read-single: +<span id="L182" class="LineNr">182 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L183" class="LineNr">183 </span> <span class="Comment"># push args</span> +<span id="L184" class="LineNr">184 </span> 68/push _test-stream/imm32 +<span id="L185" class="LineNr">185 </span> <span class="Comment"># call</span> +<span id="L186" class="LineNr">186 </span> e8/call clear-stream/disp32 +<span id="L187" class="LineNr">187 </span> <span class="Comment"># discard args</span> +<span id="L188" class="LineNr">188 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L189" class="LineNr">189 </span> <span class="Comment"># clear-stream(_test-stream-buffer)</span> +<span id="L190" class="LineNr">190 </span> <span class="Comment"># push args</span> +<span id="L191" class="LineNr">191 </span> 68/push _test-stream-buffer/imm32 +<span id="L192" class="LineNr">192 </span> <span class="Comment"># call</span> +<span id="L193" class="LineNr">193 </span> e8/call clear-stream/disp32 +<span id="L194" class="LineNr">194 </span> <span class="Comment"># discard args</span> +<span id="L195" class="LineNr">195 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L196" class="LineNr">196 </span> <span class="Comment"># write(_test-stream, "Ab")</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment"># push args</span> +<span id="L198" class="LineNr">198 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L199" class="LineNr">199 </span> 68/push _test-stream/imm32 +<span id="L200" class="LineNr">200 </span> <span class="Comment"># call</span> +<span id="L201" class="LineNr">201 </span> e8/call write/disp32 +<span id="L202" class="LineNr">202 </span> <span class="Comment"># discard args</span> +<span id="L203" class="LineNr">203 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L204" class="LineNr">204 </span> <span class="Comment"># read(_test-stream, _test-stream-buffer)</span> +<span id="L205" class="LineNr">205 </span> <span class="Comment"># push args</span> +<span id="L206" class="LineNr">206 </span> 68/push _test-stream-buffer/imm32 +<span id="L207" class="LineNr">207 </span> 68/push _test-stream/imm32 +<span id="L208" class="LineNr">208 </span> <span class="Comment"># call</span> +<span id="L209" class="LineNr">209 </span> e8/call read/disp32 +<span id="L210" class="LineNr">210 </span> <span class="Comment"># discard args</span> +<span id="L211" class="LineNr">211 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L212" class="LineNr">212 </span> <span class="Comment"># check-ints-equal(EAX, 2)</span> +<span id="L213" class="LineNr">213 </span> <span class="Comment"># push args</span> +<span id="L214" class="LineNr">214 </span> 68/push <span class="Constant">"F - test-read-single: return EAX"</span>/imm32 +<span id="L215" class="LineNr">215 </span> 68/push 2/imm32 +<span id="L216" class="LineNr">216 </span> 50/push-EAX +<span id="L217" class="LineNr">217 </span> <span class="Comment"># call</span> +<span id="L218" class="LineNr">218 </span> e8/call check-ints-equal/disp32 +<span id="L219" class="LineNr">219 </span> <span class="Comment"># discard args</span> +<span id="L220" class="LineNr">220 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L221" class="LineNr">221 </span> <span class="Comment"># check-ints-equal(*_test-stream-buffer->data, 41/A 62/b 00 00, msg)</span> +<span id="L222" class="LineNr">222 </span> <span class="Comment"># push args</span> +<span id="L223" class="LineNr">223 </span> 68/push <span class="Constant">"F - test-read-single"</span>/imm32 +<span id="L224" class="LineNr">224 </span> 68/push 0x006241/imm32/<span class="Special">Ab</span> +<span id="L225" class="LineNr">225 </span> <span class="Comment"># push *_test-stream-buffer->data</span> +<span id="L226" class="LineNr">226 </span> b8/copy-to-EAX _test-stream-buffer/imm32 +<span id="L227" class="LineNr">227 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L228" class="LineNr">228 </span> <span class="Comment"># call</span> +<span id="L229" class="LineNr">229 </span> e8/call check-ints-equal/disp32 +<span id="L230" class="LineNr">230 </span> <span class="Comment"># discard args</span> +<span id="L231" class="LineNr">231 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L232" class="LineNr">232 </span> <span class="Comment"># end</span> +<span id="L233" class="LineNr">233 </span> c3/return +<span id="L234" class="LineNr">234 </span> +<span id="L235" class="LineNr">235 </span>test-read-is-stateful: +<span id="L236" class="LineNr">236 </span> <span class="SalientComment">## make two consecutive reads, check that their results are appended</span> +<span id="L237" class="LineNr">237 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L238" class="LineNr">238 </span> <span class="Comment"># push args</span> +<span id="L239" class="LineNr">239 </span> 68/push _test-stream/imm32 +<span id="L240" class="LineNr">240 </span> <span class="Comment"># call</span> +<span id="L241" class="LineNr">241 </span> e8/call clear-stream/disp32 +<span id="L242" class="LineNr">242 </span> <span class="Comment"># discard args</span> +<span id="L243" class="LineNr">243 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L244" class="LineNr">244 </span> <span class="Comment"># clear-stream(_test-stream-buffer)</span> +<span id="L245" class="LineNr">245 </span> <span class="Comment"># push args</span> +<span id="L246" class="LineNr">246 </span> 68/push _test-stream-buffer/imm32 +<span id="L247" class="LineNr">247 </span> <span class="Comment"># call</span> +<span id="L248" class="LineNr">248 </span> e8/call clear-stream/disp32 +<span id="L249" class="LineNr">249 </span> <span class="Comment"># discard args</span> +<span id="L250" class="LineNr">250 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L251" class="LineNr">251 </span> <span class="Comment"># write(_test-stream, "C")</span> +<span id="L252" class="LineNr">252 </span> <span class="Comment"># push args</span> +<span id="L253" class="LineNr">253 </span> 68/push <span class="Constant">"C"</span>/imm32 +<span id="L254" class="LineNr">254 </span> 68/push _test-stream/imm32 +<span id="L255" class="LineNr">255 </span> <span class="Comment"># call</span> +<span id="L256" class="LineNr">256 </span> e8/call write/disp32 +<span id="L257" class="LineNr">257 </span> <span class="Comment"># discard args</span> +<span id="L258" class="LineNr">258 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L259" class="LineNr">259 </span> <span class="Comment"># read(_test-stream, _test-stream-buffer)</span> +<span id="L260" class="LineNr">260 </span> <span class="Comment"># push args</span> +<span id="L261" class="LineNr">261 </span> 68/push _test-stream-buffer/imm32 +<span id="L262" class="LineNr">262 </span> 68/push _test-stream/imm32 +<span id="L263" class="LineNr">263 </span> <span class="Comment"># call</span> +<span id="L264" class="LineNr">264 </span> e8/call read/disp32 +<span id="L265" class="LineNr">265 </span> <span class="Comment"># discard args</span> +<span id="L266" class="LineNr">266 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L267" class="LineNr">267 </span> <span class="Comment"># write(_test-stream, "D")</span> +<span id="L268" class="LineNr">268 </span> <span class="Comment"># push args</span> +<span id="L269" class="LineNr">269 </span> 68/push <span class="Constant">"D"</span>/imm32 +<span id="L270" class="LineNr">270 </span> 68/push _test-stream/imm32 +<span id="L271" class="LineNr">271 </span> <span class="Comment"># call</span> +<span id="L272" class="LineNr">272 </span> e8/call write/disp32 +<span id="L273" class="LineNr">273 </span> <span class="Comment"># discard args</span> +<span id="L274" class="LineNr">274 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L275" class="LineNr">275 </span> <span class="Comment"># read(_test-stream, _test-stream-buffer)</span> +<span id="L276" class="LineNr">276 </span> <span class="Comment"># push args</span> +<span id="L277" class="LineNr">277 </span> 68/push _test-stream-buffer/imm32 +<span id="L278" class="LineNr">278 </span> 68/push _test-stream/imm32 +<span id="L279" class="LineNr">279 </span> <span class="Comment"># call</span> +<span id="L280" class="LineNr">280 </span> e8/call read/disp32 +<span id="L281" class="LineNr">281 </span> <span class="Comment"># discard args</span> +<span id="L282" class="LineNr">282 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L283" class="LineNr">283 </span> <span class="Comment"># check-ints-equal(*_test-stream-buffer->data, 43/C 44/D 00 00, msg)</span> +<span id="L284" class="LineNr">284 </span> <span class="Comment"># push args</span> +<span id="L285" class="LineNr">285 </span> 68/push <span class="Constant">"F - test-read-is-stateful"</span>/imm32 +<span id="L286" class="LineNr">286 </span> 68/push 0x00004443/imm32/C-D +<span id="L287" class="LineNr">287 </span> <span class="Comment"># push *_test-stream-buffer->data</span> +<span id="L288" class="LineNr">288 </span> b8/copy-to-EAX _test-stream-buffer/imm32 +<span id="L289" class="LineNr">289 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L290" class="LineNr">290 </span> <span class="Comment"># call</span> +<span id="L291" class="LineNr">291 </span> e8/call check-ints-equal/disp32 +<span id="L292" class="LineNr">292 </span> <span class="Comment"># discard args</span> +<span id="L293" class="LineNr">293 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L294" class="LineNr">294 </span> <span class="Comment"># end</span> +<span id="L295" class="LineNr">295 </span> c3/return +<span id="L296" class="LineNr">296 </span> +<span id="L297" class="LineNr">297 </span>test-read-returns-0-on-end-of-file: +<span id="L298" class="LineNr">298 </span> <span class="SalientComment">## read after hitting end-of-file, check that result is 0</span> +<span id="L299" class="LineNr">299 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L300" class="LineNr">300 </span> <span class="Comment"># push args</span> +<span id="L301" class="LineNr">301 </span> 68/push _test-stream/imm32 +<span id="L302" class="LineNr">302 </span> <span class="Comment"># call</span> +<span id="L303" class="LineNr">303 </span> e8/call clear-stream/disp32 +<span id="L304" class="LineNr">304 </span> <span class="Comment"># discard args</span> +<span id="L305" class="LineNr">305 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L306" class="LineNr">306 </span> <span class="Comment"># clear-stream(_test-stream-buffer)</span> +<span id="L307" class="LineNr">307 </span> <span class="Comment"># push args</span> +<span id="L308" class="LineNr">308 </span> 68/push _test-stream-buffer/imm32 +<span id="L309" class="LineNr">309 </span> <span class="Comment"># call</span> +<span id="L310" class="LineNr">310 </span> e8/call clear-stream/disp32 +<span id="L311" class="LineNr">311 </span> <span class="Comment"># discard args</span> +<span id="L312" class="LineNr">312 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L313" class="LineNr">313 </span> <span class="Comment"># write(_test-stream, "Ab")</span> +<span id="L314" class="LineNr">314 </span> <span class="Comment"># push args</span> +<span id="L315" class="LineNr">315 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L316" class="LineNr">316 </span> 68/push _test-stream/imm32 +<span id="L317" class="LineNr">317 </span> <span class="Comment"># call</span> +<span id="L318" class="LineNr">318 </span> e8/call write/disp32 +<span id="L319" class="LineNr">319 </span> <span class="Comment"># discard args</span> +<span id="L320" class="LineNr">320 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L321" class="LineNr">321 </span> <span class="SalientComment">## first read gets to end-of-file</span> +<span id="L322" class="LineNr">322 </span> <span class="Comment"># read(_test-stream, _test-stream-buffer)</span> +<span id="L323" class="LineNr">323 </span> <span class="Comment"># push args</span> +<span id="L324" class="LineNr">324 </span> 68/push _test-stream-buffer/imm32 +<span id="L325" class="LineNr">325 </span> 68/push _test-stream/imm32 +<span id="L326" class="LineNr">326 </span> <span class="Comment"># call</span> +<span id="L327" class="LineNr">327 </span> e8/call read/disp32 +<span id="L328" class="LineNr">328 </span> <span class="Comment"># discard args</span> +<span id="L329" class="LineNr">329 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L330" class="LineNr">330 </span> <span class="SalientComment">## second read</span> +<span id="L331" class="LineNr">331 </span> <span class="Comment"># read(_test-stream, _test-stream-buffer)</span> +<span id="L332" class="LineNr">332 </span> <span class="Comment"># push args</span> +<span id="L333" class="LineNr">333 </span> 68/push _test-stream-buffer/imm32 +<span id="L334" class="LineNr">334 </span> 68/push _test-stream/imm32 +<span id="L335" class="LineNr">335 </span> <span class="Comment"># call</span> +<span id="L336" class="LineNr">336 </span> e8/call read/disp32 +<span id="L337" class="LineNr">337 </span> <span class="Comment"># discard args</span> +<span id="L338" class="LineNr">338 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L339" class="LineNr">339 </span> <span class="Comment"># check-ints-equal(EAX, 0)</span> +<span id="L340" class="LineNr">340 </span> <span class="Comment"># push args</span> +<span id="L341" class="LineNr">341 </span> 68/push <span class="Constant">"F - test-read-returns-0-on-end-of-file"</span>/imm32 +<span id="L342" class="LineNr">342 </span> 68/push 0/imm32 +<span id="L343" class="LineNr">343 </span> 50/push-EAX +<span id="L344" class="LineNr">344 </span> <span class="Comment"># call</span> +<span id="L345" class="LineNr">345 </span> e8/call check-ints-equal/disp32 +<span id="L346" class="LineNr">346 </span> <span class="Comment"># discard args</span> +<span id="L347" class="LineNr">347 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L348" class="LineNr">348 </span> <span class="Comment"># end</span> +<span id="L349" class="LineNr">349 </span> c3/return +<span id="L350" class="LineNr">350 </span> +<span id="L351" class="LineNr">351 </span>== data +<span id="L352" class="LineNr">352 </span> +<span id="L353" class="LineNr">353 </span>_test-stream-buffer: +<span id="L354" class="LineNr">354 </span> <span class="Comment"># current write index</span> +<span id="L355" class="LineNr">355 </span> 00 00 00 00 +<span id="L356" class="LineNr">356 </span> <span class="Comment"># current read index</span> +<span id="L357" class="LineNr">357 </span> 00 00 00 00 +<span id="L358" class="LineNr">358 </span> <span class="Comment"># length (= 8)</span> +<span id="L359" class="LineNr">359 </span> 08 00 00 00 +<span id="L360" class="LineNr">360 </span> <span class="Comment"># data</span> +<span id="L361" class="LineNr">361 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L362" class="LineNr">362 </span> +<span id="L363" class="LineNr">363 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/subx/059read-byte.subx.html b/html/subx/059read-byte.subx.html new file mode 100644 index 00000000..070d5afb --- /dev/null +++ b/html/subx/059read-byte.subx.html @@ -0,0 +1,310 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - subx/059read-byte.subx</title> +<meta name="Generator" content="Vim/8.0"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { font-family: monospace; color: #aaaaaa; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } +a { color:#eeeeee; text-decoration: none; } +a:hover { text-decoration: underline; } +* { font-size: 12pt; font-size: 1em; } +.CommentedCode { color: #6c6c6c; } +.LineNr { color: #444444; } +.Constant { color: #00a0a0; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Comment { color: #9090ff; } +.Comment a { color:#0000ee; text-decoration:underline; } +.SalientComment { color: #00ffff; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment"># read-byte: one higher-level abstraction atop 'read'.</span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment">#</span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment"># There are many situations where 'read' is a lot to manage, and we need</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># to abstract some details away. One of them is when we want to read a file</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># character by character. In this situation we follow C's FILE data structure,</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># which manages the underlying file descriptor together with the buffer it</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># reads into. We call our version 'buffered-file'. Should be useful with other</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># primitives as well, in later layers.</span> +<span id="L9" class="LineNr"> 9 </span> +<span id="L10" class="LineNr"> 10 </span>== data +<span id="L11" class="LineNr"> 11 </span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment"># The buffered file for standard input. Also illustrates the layout for</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment"># buffered-file.</span> +<span id="L14" class="LineNr"> 14 </span> +<span id="L15" class="LineNr"> 15 </span><span class="Special">Stdin</span>: +<span id="L16" class="LineNr"> 16 </span> <span class="Comment"># file descriptor or (address stream)</span> +<span id="L17" class="LineNr"> 17 </span> 00 00 00 00 <span class="Comment"># 0 = standard input</span> +<span id="L18" class="LineNr"> 18 </span> <span class="Comment"># current write index</span> +<span id="L19" class="LineNr"> 19 </span> 00 00 00 00 +<span id="L20" class="LineNr"> 20 </span> <span class="Comment"># current read index</span> +<span id="L21" class="LineNr"> 21 </span> 00 00 00 00 +<span id="L22" class="LineNr"> 22 </span> <span class="Comment"># length (8)</span> +<span id="L23" class="LineNr"> 23 </span> 08 00 00 00 +<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># data</span> +<span id="L25" class="LineNr"> 25 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L26" class="LineNr"> 26 </span> +<span id="L27" class="LineNr"> 27 </span><span class="Comment"># TODO: 8 bytes is too small. We'll need to grow the buffer for efficiency.</span> +<span id="L28" class="LineNr"> 28 </span> +<span id="L29" class="LineNr"> 29 </span>== code +<span id="L30" class="LineNr"> 30 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L31" class="LineNr"> 31 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L32" class="LineNr"> 32 </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> +<span id="L33" class="LineNr"> 33 </span> +<span id="L34" class="LineNr"> 34 </span><span class="Comment"># main:</span> +<span id="L35" class="LineNr"> 35 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L36" class="LineNr"> 36 </span><span class="CommentedCode">#? e8/call test-read-byte-multiple/disp32</span> +<span id="L37" class="LineNr"> 37 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> +<span id="L38" class="LineNr"> 38 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L39" class="LineNr"> 39 </span> b8/copy-to-EAX 1/imm32 +<span id="L40" class="LineNr"> 40 </span> cd/syscall 0x80/imm8 +<span id="L41" class="LineNr"> 41 </span> +<span id="L42" class="LineNr"> 42 </span><span class="Comment"># return next byte value in EAX, with top 3 bytes cleared.</span> +<span id="L43" class="LineNr"> 43 </span><span class="Comment"># On EOF, return 0xffffffff.</span> +<span id="L44" class="LineNr"> 44 </span>read-byte: <span class="Comment"># f : (address buffered-file) -> byte/EAX</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># prolog</span> +<span id="L46" class="LineNr"> 46 </span> 55/push-EBP +<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"># save registers</span> +<span id="L49" class="LineNr"> 49 </span> 51/push-ECX +<span id="L50" class="LineNr"> 50 </span> 56/push-ESI +<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># ESI = f</span> +<span id="L52" class="LineNr"> 52 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ESI</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># ECX = f->read</span> +<span id="L54" class="LineNr"> 54 </span> 8b/copy 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESI+8) to ECX</span> +<span id="L55" class="LineNr"> 55 </span> <span class="SalientComment">## if (f->read < f->write) read byte from stream</span> +<span id="L56" class="LineNr"> 56 </span> 3b/compare 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># compare ECX with *(ESI+4)</span> +<span id="L57" class="LineNr"> 57 </span> 7c/jump-if-lesser $read-byte:from-stream/disp8 +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># clear-stream(stream = f+4)</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># push args</span> +<span id="L60" class="LineNr"> 60 </span> 8d/copy-address 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+4 to EAX</span> +<span id="L61" class="LineNr"> 61 </span> 50/push-EAX +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># call</span> +<span id="L63" class="LineNr"> 63 </span> e8/call clear-stream/disp32 +<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># discard args</span> +<span id="L65" class="LineNr"> 65 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># EAX = read(f->fd, stream = f+4)</span> +<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># push args</span> +<span id="L68" class="LineNr"> 68 </span> 50/push-EAX +<span id="L69" class="LineNr"> 69 </span> ff 6/subop/push 0/mod/indirect 6/rm32/ESI <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 *ESI</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># call</span> +<span id="L71" class="LineNr"> 71 </span> e8/call read/disp32 +<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># discard args</span> +<span id="L73" class="LineNr"> 73 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Comment"># if EAX = 0 return 0xffffffff</span> +<span id="L75" class="LineNr"> 75 </span> 81 7/subop/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare EAX</span> +<span id="L76" class="LineNr"> 76 </span> 75/jump-if-not-equal $read-byte:from-stream/disp8 +<span id="L77" class="LineNr"> 77 </span> b8/copy-to-EAX 0xffffffff/imm32 +<span id="L78" class="LineNr"> 78 </span> eb/jump $read-byte:end/disp8 +<span id="L79" class="LineNr"> 79 </span>$read-byte:from-stream: +<span id="L80" class="LineNr"> 80 </span> <span class="Comment"># AL = f->data[f->read]</span> +<span id="L81" class="LineNr"> 81 </span> 31/xor 3/mod/direct 0/rm32/EAX <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"># clear EAX</span> +<span id="L82" class="LineNr"> 82 </span> 8a/copy-byte 1/mod/*+disp8 4/rm32/sib 6/base/ESI 1/index/ECX <span class="Delimiter"> . </span> 0/r32/AL 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESI+ECX+16) to AL</span> +<span id="L83" class="LineNr"> 83 </span> <span class="Comment"># ++f->read</span> +<span id="L84" class="LineNr"> 84 </span> ff 0/subop/increment 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># increment *(ESI+8)</span> +<span id="L85" class="LineNr"> 85 </span>$read-byte:end: +<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># restore registers</span> +<span id="L87" class="LineNr"> 87 </span> 5e/pop-to-ESI +<span id="L88" class="LineNr"> 88 </span> 59/pop-to-ECX +<span id="L89" class="LineNr"> 89 </span> <span class="Comment"># epilog</span> +<span id="L90" class="LineNr"> 90 </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="L91" class="LineNr"> 91 </span> 5d/pop-to-EBP +<span id="L92" class="LineNr"> 92 </span> c3/return +<span id="L93" class="LineNr"> 93 </span> +<span id="L94" class="LineNr"> 94 </span><span class="Comment"># todo: how should write-byte look? What should it do when the output has no</span> +<span id="L95" class="LineNr"> 95 </span><span class="Comment"># space remaining? Maybe return an error code.</span> +<span id="L96" class="LineNr"> 96 </span> +<span id="L97" class="LineNr"> 97 </span><span class="SalientComment">## tests</span> +<span id="L98" class="LineNr"> 98 </span> +<span id="L99" class="LineNr"> 99 </span>test-read-byte-single: +<span id="L100" class="LineNr">100 </span> <span class="SalientComment">## check that read-byte returns first byte of 'file'</span> +<span id="L101" class="LineNr">101 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L102" class="LineNr">102 </span> <span class="Comment"># push args</span> +<span id="L103" class="LineNr">103 </span> 68/push _test-stream/imm32 +<span id="L104" class="LineNr">104 </span> <span class="Comment"># call</span> +<span id="L105" class="LineNr">105 </span> e8/call clear-stream/disp32 +<span id="L106" class="LineNr">106 </span> <span class="Comment"># discard args</span> +<span id="L107" class="LineNr">107 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L108" class="LineNr">108 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L109" class="LineNr">109 </span> <span class="Comment"># push args</span> +<span id="L110" class="LineNr">110 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L111" class="LineNr">111 </span> 05/add-to-EAX 4/imm32 +<span id="L112" class="LineNr">112 </span> 50/push-EAX +<span id="L113" class="LineNr">113 </span> <span class="Comment"># call</span> +<span id="L114" class="LineNr">114 </span> e8/call clear-stream/disp32 +<span id="L115" class="LineNr">115 </span> <span class="Comment"># discard args</span> +<span id="L116" class="LineNr">116 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment"># write(_test-stream, "Ab")</span> +<span id="L118" class="LineNr">118 </span> <span class="Comment"># push args</span> +<span id="L119" class="LineNr">119 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L120" class="LineNr">120 </span> 68/push _test-stream/imm32 +<span id="L121" class="LineNr">121 </span> <span class="Comment"># call</span> +<span id="L122" class="LineNr">122 </span> e8/call write/disp32 +<span id="L123" class="LineNr">123 </span> <span class="Comment"># discard args</span> +<span id="L124" class="LineNr">124 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L125" class="LineNr">125 </span> <span class="Comment"># read-byte(_test-buffered-file)</span> +<span id="L126" class="LineNr">126 </span> <span class="Comment"># push args</span> +<span id="L127" class="LineNr">127 </span> 68/push _test-buffered-file/imm32 +<span id="L128" class="LineNr">128 </span> <span class="Comment"># call</span> +<span id="L129" class="LineNr">129 </span> e8/call read-byte/disp32 +<span id="L130" class="LineNr">130 </span> <span class="Comment"># discard args</span> +<span id="L131" class="LineNr">131 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L132" class="LineNr">132 </span> <span class="Comment"># check-ints-equal(EAX, 'A')</span> +<span id="L133" class="LineNr">133 </span> <span class="Comment"># push args</span> +<span id="L134" class="LineNr">134 </span> 68/push <span class="Constant">"F - test-read-byte-single"</span>/imm32 +<span id="L135" class="LineNr">135 </span> 68/push 0x41/imm32 +<span id="L136" class="LineNr">136 </span> 50/push-EAX +<span id="L137" class="LineNr">137 </span> <span class="Comment"># call</span> +<span id="L138" class="LineNr">138 </span> e8/call check-ints-equal/disp32 +<span id="L139" class="LineNr">139 </span> <span class="Comment"># discard args</span> +<span id="L140" class="LineNr">140 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment"># end</span> +<span id="L142" class="LineNr">142 </span> c3/return +<span id="L143" class="LineNr">143 </span> +<span id="L144" class="LineNr">144 </span>test-read-byte-multiple: +<span id="L145" class="LineNr">145 </span> <span class="SalientComment">## call read-byte twice, check that second call returns second byte</span> +<span id="L146" class="LineNr">146 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L147" class="LineNr">147 </span> <span class="Comment"># push args</span> +<span id="L148" class="LineNr">148 </span> 68/push _test-stream/imm32 +<span id="L149" class="LineNr">149 </span> <span class="Comment"># call</span> +<span id="L150" class="LineNr">150 </span> e8/call clear-stream/disp32 +<span id="L151" class="LineNr">151 </span> <span class="Comment"># discard args</span> +<span id="L152" class="LineNr">152 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L154" class="LineNr">154 </span> <span class="Comment"># push args</span> +<span id="L155" class="LineNr">155 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L156" class="LineNr">156 </span> 05/add-to-EAX 4/imm32 +<span id="L157" class="LineNr">157 </span> 50/push-EAX +<span id="L158" class="LineNr">158 </span> <span class="Comment"># call</span> +<span id="L159" class="LineNr">159 </span> e8/call clear-stream/disp32 +<span id="L160" class="LineNr">160 </span> <span class="Comment"># discard args</span> +<span id="L161" class="LineNr">161 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L162" class="LineNr">162 </span> <span class="Comment"># write(_test-stream, "Ab")</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># push args</span> +<span id="L164" class="LineNr">164 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L165" class="LineNr">165 </span> 68/push _test-stream/imm32 +<span id="L166" class="LineNr">166 </span> <span class="Comment"># call</span> +<span id="L167" class="LineNr">167 </span> e8/call write/disp32 +<span id="L168" class="LineNr">168 </span> <span class="Comment"># discard args</span> +<span id="L169" class="LineNr">169 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L170" class="LineNr">170 </span> <span class="Comment"># read-byte(_test-buffered-file)</span> +<span id="L171" class="LineNr">171 </span> <span class="Comment"># push args</span> +<span id="L172" class="LineNr">172 </span> 68/push _test-buffered-file/imm32 +<span id="L173" class="LineNr">173 </span> <span class="Comment"># call</span> +<span id="L174" class="LineNr">174 </span> e8/call read-byte/disp32 +<span id="L175" class="LineNr">175 </span> <span class="Comment"># discard args</span> +<span id="L176" class="LineNr">176 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L177" class="LineNr">177 </span> <span class="Comment"># read-byte(_test-buffered-file)</span> +<span id="L178" class="LineNr">178 </span> <span class="Comment"># push args</span> +<span id="L179" class="LineNr">179 </span> 68/push _test-buffered-file/imm32 +<span id="L180" class="LineNr">180 </span> <span class="Comment"># call</span> +<span id="L181" class="LineNr">181 </span> e8/call read-byte/disp32 +<span id="L182" class="LineNr">182 </span> <span class="Comment"># discard args</span> +<span id="L183" class="LineNr">183 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L184" class="LineNr">184 </span> <span class="Comment"># check-ints-equal(EAX, 'b')</span> +<span id="L185" class="LineNr">185 </span> <span class="Comment"># push args</span> +<span id="L186" class="LineNr">186 </span> 68/push <span class="Constant">"F - test-read-byte-multiple"</span>/imm32 +<span id="L187" class="LineNr">187 </span> 68/push 0x62/imm32 +<span id="L188" class="LineNr">188 </span> 50/push-EAX +<span id="L189" class="LineNr">189 </span> <span class="Comment"># call</span> +<span id="L190" class="LineNr">190 </span> e8/call check-ints-equal/disp32 +<span id="L191" class="LineNr">191 </span> <span class="Comment"># discard args</span> +<span id="L192" class="LineNr">192 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L193" class="LineNr">193 </span> <span class="Comment"># end</span> +<span id="L194" class="LineNr">194 </span> c3/return +<span id="L195" class="LineNr">195 </span> +<span id="L196" class="LineNr">196 </span>test-read-byte-end-of-file: +<span id="L197" class="LineNr">197 </span> <span class="SalientComment">## call read-byte on an empty 'file', check that it returns -1</span> +<span id="L198" class="LineNr">198 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L199" class="LineNr">199 </span> <span class="Comment"># push args</span> +<span id="L200" class="LineNr">200 </span> 68/push _test-stream/imm32 +<span id="L201" class="LineNr">201 </span> <span class="Comment"># call</span> +<span id="L202" class="LineNr">202 </span> e8/call clear-stream/disp32 +<span id="L203" class="LineNr">203 </span> <span class="Comment"># discard args</span> +<span id="L204" class="LineNr">204 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L205" class="LineNr">205 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L206" class="LineNr">206 </span> <span class="Comment"># push args</span> +<span id="L207" class="LineNr">207 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L208" class="LineNr">208 </span> 05/add-to-EAX 4/imm32 +<span id="L209" class="LineNr">209 </span> 50/push-EAX +<span id="L210" class="LineNr">210 </span> <span class="Comment"># call</span> +<span id="L211" class="LineNr">211 </span> e8/call clear-stream/disp32 +<span id="L212" class="LineNr">212 </span> <span class="Comment"># discard args</span> +<span id="L213" class="LineNr">213 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L214" class="LineNr">214 </span> <span class="Comment"># read-byte(_test-buffered-file)</span> +<span id="L215" class="LineNr">215 </span> <span class="Comment"># push args</span> +<span id="L216" class="LineNr">216 </span> 68/push _test-buffered-file/imm32 +<span id="L217" class="LineNr">217 </span> <span class="Comment"># call</span> +<span id="L218" class="LineNr">218 </span> e8/call read-byte/disp32 +<span id="L219" class="LineNr">219 </span> <span class="Comment"># discard args</span> +<span id="L220" class="LineNr">220 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L221" class="LineNr">221 </span> <span class="Comment"># check-ints-equal(EAX, -1)</span> +<span id="L222" class="LineNr">222 </span> <span class="Comment"># push args</span> +<span id="L223" class="LineNr">223 </span> 68/push <span class="Constant">"F - test-read-byte-end-of-file"</span>/imm32 +<span id="L224" class="LineNr">224 </span> 68/push -1/imm32 +<span id="L225" class="LineNr">225 </span> 50/push-EAX +<span id="L226" class="LineNr">226 </span> <span class="Comment"># call</span> +<span id="L227" class="LineNr">227 </span> e8/call check-ints-equal/disp32 +<span id="L228" class="LineNr">228 </span> <span class="Comment"># discard args</span> +<span id="L229" class="LineNr">229 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L230" class="LineNr">230 </span> <span class="Comment"># end</span> +<span id="L231" class="LineNr">231 </span> c3/return +<span id="L232" class="LineNr">232 </span> +<span id="L233" class="LineNr">233 </span>== data +<span id="L234" class="LineNr">234 </span> +<span id="L235" class="LineNr">235 </span>_test-buffered-file: +<span id="L236" class="LineNr">236 </span> <span class="Comment"># file descriptor or (address stream)</span> +<span id="L237" class="LineNr">237 </span> _test-stream/imm32 +<span id="L238" class="LineNr">238 </span> <span class="Comment"># current write index</span> +<span id="L239" class="LineNr">239 </span> 00 00 00 00 +<span id="L240" class="LineNr">240 </span> <span class="Comment"># current read index</span> +<span id="L241" class="LineNr">241 </span> 00 00 00 00 +<span id="L242" class="LineNr">242 </span> <span class="Comment"># length (8)</span> +<span id="L243" class="LineNr">243 </span> 08 00 00 00 +<span id="L244" class="LineNr">244 </span> <span class="Comment"># data</span> +<span id="L245" class="LineNr">245 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L246" class="LineNr">246 </span> +<span id="L247" class="LineNr">247 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/subx/060write-stream.subx.html b/html/subx/060write-stream.subx.html new file mode 100644 index 00000000..90a90fa3 --- /dev/null +++ b/html/subx/060write-stream.subx.html @@ -0,0 +1,301 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - subx/060write-stream.subx</title> +<meta name="Generator" content="Vim/8.0"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { font-family: monospace; color: #aaaaaa; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } +a { color:#eeeeee; text-decoration: none; } +a:hover { text-decoration: underline; } +* { font-size: 12pt; font-size: 1em; } +.CommentedCode { color: #6c6c6c; } +.LineNr { color: #444444; } +.Constant { color: #00a0a0; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Comment { color: #9090ff; } +.Comment a { color:#0000ee; text-decoration:underline; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="Comment"># write-stream: like write, but write streams rather than strings</span> +<span id="L2" class="LineNr"> 2 </span> +<span id="L3" class="LineNr"> 3 </span>== code +<span id="L4" class="LineNr"> 4 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L6" class="LineNr"> 6 </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> +<span id="L7" class="LineNr"> 7 </span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># main:</span> +<span id="L9" class="LineNr"> 9 </span> <span class="Comment"># manual test</span> +<span id="L10" class="LineNr"> 10 </span><span class="CommentedCode">#? # write-stream(stdout, _test-stream2)</span> +<span id="L11" class="LineNr"> 11 </span><span class="CommentedCode">#? 68/push _test-stream2/imm32</span> +<span id="L12" class="LineNr"> 12 </span><span class="CommentedCode">#? 68/push 1/imm32/stdout</span> +<span id="L13" class="LineNr"> 13 </span><span class="CommentedCode">#? e8/call write-stream/disp32</span> +<span id="L14" class="LineNr"> 14 </span> <span class="Comment"># automatic test</span> +<span id="L15" class="LineNr"> 15 </span><span class="CommentedCode">#? e8/call test-write-stream-appends/disp32</span> +<span id="L16" class="LineNr"> 16 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L17" class="LineNr"> 17 </span> <span class="Comment"># syscall(exit, Num-test-failures)</span> +<span id="L18" class="LineNr"> 18 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L19" class="LineNr"> 19 </span> b8/copy-to-EAX 1/imm32 +<span id="L20" class="LineNr"> 20 </span> cd/syscall 0x80/imm8 +<span id="L21" class="LineNr"> 21 </span> +<span id="L22" class="LineNr"> 22 </span>write-stream: <span class="Comment"># f : fd or (address stream), s : (address stream) -> <void></span> +<span id="L23" class="LineNr"> 23 </span> <span class="Comment"># prolog</span> +<span id="L24" class="LineNr"> 24 </span> 55/push-EBP +<span id="L25" class="LineNr"> 25 </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="L26" class="LineNr"> 26 </span> <span class="Comment"># if (f < 0x08000000) _write-stream(f, s), return # f can't be a user-mode address, so treat it as a kernel file descriptor</span> +<span id="L27" class="LineNr"> 27 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 0x08000000/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L28" class="LineNr"> 28 </span> 7d/jump-if-greater-or-equal $write-stream:fake/disp8 +<span id="L29" class="LineNr"> 29 </span> <span class="Comment"># push args</span> +<span id="L30" class="LineNr"> 30 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L31" class="LineNr"> 31 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Comment"># call</span> +<span id="L33" class="LineNr"> 33 </span> e8/call _write-stream/disp32 +<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># discard args</span> +<span id="L35" class="LineNr"> 35 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L36" class="LineNr"> 36 </span> eb/jump $write-stream:end/disp8 +<span id="L37" class="LineNr"> 37 </span>$write-stream:fake: +<span id="L38" class="LineNr"> 38 </span> <span class="Comment"># otherwise, treat 'f' as a stream to append to</span> +<span id="L39" class="LineNr"> 39 </span> <span class="Comment"># save registers</span> +<span id="L40" class="LineNr"> 40 </span> 50/push-EAX +<span id="L41" class="LineNr"> 41 </span> 56/push-ESI +<span id="L42" class="LineNr"> 42 </span> 57/push-EDI +<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># ESI = f</span> +<span id="L44" class="LineNr"> 44 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 6/r32/ESI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ESI</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># EDI = s</span> +<span id="L46" class="LineNr"> 46 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none 7/r32/EDI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDI</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># EAX = _append-4(&f->data[f->write], &f->data[f->length], &s->data[s->read], &s->data[s->write])</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># push &s->data[s->write]</span> +<span id="L49" class="LineNr"> 49 </span> 8b/copy 0/mod/indirect 7/rm32/EDI <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"># copy *EDI to EAX</span> +<span id="L50" class="LineNr"> 50 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+EAX+12 to EAX</span> +<span id="L51" class="LineNr"> 51 </span> 50/push-EAX +<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># push &s->data[s->read]</span> +<span id="L53" class="LineNr"> 53 </span> 8b/copy 1/mod/*+disp8 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EDI+4) to EAX</span> +<span id="L54" class="LineNr"> 54 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+EAX+12 to EAX</span> +<span id="L55" class="LineNr"> 55 </span> 50/push-EAX +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># push &f->data[f->length]</span> +<span id="L57" class="LineNr"> 57 </span> 8b/copy 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESI+8) to EAX</span> +<span id="L58" class="LineNr"> 58 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+EAX+12 to EAX</span> +<span id="L59" class="LineNr"> 59 </span> 50/push-EAX +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># push &f->data[f->write]</span> +<span id="L61" class="LineNr"> 61 </span> 8b/copy 0/mod/indirect 6/rm32/ESI <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"># copy *ESI to EAX</span> +<span id="L62" class="LineNr"> 62 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 0/index/EAX <span class="Delimiter"> . </span> 0/r32/EAX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+EAX+12 to EAX</span> +<span id="L63" class="LineNr"> 63 </span> 50/push-EAX +<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># call</span> +<span id="L65" class="LineNr"> 65 </span> e8/call _append-4/disp32 +<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># discard args</span> +<span id="L67" class="LineNr"> 67 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># f->write += EAX</span> +<span id="L69" class="LineNr"> 69 </span> 01/add 0/mod/indirect 6/rm32/ESI <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"># add EAX to *ESI</span> +<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># s->read += EAX</span> +<span id="L71" class="LineNr"> 71 </span> 01/add 1/mod/*+disp8 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># add EAX to *(EDI+4)</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># restore registers</span> +<span id="L73" class="LineNr"> 73 </span> 5f/pop-to-EDI +<span id="L74" class="LineNr"> 74 </span> 5e/pop-to-ESI +<span id="L75" class="LineNr"> 75 </span> 58/pop-to-EAX +<span id="L76" class="LineNr"> 76 </span>$write-stream:end: +<span id="L77" class="LineNr"> 77 </span> <span class="Comment"># epilog</span> +<span id="L78" class="LineNr"> 78 </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="L79" class="LineNr"> 79 </span> 5d/pop-to-EBP +<span id="L80" class="LineNr"> 80 </span> c3/return +<span id="L81" class="LineNr"> 81 </span> +<span id="L82" class="LineNr"> 82 </span>_write-stream: <span class="Comment"># fd : int, s : (address stream) -> <void></span> +<span id="L83" class="LineNr"> 83 </span> <span class="Comment"># prolog</span> +<span id="L84" class="LineNr"> 84 </span> 55/push-EBP +<span id="L85" class="LineNr"> 85 </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="L86" class="LineNr"> 86 </span> <span class="Comment"># save registers</span> +<span id="L87" class="LineNr"> 87 </span> 50/push-EAX +<span id="L88" class="LineNr"> 88 </span> 51/push-ECX +<span id="L89" class="LineNr"> 89 </span> 52/push-EDX +<span id="L90" class="LineNr"> 90 </span> 53/push-EBX +<span id="L91" class="LineNr"> 91 </span> 56/push-ESI +<span id="L92" class="LineNr"> 92 </span> 57/push-EDI +<span id="L93" class="LineNr"> 93 </span> <span class="Comment"># ESI = s</span> +<span id="L94" class="LineNr"> 94 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># EDI = s->read</span> +<span id="L96" class="LineNr"> 96 </span> 8b/copy 1/mod/*+disp8 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 7/r32/EDI 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESI+4) to EDI</span> +<span id="L97" class="LineNr"> 97 </span> <span class="Comment"># EDX = s->write</span> +<span id="L98" class="LineNr"> 98 </span> 8b/copy 0/mod/indirect 6/rm32/ESI <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 *ESI to EDX</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Comment"># syscall(write, fd, &s->data[s->read], s->write-s->read)</span> +<span id="L100" class="LineNr">100 </span> <span class="Comment"># fd : EBX</span> +<span id="L101" class="LineNr">101 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EBX</span> +<span id="L102" class="LineNr">102 </span> <span class="Comment"># data : ECX = &s->data[s->read]</span> +<span id="L103" class="LineNr">103 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 6/base/ESI 7/index/EDI <span class="Delimiter"> . </span> 1/r32/ECX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy ESI+EDI+12 to ECX</span> +<span id="L104" class="LineNr">104 </span> <span class="Comment"># size : EDX = s->write - s->read</span> +<span id="L105" class="LineNr">105 </span> 29/subtract 3/mod/direct 2/rm32/EDX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 7/r32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># subtract EDI from EDX</span> +<span id="L106" class="LineNr">106 </span> <span class="Comment"># syscall</span> +<span id="L107" class="LineNr">107 </span> b8/copy-to-EAX 4/imm32/write +<span id="L108" class="LineNr">108 </span> cd/syscall 0x80/imm8 +<span id="L109" class="LineNr">109 </span> <span class="Comment"># restore registers</span> +<span id="L110" class="LineNr">110 </span> 5f/pop-to-EDI +<span id="L111" class="LineNr">111 </span> 5e/pop-to-ESI +<span id="L112" class="LineNr">112 </span> 5b/pop-to-EBX +<span id="L113" class="LineNr">113 </span> 5a/pop-to-EDX +<span id="L114" class="LineNr">114 </span> 59/pop-to-ECX +<span id="L115" class="LineNr">115 </span> 58/pop-to-EAX +<span id="L116" class="LineNr">116 </span> <span class="Comment"># epilog</span> +<span id="L117" class="LineNr">117 </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="L118" class="LineNr">118 </span> 5d/pop-to-EBP +<span id="L119" class="LineNr">119 </span> c3/return +<span id="L120" class="LineNr">120 </span> +<span id="L121" class="LineNr">121 </span>test-write-stream-single: +<span id="L122" class="LineNr">122 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L123" class="LineNr">123 </span> <span class="Comment"># push args</span> +<span id="L124" class="LineNr">124 </span> 68/push _test-stream/imm32 +<span id="L125" class="LineNr">125 </span> <span class="Comment"># call</span> +<span id="L126" class="LineNr">126 </span> e8/call clear-stream/disp32 +<span id="L127" class="LineNr">127 </span> <span class="Comment"># discard args</span> +<span id="L128" class="LineNr">128 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L129" class="LineNr">129 </span> <span class="Comment"># clear-stream(_test-stream2)</span> +<span id="L130" class="LineNr">130 </span> <span class="Comment"># push args</span> +<span id="L131" class="LineNr">131 </span> 68/push _test-stream2/imm32 +<span id="L132" class="LineNr">132 </span> <span class="Comment"># call</span> +<span id="L133" class="LineNr">133 </span> e8/call clear-stream/disp32 +<span id="L134" class="LineNr">134 </span> <span class="Comment"># discard args</span> +<span id="L135" class="LineNr">135 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L136" class="LineNr">136 </span> <span class="Comment"># write(_test-stream2, "Ab")</span> +<span id="L137" class="LineNr">137 </span> <span class="Comment"># push args</span> +<span id="L138" class="LineNr">138 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L139" class="LineNr">139 </span> 68/push _test-stream2/imm32 +<span id="L140" class="LineNr">140 </span> <span class="Comment"># call</span> +<span id="L141" class="LineNr">141 </span> e8/call write/disp32 +<span id="L142" class="LineNr">142 </span> <span class="Comment"># discard args</span> +<span id="L143" class="LineNr">143 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L144" class="LineNr">144 </span> <span class="Comment"># write-stream(_test-stream, _test-stream2)</span> +<span id="L145" class="LineNr">145 </span> <span class="Comment"># push args</span> +<span id="L146" class="LineNr">146 </span> 68/push _test-stream2/imm32 +<span id="L147" class="LineNr">147 </span> 68/push _test-stream/imm32 +<span id="L148" class="LineNr">148 </span> <span class="Comment"># call</span> +<span id="L149" class="LineNr">149 </span> e8/call write-stream/disp32 +<span id="L150" class="LineNr">150 </span> <span class="Comment"># discard args</span> +<span id="L151" class="LineNr">151 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L152" class="LineNr">152 </span> <span class="Comment"># check-ints-equal(*_test-stream.data, 41/A 62/b 00 00, msg)</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment"># push args</span> +<span id="L154" class="LineNr">154 </span> 68/push <span class="Constant">"F - test-write-stream-single"</span>/imm32 +<span id="L155" class="LineNr">155 </span> 68/push 0x006241/imm32/<span class="Special">Ab</span> +<span id="L156" class="LineNr">156 </span> <span class="Comment"># push *_test-stream.data</span> +<span id="L157" class="LineNr">157 </span> b8/copy-to-EAX _test-stream/imm32 +<span id="L158" class="LineNr">158 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L159" class="LineNr">159 </span> <span class="Comment"># call</span> +<span id="L160" class="LineNr">160 </span> e8/call check-ints-equal/disp32 +<span id="L161" class="LineNr">161 </span> <span class="Comment"># discard args</span> +<span id="L162" class="LineNr">162 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># end</span> +<span id="L164" class="LineNr">164 </span> c3/return +<span id="L165" class="LineNr">165 </span> +<span id="L166" class="LineNr">166 </span>test-write-stream-appends: +<span id="L167" class="LineNr">167 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L168" class="LineNr">168 </span> <span class="Comment"># push args</span> +<span id="L169" class="LineNr">169 </span> 68/push _test-stream/imm32 +<span id="L170" class="LineNr">170 </span> <span class="Comment"># call</span> +<span id="L171" class="LineNr">171 </span> e8/call clear-stream/disp32 +<span id="L172" class="LineNr">172 </span> <span class="Comment"># discard args</span> +<span id="L173" class="LineNr">173 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L174" class="LineNr">174 </span> <span class="Comment"># clear-stream(_test-stream2)</span> +<span id="L175" class="LineNr">175 </span> <span class="Comment"># push args</span> +<span id="L176" class="LineNr">176 </span> 68/push _test-stream2/imm32 +<span id="L177" class="LineNr">177 </span> <span class="Comment"># call</span> +<span id="L178" class="LineNr">178 </span> e8/call clear-stream/disp32 +<span id="L179" class="LineNr">179 </span> <span class="Comment"># discard args</span> +<span id="L180" class="LineNr">180 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L181" class="LineNr">181 </span> <span class="Comment"># write(_test-stream2, "C")</span> +<span id="L182" class="LineNr">182 </span> <span class="Comment"># push args</span> +<span id="L183" class="LineNr">183 </span> 68/push <span class="Constant">"C"</span>/imm32 +<span id="L184" class="LineNr">184 </span> 68/push _test-stream2/imm32 +<span id="L185" class="LineNr">185 </span> <span class="Comment"># call</span> +<span id="L186" class="LineNr">186 </span> e8/call write/disp32 +<span id="L187" class="LineNr">187 </span> <span class="Comment"># discard args</span> +<span id="L188" class="LineNr">188 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L189" class="LineNr">189 </span> <span class="Comment"># write-stream(_test-stream, _test-stream2)</span> +<span id="L190" class="LineNr">190 </span> <span class="Comment"># push args</span> +<span id="L191" class="LineNr">191 </span> 68/push _test-stream2/imm32 +<span id="L192" class="LineNr">192 </span> 68/push _test-stream/imm32 +<span id="L193" class="LineNr">193 </span> <span class="Comment"># call</span> +<span id="L194" class="LineNr">194 </span> e8/call write-stream/disp32 +<span id="L195" class="LineNr">195 </span> <span class="Comment"># discard args</span> +<span id="L196" class="LineNr">196 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment"># write(_test-stream2, "D")</span> +<span id="L198" class="LineNr">198 </span> <span class="Comment"># push args</span> +<span id="L199" class="LineNr">199 </span> 68/push <span class="Constant">"D"</span>/imm32 +<span id="L200" class="LineNr">200 </span> 68/push _test-stream2/imm32 +<span id="L201" class="LineNr">201 </span> <span class="Comment"># call</span> +<span id="L202" class="LineNr">202 </span> e8/call write/disp32 +<span id="L203" class="LineNr">203 </span> <span class="Comment"># discard args</span> +<span id="L204" class="LineNr">204 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L205" class="LineNr">205 </span> <span class="Comment"># write-stream(_test-stream, _test-stream2)</span> +<span id="L206" class="LineNr">206 </span> <span class="Comment"># push args</span> +<span id="L207" class="LineNr">207 </span> 68/push _test-stream2/imm32 +<span id="L208" class="LineNr">208 </span> 68/push _test-stream/imm32 +<span id="L209" class="LineNr">209 </span> <span class="Comment"># call</span> +<span id="L210" class="LineNr">210 </span> e8/call write-stream/disp32 +<span id="L211" class="LineNr">211 </span> <span class="Comment"># discard args</span> +<span id="L212" class="LineNr">212 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L213" class="LineNr">213 </span> <span class="Comment"># check-ints-equal(*_test-stream.data, 43/C 44/D 00 00, msg)</span> +<span id="L214" class="LineNr">214 </span> <span class="Comment"># push args</span> +<span id="L215" class="LineNr">215 </span> 68/push <span class="Constant">"F - test-write-stream-appends"</span>/imm32 +<span id="L216" class="LineNr">216 </span> 68/push 0x00004443/imm32/C-D +<span id="L217" class="LineNr">217 </span> <span class="Comment"># push *_test-stream.data</span> +<span id="L218" class="LineNr">218 </span> b8/copy-to-EAX _test-stream/imm32 +<span id="L219" class="LineNr">219 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L220" class="LineNr">220 </span> <span class="Comment"># call</span> +<span id="L221" class="LineNr">221 </span> e8/call check-ints-equal/disp32 +<span id="L222" class="LineNr">222 </span> <span class="Comment"># discard args</span> +<span id="L223" class="LineNr">223 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L224" class="LineNr">224 </span> <span class="Comment"># end</span> +<span id="L225" class="LineNr">225 </span> c3/return +<span id="L226" class="LineNr">226 </span> +<span id="L227" class="LineNr">227 </span>== data +<span id="L228" class="LineNr">228 </span> +<span id="L229" class="LineNr">229 </span>_test-stream2: +<span id="L230" class="LineNr">230 </span> <span class="Comment"># current write index</span> +<span id="L231" class="LineNr">231 </span> 04 00 00 00 +<span id="L232" class="LineNr">232 </span> <span class="Comment"># current read index</span> +<span id="L233" class="LineNr">233 </span> 01 00 00 00 +<span id="L234" class="LineNr">234 </span> <span class="Comment"># length (= 8)</span> +<span id="L235" class="LineNr">235 </span> 08 00 00 00 +<span id="L236" class="LineNr">236 </span> <span class="Comment"># data</span> +<span id="L237" class="LineNr">237 </span> 41 42 43 44 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L238" class="LineNr">238 </span> +<span id="L239" class="LineNr">239 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/subx/apps/crenshaw2-1.subx.html b/html/subx/apps/crenshaw2-1.subx.html index c848a55f..157eee2d 100644 --- a/html/subx/apps/crenshaw2-1.subx.html +++ b/html/subx/apps/crenshaw2-1.subx.html @@ -15,8 +15,11 @@ body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } +.CommentedCode { color: #6c6c6c; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -54,8 +57,8 @@ if ('onhashchange' in window) { </head> <body onload='JumpToLine();'> <pre id='vimCodeElement'> -<span id="L1" class="LineNr"> 1 </span><span class="SalientComment">## port of <a href="https://github.com/akkartik/crenshaw/blob/master/tutor2.1.pas">https://github.com/akkartik/crenshaw/blob/master/tutor2.1.pas</a></span> -<span id="L2" class="LineNr"> 2 </span><span class="Comment"># corresponds to the section "single digits" in <a href="https://compilers.iecc.com/crenshaw/tutor2.txt">https://compilers.iecc.com/crenshaw/tutor2.txt</a></span> +<span id="L1" class="LineNr"> 1 </span><span class="SalientComment">## Port of <a href="https://github.com/akkartik/crenshaw/blob/master/tutor2.1.pas">https://github.com/akkartik/crenshaw/blob/master/tutor2.1.pas</a></span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment"># Corresponds to the section "single digits" in <a href="https://compilers.iecc.com/crenshaw/tutor2.txt">https://compilers.iecc.com/crenshaw/tutor2.txt</a></span> <span id="L3" class="LineNr"> 3 </span><span class="Comment">#</span> <span id="L4" class="LineNr"> 4 </span><span class="Comment"># To run (from the subx directory):</span> <span id="L5" class="LineNr"> 5 </span><span class="Comment"># $ ./subx translate *.subx apps/crenshaw2-1.subx -o crenshaw2-1</span> @@ -73,87 +76,620 @@ if ('onhashchange' in window) { <span id="L17" class="LineNr"> 17 </span><span class="Comment"># $ echo $?</span> <span id="L18" class="LineNr"> 18 </span><span class="Comment"># 3</span> <span id="L19" class="LineNr"> 19 </span><span class="Comment">#</span> -<span id="L20" class="LineNr"> 20 </span><span class="Comment"># Stdin must contain just a single hex number. Other input will print an error:</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment"># Stdin must contain just a single hex digit. Other input will print an error:</span> <span id="L21" class="LineNr"> 21 </span><span class="Comment"># $ echo 'xyz' |./subx run apps/crenshaw2-1</span> <span id="L22" class="LineNr"> 22 </span><span class="Comment"># Error: integer expected</span> -<span id="L23" class="LineNr"> 23 </span> -<span id="L24" class="LineNr"> 24 </span>== code -<span id="L25" class="LineNr"> 25 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L26" class="LineNr"> 26 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L27" class="LineNr"> 27 </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> -<span id="L28" class="LineNr"> 28 </span> -<span id="L29" class="LineNr"> 29 </span><span class="Comment"># main:</span> -<span id="L30" class="LineNr"> 30 </span> <span class="Comment"># allocate space for an exit-descriptor</span> -<span id="L31" class="LineNr"> 31 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> -<span id="L32" class="LineNr"> 32 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> -<span id="L33" class="LineNr"> 33 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> -<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># clear ed->target (so we really exit)</span> -<span id="L35" class="LineNr"> 35 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> -<span id="L36" class="LineNr"> 36 </span> <span class="Comment"># expected(ed, 2/stderr, "integer")</span> -<span id="L37" class="LineNr"> 37 </span> <span class="Comment"># push args</span> -<span id="L38" class="LineNr"> 38 </span> 68/push "integer"/imm32 -<span id="L39" class="LineNr"> 39 </span> 68/push 2/imm32/stderr -<span id="L40" class="LineNr"> 40 </span> 50/push-EAX -<span id="L41" class="LineNr"> 41 </span> <span class="Comment"># call</span> -<span id="L42" class="LineNr"> 42 </span> e8/call expected/disp32 -<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># discard args</span> -<span id="L44" class="LineNr"> 44 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># syscall(exit, 0)</span> -<span id="L46" class="LineNr"> 46 </span> bb/copy-to-EBX 0/imm32 -<span id="L47" class="LineNr"> 47 </span> b8/copy-to-EAX 1/imm32/exit -<span id="L48" class="LineNr"> 48 </span> cd/syscall 0x80/imm8 -<span id="L49" class="LineNr"> 49 </span> -<span id="L50" class="LineNr"> 50 </span><span class="SalientComment">## helpers</span> -<span id="L51" class="LineNr"> 51 </span> -<span id="L52" class="LineNr"> 52 </span>expected: <span class="Comment"># ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte)</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># prolog</span> -<span id="L54" class="LineNr"> 54 </span> 55/push-EBP -<span id="L55" class="LineNr"> 55 </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="L56" class="LineNr"> 56 </span> <span class="Comment"># write(f, "Error: ")</span> -<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># push args</span> -<span id="L58" class="LineNr"> 58 </span> 68/push "Error: "/imm32 -<span id="L59" class="LineNr"> 59 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># call</span> -<span id="L61" class="LineNr"> 61 </span> e8/call write/disp32 -<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># discard args</span> -<span id="L63" class="LineNr"> 63 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># write(f, s)</span> -<span id="L65" class="LineNr"> 65 </span> <span class="Comment"># push args</span> -<span id="L66" class="LineNr"> 66 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> -<span id="L67" class="LineNr"> 67 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># call</span> -<span id="L69" class="LineNr"> 69 </span> e8/call write/disp32 -<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># discard args</span> -<span id="L71" class="LineNr"> 71 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># write(f, " expected")</span> -<span id="L73" class="LineNr"> 73 </span> <span class="Comment"># push args</span> -<span id="L74" class="LineNr"> 74 </span> 68/push " expected"/imm32 -<span id="L75" class="LineNr"> 75 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L76" class="LineNr"> 76 </span> <span class="Comment"># call</span> -<span id="L77" class="LineNr"> 77 </span> e8/call write/disp32 -<span id="L78" class="LineNr"> 78 </span> <span class="Comment"># discard args</span> -<span id="L79" class="LineNr"> 79 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L80" class="LineNr"> 80 </span> <span class="Comment"># write(f, Newline)</span> -<span id="L81" class="LineNr"> 81 </span> <span class="Comment"># push args</span> -<span id="L82" class="LineNr"> 82 </span> 68/push Newline/imm32 -<span id="L83" class="LineNr"> 83 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L84" class="LineNr"> 84 </span> <span class="Comment"># call</span> -<span id="L85" class="LineNr"> 85 </span> e8/call write/disp32 -<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># discard args</span> -<span id="L87" class="LineNr"> 87 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L88" class="LineNr"> 88 </span> <span class="Comment"># stop(ed, 1)</span> -<span id="L89" class="LineNr"> 89 </span> <span class="Comment"># push args</span> -<span id="L90" class="LineNr"> 90 </span> 68/push 1/imm32 -<span id="L91" class="LineNr"> 91 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> -<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># call</span> -<span id="L93" class="LineNr"> 93 </span> e8/call stop/disp32 -<span id="L94" class="LineNr"> 94 </span> <span class="SalientComment">## should never get past this point</span> -<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># epilog</span> -<span id="L96" class="LineNr"> 96 </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="L97" class="LineNr"> 97 </span> 5d/pop-to-EBP -<span id="L98" class="LineNr"> 98 </span> c3/return -<span id="L99" class="LineNr"> 99 </span> -<span id="L100" class="LineNr">100 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment">#</span> +<span id="L24" class="LineNr"> 24 </span><span class="Comment"># Names in this file sometimes follow Crenshaw's original rather than my usual</span> +<span id="L25" class="LineNr"> 25 </span><span class="Comment"># naming conventions.</span> +<span id="L26" class="LineNr"> 26 </span> +<span id="L27" class="LineNr"> 27 </span>== code +<span id="L28" class="LineNr"> 28 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L30" class="LineNr"> 30 </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> +<span id="L31" class="LineNr"> 31 </span> +<span id="L32" class="LineNr"> 32 </span><span class="Comment"># main: run tests if necessary, call 'compile' if not</span> +<span id="L33" class="LineNr"> 33 </span> <span class="Comment"># prolog</span> +<span id="L34" class="LineNr"> 34 </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="L35" class="LineNr"> 35 </span> <span class="Comment"># if (argc > 1)</span> +<span id="L36" class="LineNr"> 36 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/disp8 1/imm32 <span class="Comment"># compare *EBP</span> +<span id="L37" class="LineNr"> 37 </span> 7e/jump-if-lesser-or-equal $run-main/disp8 +<span id="L38" class="LineNr"> 38 </span> <span class="Comment"># and if (argv[1] == "test")</span> +<span id="L39" class="LineNr"> 39 </span> <span class="Comment"># push args</span> +<span id="L40" class="LineNr"> 40 </span> 68/push <span class="Constant">"test"</span>/imm32 +<span id="L41" class="LineNr"> 41 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L42" class="LineNr"> 42 </span> <span class="Comment"># call</span> +<span id="L43" class="LineNr"> 43 </span> e8/call kernel-string-equal/disp32 +<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># discard args</span> +<span id="L45" class="LineNr"> 45 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment"># check result</span> +<span id="L47" class="LineNr"> 47 </span> 3d/compare-EAX 1/imm32 +<span id="L48" class="LineNr"> 48 </span> 75/jump-if-not-equal $run-main/disp8 +<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># then return run-tests()</span> +<span id="L50" class="LineNr"> 50 </span> e8/call run-tests/disp32 +<span id="L51" class="LineNr"> 51 </span><span class="CommentedCode">#? e8/call test-get-num-reads-multiple-digits/disp32</span> +<span id="L52" class="LineNr"> 52 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L53" class="LineNr"> 53 </span> eb/jump $main:end/disp8 +<span id="L54" class="LineNr"> 54 </span>$run-main: +<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># allocate space for an exit-descriptor</span> +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L57" class="LineNr"> 57 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L58" class="LineNr"> 58 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L59" class="LineNr"> 59 </span> <span class="Comment"># clear ed->target (so we really exit)</span> +<span id="L60" class="LineNr"> 60 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> +<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># compile(Stdin, 1/stdout, 2/stderr, ed)</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># push args</span> +<span id="L63" class="LineNr"> 63 </span> 50/push-EAX/ed +<span id="L64" class="LineNr"> 64 </span> 68/push 2/imm32/stderr +<span id="L65" class="LineNr"> 65 </span> 68/push 1/imm32/stdout +<span id="L66" class="LineNr"> 66 </span> 68/push <span class="Special">Stdin</span>/imm32 +<span id="L67" class="LineNr"> 67 </span> <span class="Comment"># call</span> +<span id="L68" class="LineNr"> 68 </span> e8/call compile/disp32 +<span id="L69" class="LineNr"> 69 </span> <span class="Comment"># discard args</span> +<span id="L70" class="LineNr"> 70 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L71" class="LineNr"> 71 </span> <span class="Comment"># syscall(exit, 0)</span> +<span id="L72" class="LineNr"> 72 </span> bb/copy-to-EBX 0/imm32 +<span id="L73" class="LineNr"> 73 </span>$main:end: +<span id="L74" class="LineNr"> 74 </span> b8/copy-to-EAX 1/imm32/exit +<span id="L75" class="LineNr"> 75 </span> cd/syscall 0x80/imm8 +<span id="L76" class="LineNr"> 76 </span> +<span id="L77" class="LineNr"> 77 </span><span class="Comment"># the main entry point</span> +<span id="L78" class="LineNr"> 78 </span>compile: <span class="Comment"># in : fd or (address stream), out : fd or (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void></span> +<span id="L79" class="LineNr"> 79 </span> <span class="Comment"># prolog</span> +<span id="L80" class="LineNr"> 80 </span> 55/push-EBP +<span id="L81" class="LineNr"> 81 </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="L82" class="LineNr"> 82 </span> <span class="Comment"># save registers</span> +<span id="L83" class="LineNr"> 83 </span> 50/push-EAX +<span id="L84" class="LineNr"> 84 </span> 51/push-ECX +<span id="L85" class="LineNr"> 85 </span> <span class="Comment"># Look = get-char(in)</span> +<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># push args</span> +<span id="L87" class="LineNr"> 87 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L88" class="LineNr"> 88 </span> <span class="Comment"># call</span> +<span id="L89" class="LineNr"> 89 </span> e8/call get-char/disp32 +<span id="L90" class="LineNr"> 90 </span> <span class="Comment"># discard args</span> +<span id="L91" class="LineNr"> 91 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L92" class="LineNr"> 92 </span> <span class="Comment"># var num/ECX : (address stream) on the stack</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Comment"># Numbers can be 32 bits or 8 hex bytes long. One of them will be in 'Look', so we need space for 7 bytes.</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Comment"># We won't add more, so that we can get overflow-handling for free.</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># Add 12 bytes for 'read', 'write' and 'length' fields, for a total of 19 bytes, or 0x13 in hex.</span> +<span id="L96" class="LineNr"> 96 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x13/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L97" class="LineNr"> 97 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to ECX</span> +<span id="L98" class="LineNr"> 98 </span> <span class="Comment"># num->length = 7</span> +<span id="L99" class="LineNr"> 99 </span> c7/copy 1/mod/*+disp8 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 7/imm32 <span class="Comment"># copy to *(ECX+8)</span> +<span id="L100" class="LineNr">100 </span> <span class="Comment"># clear-stream(num)</span> +<span id="L101" class="LineNr">101 </span> <span class="Comment"># push args</span> +<span id="L102" class="LineNr">102 </span> 51/push-ECX +<span id="L103" class="LineNr">103 </span> <span class="Comment"># call</span> +<span id="L104" class="LineNr">104 </span> e8/call clear-stream/disp32 +<span id="L105" class="LineNr">105 </span> <span class="Comment"># discard args</span> +<span id="L106" class="LineNr">106 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L107" class="LineNr">107 </span> <span class="Comment"># get-num(in, num, err, ed)</span> +<span id="L108" class="LineNr">108 </span> <span class="Comment"># push args</span> +<span id="L109" class="LineNr">109 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+20)</span> +<span id="L110" class="LineNr">110 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L111" class="LineNr">111 </span> 51/push-ECX/num +<span id="L112" class="LineNr">112 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L113" class="LineNr">113 </span> <span class="Comment"># call</span> +<span id="L114" class="LineNr">114 </span> e8/call get-num/disp32 +<span id="L115" class="LineNr">115 </span> <span class="Comment"># discard args</span> +<span id="L116" class="LineNr">116 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L117" class="LineNr">117 </span> <span class="Comment"># EAX = write(_test-stream, "Ab")</span> +<span id="L118" class="LineNr">118 </span> <span class="Comment"># push args</span> +<span id="L119" class="LineNr">119 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L120" class="LineNr">120 </span> 68/push _test-stream/imm32 +<span id="L121" class="LineNr">121 </span> <span class="Comment"># call</span> +<span id="L122" class="LineNr">122 </span> e8/call write/disp32 +<span id="L123" class="LineNr">123 </span> <span class="Comment"># discard args</span> +<span id="L124" class="LineNr">124 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L125" class="LineNr">125 </span> <span class="Comment"># EAX = write(out, "bb/copy-to-EBX ")</span> +<span id="L126" class="LineNr">126 </span> <span class="Comment"># push args</span> +<span id="L127" class="LineNr">127 </span> 68/push <span class="Constant">"bb/copy-to-EBX "</span>/imm32 +<span id="L128" class="LineNr">128 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L129" class="LineNr">129 </span> <span class="Comment"># call</span> +<span id="L130" class="LineNr">130 </span> e8/call write/disp32 +<span id="L131" class="LineNr">131 </span> <span class="Comment"># discard args</span> +<span id="L132" class="LineNr">132 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L133" class="LineNr">133 </span> <span class="Comment"># write-stream(out, num)</span> +<span id="L134" class="LineNr">134 </span> <span class="Comment"># push args</span> +<span id="L135" class="LineNr">135 </span> 51/push-ECX/num +<span id="L136" class="LineNr">136 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L137" class="LineNr">137 </span> <span class="Comment"># call</span> +<span id="L138" class="LineNr">138 </span> e8/call write-stream/disp32 +<span id="L139" class="LineNr">139 </span> <span class="Comment"># discard args</span> +<span id="L140" class="LineNr">140 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L141" class="LineNr">141 </span> <span class="Comment"># write(out, Newline)</span> +<span id="L142" class="LineNr">142 </span> <span class="Comment"># push args</span> +<span id="L143" class="LineNr">143 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L144" class="LineNr">144 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L145" class="LineNr">145 </span> <span class="Comment"># call</span> +<span id="L146" class="LineNr">146 </span> e8/call write/disp32 +<span id="L147" class="LineNr">147 </span> <span class="Comment"># discard args</span> +<span id="L148" class="LineNr">148 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L149" class="LineNr">149 </span> <span class="Comment"># EAX = write(out, "b8/copy-to-EAX 1/imm32/exit")</span> +<span id="L150" class="LineNr">150 </span> <span class="Comment"># push args</span> +<span id="L151" class="LineNr">151 </span> 68/push <span class="Constant">"b8/copy-to-EAX 1/imm32/exit"</span>/imm32 +<span id="L152" class="LineNr">152 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L153" class="LineNr">153 </span> <span class="Comment"># call</span> +<span id="L154" class="LineNr">154 </span> e8/call write/disp32 +<span id="L155" class="LineNr">155 </span> <span class="Comment"># discard args</span> +<span id="L156" class="LineNr">156 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L157" class="LineNr">157 </span> <span class="Comment"># EAX = write(out, Newline)</span> +<span id="L158" class="LineNr">158 </span> <span class="Comment"># push args</span> +<span id="L159" class="LineNr">159 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L160" class="LineNr">160 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L161" class="LineNr">161 </span> <span class="Comment"># call</span> +<span id="L162" class="LineNr">162 </span> e8/call write/disp32 +<span id="L163" class="LineNr">163 </span> <span class="Comment"># discard args</span> +<span id="L164" class="LineNr">164 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L165" class="LineNr">165 </span> <span class="Comment"># EAX = write(out, "cd/syscall 0x80/imm8")</span> +<span id="L166" class="LineNr">166 </span> <span class="Comment"># push args</span> +<span id="L167" class="LineNr">167 </span> 68/push <span class="Constant">"cd/syscall 0x80/imm8"</span>/imm32 +<span id="L168" class="LineNr">168 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L169" class="LineNr">169 </span> <span class="Comment"># call</span> +<span id="L170" class="LineNr">170 </span> e8/call write/disp32 +<span id="L171" class="LineNr">171 </span> <span class="Comment"># discard args</span> +<span id="L172" class="LineNr">172 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L173" class="LineNr">173 </span> <span class="Comment"># EAX = write(out, Newline)</span> +<span id="L174" class="LineNr">174 </span> <span class="Comment"># push args</span> +<span id="L175" class="LineNr">175 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L176" class="LineNr">176 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L177" class="LineNr">177 </span> <span class="Comment"># call</span> +<span id="L178" class="LineNr">178 </span> e8/call write/disp32 +<span id="L179" class="LineNr">179 </span> <span class="Comment"># discard args</span> +<span id="L180" class="LineNr">180 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L181" class="LineNr">181 </span> <span class="Comment"># restore registers</span> +<span id="L182" class="LineNr">182 </span> 59/pop-to-ECX +<span id="L183" class="LineNr">183 </span> 58/pop-to-EAX +<span id="L184" class="LineNr">184 </span> <span class="Comment"># epilog</span> +<span id="L185" class="LineNr">185 </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="L186" class="LineNr">186 </span> 5d/pop-to-EBP +<span id="L187" class="LineNr">187 </span> c3/return +<span id="L188" class="LineNr">188 </span> +<span id="L189" class="LineNr">189 </span><span class="Comment"># Read a single digit into 'out'. Abort if there are none, or if there is no space in 'out'.</span> +<span id="L190" class="LineNr">190 </span><span class="Comment"># Input comes from the global variable 'Look', and we leave the next byte from</span> +<span id="L191" class="LineNr">191 </span><span class="Comment"># 'in' into it on exit.</span> +<span id="L192" class="LineNr">192 </span>get-num: <span class="Comment"># in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void></span> +<span id="L193" class="LineNr">193 </span> <span class="Comment"># pseudocode:</span> +<span id="L194" class="LineNr">194 </span> <span class="Comment"># if !is-digit?(Look) expected(ed, err, "integer")</span> +<span id="L195" class="LineNr">195 </span> <span class="Comment"># if out.write >= out.length</span> +<span id="L196" class="LineNr">196 </span> <span class="Comment"># write(err, "Error: too many digits in number\n")</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment"># stop(ed, 1)</span> +<span id="L198" class="LineNr">198 </span> <span class="Comment"># out.data[out.write] = LSB(Look)</span> +<span id="L199" class="LineNr">199 </span> <span class="Comment"># ++out.write</span> +<span id="L200" class="LineNr">200 </span> <span class="Comment"># Look = get-char(in)</span> +<span id="L201" class="LineNr">201 </span> <span class="Comment">#</span> +<span id="L202" class="LineNr">202 </span> <span class="Comment"># within the loop we'll try to keep things in registers:</span> +<span id="L203" class="LineNr">203 </span> <span class="Comment"># ESI : in</span> +<span id="L204" class="LineNr">204 </span> <span class="Comment"># EDI : out</span> +<span id="L205" class="LineNr">205 </span> <span class="Comment"># EAX : temp</span> +<span id="L206" class="LineNr">206 </span> <span class="Comment"># ECX : out->write</span> +<span id="L207" class="LineNr">207 </span> <span class="Comment"># EDX : out->length</span> +<span id="L208" class="LineNr">208 </span> <span class="Comment"># EBX : temp2</span> +<span id="L209" class="LineNr">209 </span> <span class="Comment"># We can't allocate Look to a register because it gets written implicitly in</span> +<span id="L210" class="LineNr">210 </span> <span class="Comment"># get-char in each iteration of the loop. (Thereby demonstrating that it's</span> +<span id="L211" class="LineNr">211 </span> <span class="Comment"># not the right interface for us. But we'll keep it just to follow Crenshaw.)</span> +<span id="L212" class="LineNr">212 </span> <span class="Comment">#</span> +<span id="L213" class="LineNr">213 </span> <span class="Comment"># prolog</span> +<span id="L214" class="LineNr">214 </span> 55/push-EBP +<span id="L215" class="LineNr">215 </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="L216" class="LineNr">216 </span> <span class="Comment"># EAX = is-digit?(Look)</span> +<span id="L217" class="LineNr">217 </span> <span class="Comment"># push args</span> +<span id="L218" class="LineNr">218 </span> ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># push *Look</span> +<span id="L219" class="LineNr">219 </span> <span class="Comment"># call</span> +<span id="L220" class="LineNr">220 </span> e8/call is-digit?/disp32 +<span id="L221" class="LineNr">221 </span> <span class="Comment"># discard args</span> +<span id="L222" class="LineNr">222 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L223" class="LineNr">223 </span> <span class="Comment"># if EAX == 0 error</span> +<span id="L224" class="LineNr">224 </span> 3d/compare-EAX 0/imm32 +<span id="L225" class="LineNr">225 </span> 75/jump-if-not-equal $get-num:main/disp8 +<span id="L226" class="LineNr">226 </span> <span class="Comment"># expected(ed, err, "integer")</span> +<span id="L227" class="LineNr">227 </span> <span class="Comment"># push args</span> +<span id="L228" class="LineNr">228 </span> 68/push <span class="Constant">"integer"</span>/imm32 +<span id="L229" class="LineNr">229 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L230" class="LineNr">230 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+20)</span> +<span id="L231" class="LineNr">231 </span> <span class="Comment"># call</span> +<span id="L232" class="LineNr">232 </span> e8/call expected/disp32 <span class="Comment"># never returns</span> +<span id="L233" class="LineNr">233 </span> <span class="Comment"># discard args</span> +<span id="L234" class="LineNr">234 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L235" class="LineNr">235 </span>$get-num:main: +<span id="L236" class="LineNr">236 </span> <span class="Comment"># save registers</span> +<span id="L237" class="LineNr">237 </span> 50/push-EAX +<span id="L238" class="LineNr">238 </span> 51/push-ECX +<span id="L239" class="LineNr">239 </span> 52/push-EDX +<span id="L240" class="LineNr">240 </span> 53/push-EBX +<span id="L241" class="LineNr">241 </span> 56/push-ESI +<span id="L242" class="LineNr">242 </span> 57/push-EDI +<span id="L243" class="LineNr">243 </span> <span class="Comment"># read necessary variables to registers</span> +<span id="L244" class="LineNr">244 </span> <span class="Comment"># ESI = in</span> +<span id="L245" class="LineNr">245 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ESI</span> +<span id="L246" class="LineNr">246 </span> <span class="Comment"># EDI = out</span> +<span id="L247" class="LineNr">247 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDI</span> +<span id="L248" class="LineNr">248 </span> <span class="Comment"># ECX = out->write</span> +<span id="L249" class="LineNr">249 </span> 8b/copy 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EDI to ECX</span> +<span id="L250" class="LineNr">250 </span> <span class="Comment"># EDX = out->length</span> +<span id="L251" class="LineNr">251 </span> 8b/copy 1/mod/*+disp8 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 2/r32/EDX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EDI+8) to EDX</span> +<span id="L252" class="LineNr">252 </span> <span class="Comment"># if out->write >= out->length error</span> +<span id="L253" class="LineNr">253 </span> 3b/compare 3/mod/direct 1/rm32/ECX <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"># compare EDX with ECX</span> +<span id="L254" class="LineNr">254 </span> 7d/jump-if-lesser $get-num:stage2/disp8 +<span id="L255" class="LineNr">255 </span> <span class="Comment"># error(ed, err, "get-num: too many digits in number") # TODO: show full number</span> +<span id="L256" class="LineNr">256 </span> <span class="Comment"># push args</span> +<span id="L257" class="LineNr">257 </span> 68/push <span class="Constant">"get-num: too many digits in number"</span>/imm32 +<span id="L258" class="LineNr">258 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L259" class="LineNr">259 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+20)</span> +<span id="L260" class="LineNr">260 </span> <span class="Comment"># call</span> +<span id="L261" class="LineNr">261 </span> e8/call error/disp32 <span class="Comment"># never returns</span> +<span id="L262" class="LineNr">262 </span> <span class="Comment"># discard args</span> +<span id="L263" class="LineNr">263 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L264" class="LineNr">264 </span>$get-num:stage2: +<span id="L265" class="LineNr">265 </span> <span class="Comment"># out->data[out->write] = LSB(Look)</span> +<span id="L266" class="LineNr">266 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+ECX+12 to EBX</span> +<span id="L267" class="LineNr">267 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># copy *Look to EAX</span> +<span id="L268" class="LineNr">268 </span> 88/copy-byte 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/AL <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at AL to *EBX</span> +<span id="L269" class="LineNr">269 </span> <span class="Comment"># ++out->write</span> +<span id="L270" class="LineNr">270 </span> 41/increment-ECX +<span id="L271" class="LineNr">271 </span> <span class="Comment"># Look = get-char(in)</span> +<span id="L272" class="LineNr">272 </span> <span class="Comment"># push args</span> +<span id="L273" class="LineNr">273 </span> 56/push-ESI +<span id="L274" class="LineNr">274 </span> <span class="Comment"># call</span> +<span id="L275" class="LineNr">275 </span> e8/call get-char/disp32 +<span id="L276" class="LineNr">276 </span> <span class="Comment"># discard args</span> +<span id="L277" class="LineNr">277 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L278" class="LineNr">278 </span>$get-num:loop-end: +<span id="L279" class="LineNr">279 </span> <span class="Comment"># persist necessary variables from registers</span> +<span id="L280" class="LineNr">280 </span> 89/copy 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ECX to *EDI</span> +<span id="L281" class="LineNr">281 </span> <span class="Comment"># restore registers</span> +<span id="L282" class="LineNr">282 </span> 5f/pop-to-EDI +<span id="L283" class="LineNr">283 </span> 5e/pop-to-ESI +<span id="L284" class="LineNr">284 </span> 5b/pop-to-EBX +<span id="L285" class="LineNr">285 </span> 5a/pop-to-EDX +<span id="L286" class="LineNr">286 </span> 59/pop-to-ECX +<span id="L287" class="LineNr">287 </span> 58/pop-to-EAX +<span id="L288" class="LineNr">288 </span> <span class="Comment"># epilog</span> +<span id="L289" class="LineNr">289 </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="L290" class="LineNr">290 </span> 5d/pop-to-EBP +<span id="L291" class="LineNr">291 </span> c3/return +<span id="L292" class="LineNr">292 </span> +<span id="L293" class="LineNr">293 </span>test-get-num-reads-single-digit: +<span id="L294" class="LineNr">294 </span> <span class="SalientComment">## check that get-num returns first character if it's a digit</span> +<span id="L295" class="LineNr">295 </span> <span class="Comment"># This test uses exit-descriptors. Use EBP for setting up local variables.</span> +<span id="L296" class="LineNr">296 </span> 55/push-EBP +<span id="L297" class="LineNr">297 </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="L298" class="LineNr">298 </span> <span class="SalientComment">## clear all streams</span> +<span id="L299" class="LineNr">299 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L300" class="LineNr">300 </span> <span class="Comment"># push args</span> +<span id="L301" class="LineNr">301 </span> 68/push _test-stream/imm32 +<span id="L302" class="LineNr">302 </span> <span class="Comment"># call</span> +<span id="L303" class="LineNr">303 </span> e8/call clear-stream/disp32 +<span id="L304" class="LineNr">304 </span> <span class="Comment"># discard args</span> +<span id="L305" class="LineNr">305 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L306" class="LineNr">306 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L307" class="LineNr">307 </span> <span class="Comment"># push args</span> +<span id="L308" class="LineNr">308 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L309" class="LineNr">309 </span> 05/add-to-EAX 4/imm32 +<span id="L310" class="LineNr">310 </span> 50/push-EAX +<span id="L311" class="LineNr">311 </span> <span class="Comment"># call</span> +<span id="L312" class="LineNr">312 </span> e8/call clear-stream/disp32 +<span id="L313" class="LineNr">313 </span> <span class="Comment"># discard args</span> +<span id="L314" class="LineNr">314 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L315" class="LineNr">315 </span> <span class="Comment"># clear-stream(_test-output-stream)</span> +<span id="L316" class="LineNr">316 </span> <span class="Comment"># push args</span> +<span id="L317" class="LineNr">317 </span> 68/push _test-output-stream/imm32 +<span id="L318" class="LineNr">318 </span> <span class="Comment"># call</span> +<span id="L319" class="LineNr">319 </span> e8/call clear-stream/disp32 +<span id="L320" class="LineNr">320 </span> <span class="Comment"># discard args</span> +<span id="L321" class="LineNr">321 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L322" class="LineNr">322 </span> <span class="Comment"># clear-stream(_test-error-stream)</span> +<span id="L323" class="LineNr">323 </span> <span class="Comment"># push args</span> +<span id="L324" class="LineNr">324 </span> 68/push _test-error-stream/imm32 +<span id="L325" class="LineNr">325 </span> <span class="Comment"># call</span> +<span id="L326" class="LineNr">326 </span> e8/call clear-stream/disp32 +<span id="L327" class="LineNr">327 </span> <span class="Comment"># discard args</span> +<span id="L328" class="LineNr">328 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L329" class="LineNr">329 </span> <span class="SalientComment">## initialize 'in'</span> +<span id="L330" class="LineNr">330 </span> <span class="Comment"># write(_test-stream, "3")</span> +<span id="L331" class="LineNr">331 </span> <span class="Comment"># push args</span> +<span id="L332" class="LineNr">332 </span> 68/push <span class="Constant">"3"</span>/imm32 +<span id="L333" class="LineNr">333 </span> 68/push _test-stream/imm32 +<span id="L334" class="LineNr">334 </span> <span class="Comment"># call</span> +<span id="L335" class="LineNr">335 </span> e8/call write/disp32 +<span id="L336" class="LineNr">336 </span> <span class="Comment"># discard args</span> +<span id="L337" class="LineNr">337 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L338" class="LineNr">338 </span> <span class="SalientComment">## initialize exit-descriptor 'ed'</span> +<span id="L339" class="LineNr">339 </span> <span class="Comment"># allocate on stack</span> +<span id="L340" class="LineNr">340 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L341" class="LineNr">341 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L342" class="LineNr">342 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L343" class="LineNr">343 </span> <span class="Comment"># size the exit-descriptor for the call to get-num below</span> +<span id="L344" class="LineNr">344 </span> <span class="Comment"># tailor-exit-descriptor(ed, 16)</span> +<span id="L345" class="LineNr">345 </span> <span class="Comment"># push args</span> +<span id="L346" class="LineNr">346 </span> 68/push 0x10/imm32/nbytes-of-args-for-get-num +<span id="L347" class="LineNr">347 </span> 50/push-EAX/ed +<span id="L348" class="LineNr">348 </span> <span class="Comment"># call</span> +<span id="L349" class="LineNr">349 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L350" class="LineNr">350 </span> <span class="Comment"># discard args</span> +<span id="L351" class="LineNr">351 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L352" class="LineNr">352 </span> <span class="SalientComment">## prime the pump</span> +<span id="L353" class="LineNr">353 </span> <span class="Comment"># get-char(_test-buffered-file)</span> +<span id="L354" class="LineNr">354 </span> <span class="Comment"># push args</span> +<span id="L355" class="LineNr">355 </span> 68/push _test-buffered-file/imm32 +<span id="L356" class="LineNr">356 </span> <span class="Comment"># call</span> +<span id="L357" class="LineNr">357 </span> e8/call get-char/disp32 +<span id="L358" class="LineNr">358 </span> <span class="Comment"># discard args</span> +<span id="L359" class="LineNr">359 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L360" class="LineNr">360 </span> <span class="SalientComment">## get-num(in, out, err, ed)</span> +<span id="L361" class="LineNr">361 </span> <span class="Comment"># push args</span> +<span id="L362" class="LineNr">362 </span> 50/push-EAX/ed +<span id="L363" class="LineNr">363 </span> 68/push _test-error-stream/imm32 +<span id="L364" class="LineNr">364 </span> 68/push _test-output-stream/imm32 +<span id="L365" class="LineNr">365 </span> 68/push _test-buffered-file/imm32 +<span id="L366" class="LineNr">366 </span> <span class="Comment"># call</span> +<span id="L367" class="LineNr">367 </span> e8/call get-num/disp32 +<span id="L368" class="LineNr">368 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L369" class="LineNr">369 </span> <span class="Comment"># discard args</span> +<span id="L370" class="LineNr">370 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L371" class="LineNr">371 </span> <span class="Comment"># check-ints-equal(*_test-output-stream.data, '3')</span> +<span id="L372" class="LineNr">372 </span> <span class="Comment"># push args</span> +<span id="L373" class="LineNr">373 </span> 68/push <span class="Constant">"F - test-get-num-reads-single-digit"</span>/imm32 +<span id="L374" class="LineNr">374 </span> 68/push 0x33/imm32 +<span id="L375" class="LineNr">375 </span> b8/copy-to-EAX _test-output-stream/imm32 +<span id="L376" class="LineNr">376 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L377" class="LineNr">377 </span> <span class="Comment"># call</span> +<span id="L378" class="LineNr">378 </span> e8/call check-ints-equal/disp32 +<span id="L379" class="LineNr">379 </span> <span class="Comment"># discard args</span> +<span id="L380" class="LineNr">380 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L381" class="LineNr">381 </span> <span class="Comment"># reclaim locals</span> +<span id="L382" class="LineNr">382 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L383" class="LineNr">383 </span> 5d/pop-to-EBP +<span id="L384" class="LineNr">384 </span> c3/return +<span id="L385" class="LineNr">385 </span> +<span id="L386" class="LineNr">386 </span>test-get-num-aborts-on-non-digit-in-Look: +<span id="L387" class="LineNr">387 </span> <span class="SalientComment">## check that get-num returns first character if it's a digit</span> +<span id="L388" class="LineNr">388 </span> <span class="Comment"># This test uses exit-descriptors. Use EBP for setting up local variables.</span> +<span id="L389" class="LineNr">389 </span> 55/push-EBP +<span id="L390" class="LineNr">390 </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="L391" class="LineNr">391 </span> <span class="SalientComment">## clear all streams</span> +<span id="L392" class="LineNr">392 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L393" class="LineNr">393 </span> <span class="Comment"># push args</span> +<span id="L394" class="LineNr">394 </span> 68/push _test-stream/imm32 +<span id="L395" class="LineNr">395 </span> <span class="Comment"># call</span> +<span id="L396" class="LineNr">396 </span> e8/call clear-stream/disp32 +<span id="L397" class="LineNr">397 </span> <span class="Comment"># discard args</span> +<span id="L398" class="LineNr">398 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L399" class="LineNr">399 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L400" class="LineNr">400 </span> <span class="Comment"># push args</span> +<span id="L401" class="LineNr">401 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L402" class="LineNr">402 </span> 05/add-to-EAX 4/imm32 +<span id="L403" class="LineNr">403 </span> 50/push-EAX +<span id="L404" class="LineNr">404 </span> <span class="Comment"># call</span> +<span id="L405" class="LineNr">405 </span> e8/call clear-stream/disp32 +<span id="L406" class="LineNr">406 </span> <span class="Comment"># discard args</span> +<span id="L407" class="LineNr">407 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L408" class="LineNr">408 </span> <span class="Comment"># clear-stream(_test-output-stream)</span> +<span id="L409" class="LineNr">409 </span> <span class="Comment"># push args</span> +<span id="L410" class="LineNr">410 </span> 68/push _test-output-stream/imm32 +<span id="L411" class="LineNr">411 </span> <span class="Comment"># call</span> +<span id="L412" class="LineNr">412 </span> e8/call clear-stream/disp32 +<span id="L413" class="LineNr">413 </span> <span class="Comment"># discard args</span> +<span id="L414" class="LineNr">414 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L415" class="LineNr">415 </span> <span class="Comment"># clear-stream(_test-error-stream)</span> +<span id="L416" class="LineNr">416 </span> <span class="Comment"># push args</span> +<span id="L417" class="LineNr">417 </span> 68/push _test-error-stream/imm32 +<span id="L418" class="LineNr">418 </span> <span class="Comment"># call</span> +<span id="L419" class="LineNr">419 </span> e8/call clear-stream/disp32 +<span id="L420" class="LineNr">420 </span> <span class="Comment"># discard args</span> +<span id="L421" class="LineNr">421 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L422" class="LineNr">422 </span> <span class="SalientComment">## initialize 'in'</span> +<span id="L423" class="LineNr">423 </span> <span class="Comment"># write(_test-stream, "3")</span> +<span id="L424" class="LineNr">424 </span> <span class="Comment"># push args</span> +<span id="L425" class="LineNr">425 </span> 68/push <span class="Constant">"3"</span>/imm32 +<span id="L426" class="LineNr">426 </span> 68/push _test-stream/imm32 +<span id="L427" class="LineNr">427 </span> <span class="Comment"># call</span> +<span id="L428" class="LineNr">428 </span> e8/call write/disp32 +<span id="L429" class="LineNr">429 </span> <span class="Comment"># discard args</span> +<span id="L430" class="LineNr">430 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L431" class="LineNr">431 </span> <span class="SalientComment">## initialize exit-descriptor 'ed'</span> +<span id="L432" class="LineNr">432 </span> <span class="Comment"># allocate on stack</span> +<span id="L433" class="LineNr">433 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L434" class="LineNr">434 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L435" class="LineNr">435 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L436" class="LineNr">436 </span> <span class="Comment"># size the exit-descriptor for the call to get-num below</span> +<span id="L437" class="LineNr">437 </span> <span class="Comment"># tailor-exit-descriptor(ed, 16)</span> +<span id="L438" class="LineNr">438 </span> <span class="Comment"># push args</span> +<span id="L439" class="LineNr">439 </span> 68/push 0x10/imm32/nbytes-of-args-for-get-num +<span id="L440" class="LineNr">440 </span> 50/push-EAX/ed +<span id="L441" class="LineNr">441 </span> <span class="Comment"># call</span> +<span id="L442" class="LineNr">442 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L443" class="LineNr">443 </span> <span class="Comment"># discard args</span> +<span id="L444" class="LineNr">444 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L445" class="LineNr">445 </span> <span class="SalientComment">## don't initialize Look</span> +<span id="L446" class="LineNr">446 </span> <span class="SalientComment">## get-num(in, out, err, ed)</span> +<span id="L447" class="LineNr">447 </span> <span class="Comment"># push args</span> +<span id="L448" class="LineNr">448 </span> 50/push-EAX/ed +<span id="L449" class="LineNr">449 </span> 68/push _test-error-stream/imm32 +<span id="L450" class="LineNr">450 </span> 68/push _test-output-stream/imm32 +<span id="L451" class="LineNr">451 </span> 68/push _test-buffered-file/imm32 +<span id="L452" class="LineNr">452 </span> <span class="Comment"># call</span> +<span id="L453" class="LineNr">453 </span> e8/call get-num/disp32 +<span id="L454" class="LineNr">454 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L455" class="LineNr">455 </span> <span class="Comment"># discard args</span> +<span id="L456" class="LineNr">456 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L457" class="LineNr">457 </span> <span class="SalientComment">## check that get-num tried to call exit(1)</span> +<span id="L458" class="LineNr">458 </span> <span class="Comment"># check-ints-equal(ed->value, 2, msg) # i.e. stop was called with value 1</span> +<span id="L459" class="LineNr">459 </span> <span class="Comment"># push args</span> +<span id="L460" class="LineNr">460 </span> 68/push <span class="Constant">"F - test-get-num-aborts-on-non-digit-in-Look"</span>/imm32 +<span id="L461" class="LineNr">461 </span> 68/push 2/imm32 +<span id="L462" class="LineNr">462 </span> <span class="Comment"># push ed->value</span> +<span id="L463" class="LineNr">463 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+4)</span> +<span id="L464" class="LineNr">464 </span> <span class="Comment"># call</span> +<span id="L465" class="LineNr">465 </span> e8/call check-ints-equal/disp32 +<span id="L466" class="LineNr">466 </span> <span class="Comment"># discard args</span> +<span id="L467" class="LineNr">467 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L468" class="LineNr">468 </span> <span class="Comment"># reclaim locals</span> +<span id="L469" class="LineNr">469 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L470" class="LineNr">470 </span> 5d/pop-to-EBP +<span id="L471" class="LineNr">471 </span> c3/return +<span id="L472" class="LineNr">472 </span> +<span id="L473" class="LineNr">473 </span><span class="SalientComment">## helpers</span> +<span id="L474" class="LineNr">474 </span> +<span id="L475" class="LineNr">475 </span><span class="Comment"># write(f, "Error: "+s+" expected\n") then stop(ed, 1)</span> +<span id="L476" class="LineNr">476 </span>expected: <span class="Comment"># ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte) -> <void></span> +<span id="L477" class="LineNr">477 </span> <span class="Comment"># prolog</span> +<span id="L478" class="LineNr">478 </span> 55/push-EBP +<span id="L479" class="LineNr">479 </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="L480" class="LineNr">480 </span> <span class="Comment"># write(f, "Error: ")</span> +<span id="L481" class="LineNr">481 </span> <span class="Comment"># push args</span> +<span id="L482" class="LineNr">482 </span> 68/push <span class="Constant">"Error: "</span>/imm32 +<span id="L483" class="LineNr">483 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L484" class="LineNr">484 </span> <span class="Comment"># call</span> +<span id="L485" class="LineNr">485 </span> e8/call write/disp32 +<span id="L486" class="LineNr">486 </span> <span class="Comment"># discard args</span> +<span id="L487" class="LineNr">487 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L488" class="LineNr">488 </span> <span class="Comment"># write(f, s)</span> +<span id="L489" class="LineNr">489 </span> <span class="Comment"># push args</span> +<span id="L490" class="LineNr">490 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L491" class="LineNr">491 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L492" class="LineNr">492 </span> <span class="Comment"># call</span> +<span id="L493" class="LineNr">493 </span> e8/call write/disp32 +<span id="L494" class="LineNr">494 </span> <span class="Comment"># discard args</span> +<span id="L495" class="LineNr">495 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L496" class="LineNr">496 </span> <span class="Comment"># write(f, " expected")</span> +<span id="L497" class="LineNr">497 </span> <span class="Comment"># push args</span> +<span id="L498" class="LineNr">498 </span> 68/push <span class="Constant">" expected"</span>/imm32 +<span id="L499" class="LineNr">499 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L500" class="LineNr">500 </span> <span class="Comment"># call</span> +<span id="L501" class="LineNr">501 </span> e8/call write/disp32 +<span id="L502" class="LineNr">502 </span> <span class="Comment"># discard args</span> +<span id="L503" class="LineNr">503 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L504" class="LineNr">504 </span> <span class="Comment"># write(f, Newline)</span> +<span id="L505" class="LineNr">505 </span> <span class="Comment"># push args</span> +<span id="L506" class="LineNr">506 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L507" class="LineNr">507 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L508" class="LineNr">508 </span> <span class="Comment"># call</span> +<span id="L509" class="LineNr">509 </span> e8/call write/disp32 +<span id="L510" class="LineNr">510 </span> <span class="Comment"># discard args</span> +<span id="L511" class="LineNr">511 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L512" class="LineNr">512 </span> <span class="Comment"># stop(ed, 1)</span> +<span id="L513" class="LineNr">513 </span> <span class="Comment"># push args</span> +<span id="L514" class="LineNr">514 </span> 68/push 1/imm32 +<span id="L515" class="LineNr">515 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L516" class="LineNr">516 </span> <span class="Comment"># call</span> +<span id="L517" class="LineNr">517 </span> e8/call stop/disp32 +<span id="L518" class="LineNr">518 </span> <span class="SalientComment">## should never get past this point</span> +<span id="L519" class="LineNr">519 </span> <span class="Comment"># epilog</span> +<span id="L520" class="LineNr">520 </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="L521" class="LineNr">521 </span> 5d/pop-to-EBP +<span id="L522" class="LineNr">522 </span> c3/return +<span id="L523" class="LineNr">523 </span> +<span id="L524" class="LineNr">524 </span><span class="Comment"># write(f, "Error: "+s+"\n") then stop(ed, 1)</span> +<span id="L525" class="LineNr">525 </span>error: <span class="Comment"># ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte) -> <void></span> +<span id="L526" class="LineNr">526 </span> <span class="Comment"># prolog</span> +<span id="L527" class="LineNr">527 </span> 55/push-EBP +<span id="L528" class="LineNr">528 </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="L529" class="LineNr">529 </span> <span class="Comment"># write(f, "Error: ")</span> +<span id="L530" class="LineNr">530 </span> <span class="Comment"># push args</span> +<span id="L531" class="LineNr">531 </span> 68/push <span class="Constant">"Error: "</span>/imm32 +<span id="L532" class="LineNr">532 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L533" class="LineNr">533 </span> <span class="Comment"># call</span> +<span id="L534" class="LineNr">534 </span> e8/call write/disp32 +<span id="L535" class="LineNr">535 </span> <span class="Comment"># discard args</span> +<span id="L536" class="LineNr">536 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L537" class="LineNr">537 </span> <span class="Comment"># write(f, s)</span> +<span id="L538" class="LineNr">538 </span> <span class="Comment"># push args</span> +<span id="L539" class="LineNr">539 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L540" class="LineNr">540 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L541" class="LineNr">541 </span> <span class="Comment"># call</span> +<span id="L542" class="LineNr">542 </span> e8/call write/disp32 +<span id="L543" class="LineNr">543 </span> <span class="Comment"># discard args</span> +<span id="L544" class="LineNr">544 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L545" class="LineNr">545 </span> <span class="Comment"># write(f, Newline)</span> +<span id="L546" class="LineNr">546 </span> <span class="Comment"># push args</span> +<span id="L547" class="LineNr">547 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L548" class="LineNr">548 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L549" class="LineNr">549 </span> <span class="Comment"># call</span> +<span id="L550" class="LineNr">550 </span> e8/call write/disp32 +<span id="L551" class="LineNr">551 </span> <span class="Comment"># discard args</span> +<span id="L552" class="LineNr">552 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L553" class="LineNr">553 </span> <span class="Comment"># stop(ed, 1)</span> +<span id="L554" class="LineNr">554 </span> <span class="Comment"># push args</span> +<span id="L555" class="LineNr">555 </span> 68/push 1/imm32 +<span id="L556" class="LineNr">556 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L557" class="LineNr">557 </span> <span class="Comment"># call</span> +<span id="L558" class="LineNr">558 </span> e8/call stop/disp32 +<span id="L559" class="LineNr">559 </span> <span class="SalientComment">## should never get past this point</span> +<span id="L560" class="LineNr">560 </span> <span class="Comment"># epilog</span> +<span id="L561" class="LineNr">561 </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="L562" class="LineNr">562 </span> 5d/pop-to-EBP +<span id="L563" class="LineNr">563 </span> c3/return +<span id="L564" class="LineNr">564 </span> +<span id="L565" class="LineNr">565 </span><span class="Comment"># read a byte from 'f', and store it in 'Look'</span> +<span id="L566" class="LineNr">566 </span>get-char: <span class="Comment"># f : (address buffered-file) -> <void></span> +<span id="L567" class="LineNr">567 </span> <span class="Comment"># prolog</span> +<span id="L568" class="LineNr">568 </span> 55/push-EBP +<span id="L569" class="LineNr">569 </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="L570" class="LineNr">570 </span> <span class="Comment"># save registers</span> +<span id="L571" class="LineNr">571 </span> 50/push-EAX +<span id="L572" class="LineNr">572 </span> <span class="Comment"># read-byte(f)</span> +<span id="L573" class="LineNr">573 </span> <span class="Comment"># push args</span> +<span id="L574" class="LineNr">574 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L575" class="LineNr">575 </span> <span class="Comment"># call</span> +<span id="L576" class="LineNr">576 </span> e8/call read-byte/disp32 +<span id="L577" class="LineNr">577 </span> <span class="Comment"># discard args</span> +<span id="L578" class="LineNr">578 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L579" class="LineNr">579 </span> <span class="Comment"># save EAX to Look</span> +<span id="L580" class="LineNr">580 </span> 89/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX to *Look</span> +<span id="L581" class="LineNr">581 </span> <span class="Comment"># restore registers</span> +<span id="L582" class="LineNr">582 </span> 58/pop-to-EAX +<span id="L583" class="LineNr">583 </span> <span class="Comment"># epilog</span> +<span id="L584" class="LineNr">584 </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="L585" class="LineNr">585 </span> 5d/pop-to-EBP +<span id="L586" class="LineNr">586 </span> c3/return +<span id="L587" class="LineNr">587 </span> +<span id="L588" class="LineNr">588 </span>is-digit?: <span class="Comment"># c : int -> bool/EAX</span> +<span id="L589" class="LineNr">589 </span> <span class="Comment"># prolog</span> +<span id="L590" class="LineNr">590 </span> 55/push-EBP +<span id="L591" class="LineNr">591 </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="L592" class="LineNr">592 </span> <span class="Comment"># EAX = false</span> +<span id="L593" class="LineNr">593 </span> b8/copy-to-EAX 0/imm32 +<span id="L594" class="LineNr">594 </span> <span class="Comment"># if c < '0' return false</span> +<span id="L595" class="LineNr">595 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 0x30/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L596" class="LineNr">596 </span> 7c/jump-if-lesser $is-digit?:end/disp8 +<span id="L597" class="LineNr">597 </span> <span class="Comment"># if c > '9' return false</span> +<span id="L598" class="LineNr">598 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 0x39/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L599" class="LineNr">599 </span> 7f/jump-if-greater $is-digit?:end/disp8 +<span id="L600" class="LineNr">600 </span> <span class="Comment"># otherwise return true</span> +<span id="L601" class="LineNr">601 </span> b8/copy-to-EAX 1/imm32 +<span id="L602" class="LineNr">602 </span>$is-digit?:end: +<span id="L603" class="LineNr">603 </span> <span class="Comment"># epilog</span> +<span id="L604" class="LineNr">604 </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="L605" class="LineNr">605 </span> 5d/pop-to-EBP +<span id="L606" class="LineNr">606 </span> c3/return +<span id="L607" class="LineNr">607 </span> +<span id="L608" class="LineNr">608 </span>== data +<span id="L609" class="LineNr">609 </span> +<span id="L610" class="LineNr">610 </span><span class="Special">Look</span>: +<span id="L611" class="LineNr">611 </span> 00 00 00 00 +<span id="L612" class="LineNr">612 </span> +<span id="L613" class="LineNr">613 </span>_test-output-stream: +<span id="L614" class="LineNr">614 </span> <span class="Comment"># current write index</span> +<span id="L615" class="LineNr">615 </span> 00 00 00 00 +<span id="L616" class="LineNr">616 </span> <span class="Comment"># current read index</span> +<span id="L617" class="LineNr">617 </span> 00 00 00 00 +<span id="L618" class="LineNr">618 </span> <span class="Comment"># length (= 8)</span> +<span id="L619" class="LineNr">619 </span> 08 00 00 00 +<span id="L620" class="LineNr">620 </span> <span class="Comment"># data</span> +<span id="L621" class="LineNr">621 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L622" class="LineNr">622 </span> +<span id="L623" class="LineNr">623 </span>_test-error-stream: +<span id="L624" class="LineNr">624 </span> <span class="Comment"># current write index</span> +<span id="L625" class="LineNr">625 </span> 00 00 00 00 +<span id="L626" class="LineNr">626 </span> <span class="Comment"># current read index</span> +<span id="L627" class="LineNr">627 </span> 00 00 00 00 +<span id="L628" class="LineNr">628 </span> <span class="Comment"># length (= 8)</span> +<span id="L629" class="LineNr">629 </span> 08 00 00 00 +<span id="L630" class="LineNr">630 </span> <span class="Comment"># data</span> +<span id="L631" class="LineNr">631 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L632" class="LineNr">632 </span> +<span id="L633" class="LineNr">633 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/apps/crenshaw2-1b.subx.html b/html/subx/apps/crenshaw2-1b.subx.html new file mode 100644 index 00000000..21c9ab2f --- /dev/null +++ b/html/subx/apps/crenshaw2-1b.subx.html @@ -0,0 +1,899 @@ +<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> +<html> +<head> +<meta http-equiv="content-type" content="text/html; charset=UTF-8"> +<title>Mu - subx/apps/crenshaw2-1b.subx</title> +<meta name="Generator" content="Vim/8.0"> +<meta name="plugin-version" content="vim7.4_v2"> +<meta name="syntax" content="none"> +<meta name="settings" content="number_lines,use_css,no_foldcolumn,expand_tabs,line_ids,prevent_copy="> +<meta name="colorscheme" content="minimal"> +<style type="text/css"> +<!-- +pre { font-family: monospace; color: #aaaaaa; background-color: #080808; } +body { font-size: 12pt; font-family: monospace; color: #aaaaaa; background-color: #080808; } +a { color:#eeeeee; text-decoration: none; } +a:hover { text-decoration: underline; } +* { font-size: 12pt; font-size: 1em; } +.CommentedCode { color: #6c6c6c; } +.LineNr { color: #444444; } +.Constant { color: #00a0a0; } +.Delimiter { color: #800080; } +.Special { color: #c00000; } +.Comment { color: #9090ff; } +.Comment a { color:#0000ee; text-decoration:underline; } +.SalientComment { color: #00ffff; } +--> +</style> + +<script type='text/javascript'> +<!-- + +/* function to open any folds containing a jumped-to line before jumping to it */ +function JumpToLine() +{ + var lineNum; + lineNum = window.location.hash; + lineNum = lineNum.substr(1); /* strip off '#' */ + + if (lineNum.indexOf('L') == -1) { + lineNum = 'L'+lineNum; + } + lineElem = document.getElementById(lineNum); + /* Always jump to new location even if the line was hidden inside a fold, or + * we corrected the raw number to a line ID. + */ + if (lineElem) { + lineElem.scrollIntoView(true); + } + return true; +} +if ('onhashchange' in window) { + window.onhashchange = JumpToLine; +} + +--> +</script> +</head> +<body onload='JumpToLine();'> +<pre id='vimCodeElement'> +<span id="L1" class="LineNr"> 1 </span><span class="SalientComment">## Port of <a href="https://github.com/akkartik/crenshaw/blob/master/tutor2.1.pas">https://github.com/akkartik/crenshaw/blob/master/tutor2.1.pas</a></span> +<span id="L2" class="LineNr"> 2 </span><span class="Comment"># Corresponds to the section "single digits" in <a href="https://compilers.iecc.com/crenshaw/tutor2.txt">https://compilers.iecc.com/crenshaw/tutor2.txt</a></span> +<span id="L3" class="LineNr"> 3 </span><span class="Comment"># except that we support numbers of multiple digits.</span> +<span id="L4" class="LineNr"> 4 </span><span class="Comment">#</span> +<span id="L5" class="LineNr"> 5 </span><span class="Comment"># To run (from the subx directory):</span> +<span id="L6" class="LineNr"> 6 </span><span class="Comment"># $ ./subx translate *.subx apps/crenshaw2-1.subx -o crenshaw2-1</span> +<span id="L7" class="LineNr"> 7 </span><span class="Comment"># $ echo '1a' |./subx run apps/crenshaw2-1</span> +<span id="L8" class="LineNr"> 8 </span><span class="Comment"># Expected output (not working yet):</span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># # syscall(exit, 1a)</span> +<span id="L10" class="LineNr"> 10 </span><span class="Comment"># bb/copy-to-EBX 3/imm32</span> +<span id="L11" class="LineNr"> 11 </span><span class="Comment"># b8/copy-to-EAX 1/imm32/exit</span> +<span id="L12" class="LineNr"> 12 </span><span class="Comment"># cd/syscall 0x80/imm8</span> +<span id="L13" class="LineNr"> 13 </span><span class="Comment">#</span> +<span id="L14" class="LineNr"> 14 </span><span class="Comment"># To run the generated output:</span> +<span id="L15" class="LineNr"> 15 </span><span class="Comment"># $ echo '1a' |./subx run apps/crenshaw2-1 > z1.subx</span> +<span id="L16" class="LineNr"> 16 </span><span class="Comment"># $ ./subx translate z1.subx -o z1</span> +<span id="L17" class="LineNr"> 17 </span><span class="Comment"># $ ./subx run z1</span> +<span id="L18" class="LineNr"> 18 </span><span class="Comment"># $ echo $?</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment"># 26 # 0x1a in decimal</span> +<span id="L20" class="LineNr"> 20 </span><span class="Comment">#</span> +<span id="L21" class="LineNr"> 21 </span><span class="Comment"># Stdin must contain just a single hex digit. Other input will print an error:</span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment"># $ echo 'xyz' |./subx run apps/crenshaw2-1</span> +<span id="L23" class="LineNr"> 23 </span><span class="Comment"># Error: integer expected</span> +<span id="L24" class="LineNr"> 24 </span><span class="Comment">#</span> +<span id="L25" class="LineNr"> 25 </span><span class="Comment"># Names in this file sometimes follow Crenshaw's original rather than my usual</span> +<span id="L26" class="LineNr"> 26 </span><span class="Comment"># naming conventions.</span> +<span id="L27" class="LineNr"> 27 </span> +<span id="L28" class="LineNr"> 28 </span>== code +<span id="L29" class="LineNr"> 29 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L31" class="LineNr"> 31 </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> +<span id="L32" class="LineNr"> 32 </span> +<span id="L33" class="LineNr"> 33 </span><span class="Comment"># main: run tests if necessary, call 'compile' if not</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># prolog</span> +<span id="L35" class="LineNr"> 35 </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="L36" class="LineNr"> 36 </span> <span class="Comment"># if (argc > 1)</span> +<span id="L37" class="LineNr"> 37 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/disp8 1/imm32 <span class="Comment"># compare *EBP</span> +<span id="L38" class="LineNr"> 38 </span> 7e/jump-if-lesser-or-equal $run-main/disp8 +<span id="L39" class="LineNr"> 39 </span> <span class="Comment"># and if (argv[1] == "test")</span> +<span id="L40" class="LineNr"> 40 </span> <span class="Comment"># push args</span> +<span id="L41" class="LineNr"> 41 </span> 68/push <span class="Constant">"test"</span>/imm32 +<span id="L42" class="LineNr"> 42 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># call</span> +<span id="L44" class="LineNr"> 44 </span> e8/call kernel-string-equal/disp32 +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># discard args</span> +<span id="L46" class="LineNr"> 46 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># check result</span> +<span id="L48" class="LineNr"> 48 </span> 3d/compare-EAX 1/imm32 +<span id="L49" class="LineNr"> 49 </span> 75/jump-if-not-equal $run-main/disp8 +<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># then return run-tests()</span> +<span id="L51" class="LineNr"> 51 </span> e8/call run-tests/disp32 +<span id="L52" class="LineNr"> 52 </span><span class="CommentedCode">#? e8/call test-get-num-reads-multiple-digits/disp32</span> +<span id="L53" class="LineNr"> 53 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EBX</span> +<span id="L54" class="LineNr"> 54 </span> eb/jump $main:end/disp8 +<span id="L55" class="LineNr"> 55 </span>$run-main: +<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># allocate space for an exit-descriptor</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L58" class="LineNr"> 58 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L59" class="LineNr"> 59 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># clear ed->target (so we really exit)</span> +<span id="L61" class="LineNr"> 61 </span> c7/copy 0/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># copy to *EAX</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># compile(Stdin, 1/stdout, 2/stderr, ed)</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># push args</span> +<span id="L64" class="LineNr"> 64 </span> 50/push-EAX/ed +<span id="L65" class="LineNr"> 65 </span> 68/push 2/imm32/stderr +<span id="L66" class="LineNr"> 66 </span> 68/push 1/imm32/stdout +<span id="L67" class="LineNr"> 67 </span> 68/push <span class="Special">Stdin</span>/imm32 +<span id="L68" class="LineNr"> 68 </span> <span class="Comment"># call</span> +<span id="L69" class="LineNr"> 69 </span> e8/call compile/disp32 +<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># discard args</span> +<span id="L71" class="LineNr"> 71 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># syscall(exit, 0)</span> +<span id="L73" class="LineNr"> 73 </span> bb/copy-to-EBX 0/imm32 +<span id="L74" class="LineNr"> 74 </span>$main:end: +<span id="L75" class="LineNr"> 75 </span> b8/copy-to-EAX 1/imm32/exit +<span id="L76" class="LineNr"> 76 </span> cd/syscall 0x80/imm8 +<span id="L77" class="LineNr"> 77 </span> +<span id="L78" class="LineNr"> 78 </span><span class="Comment"># the main entry point</span> +<span id="L79" class="LineNr"> 79 </span>compile: <span class="Comment"># in : fd or (address stream), out : fd or (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void></span> +<span id="L80" class="LineNr"> 80 </span> <span class="Comment"># prolog</span> +<span id="L81" class="LineNr"> 81 </span> 55/push-EBP +<span id="L82" class="LineNr"> 82 </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="L83" class="LineNr"> 83 </span> <span class="Comment"># save registers</span> +<span id="L84" class="LineNr"> 84 </span> 50/push-EAX +<span id="L85" class="LineNr"> 85 </span> 51/push-ECX +<span id="L86" class="LineNr"> 86 </span> <span class="Comment"># Look = get-char(in)</span> +<span id="L87" class="LineNr"> 87 </span> <span class="Comment"># push args</span> +<span id="L88" class="LineNr"> 88 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L89" class="LineNr"> 89 </span> <span class="Comment"># call</span> +<span id="L90" class="LineNr"> 90 </span> e8/call get-char/disp32 +<span id="L91" class="LineNr"> 91 </span> <span class="Comment"># discard args</span> +<span id="L92" class="LineNr"> 92 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L93" class="LineNr"> 93 </span> <span class="Comment"># var num/ECX : (address stream) on the stack</span> +<span id="L94" class="LineNr"> 94 </span> <span class="Comment"># Numbers can be 32 bits or 8 hex bytes long. One of them will be in 'Look', so we need space for 7 bytes.</span> +<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># We won't add more, so that we can get overflow-handling for free.</span> +<span id="L96" class="LineNr"> 96 </span> <span class="Comment"># Add 12 bytes for 'read', 'write' and 'length' fields, for a total of 19 bytes, or 0x13 in hex.</span> +<span id="L97" class="LineNr"> 97 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x13/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L98" class="LineNr"> 98 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to ECX</span> +<span id="L99" class="LineNr"> 99 </span> <span class="Comment"># num->length = 7</span> +<span id="L100" class="LineNr">100 </span> c7/copy 1/mod/*+disp8 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 7/imm32 <span class="Comment"># copy to *(ECX+8)</span> +<span id="L101" class="LineNr">101 </span> <span class="Comment"># clear-stream(num)</span> +<span id="L102" class="LineNr">102 </span> <span class="Comment"># push args</span> +<span id="L103" class="LineNr">103 </span> 51/push-ECX +<span id="L104" class="LineNr">104 </span> <span class="Comment"># call</span> +<span id="L105" class="LineNr">105 </span> e8/call clear-stream/disp32 +<span id="L106" class="LineNr">106 </span> <span class="Comment"># discard args</span> +<span id="L107" class="LineNr">107 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L108" class="LineNr">108 </span> <span class="Comment"># get-num(in, num, err, ed)</span> +<span id="L109" class="LineNr">109 </span> <span class="Comment"># push args</span> +<span id="L110" class="LineNr">110 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+20)</span> +<span id="L111" class="LineNr">111 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L112" class="LineNr">112 </span> 51/push-ECX/num +<span id="L113" class="LineNr">113 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L114" class="LineNr">114 </span> <span class="Comment"># call</span> +<span id="L115" class="LineNr">115 </span> e8/call get-num/disp32 +<span id="L116" class="LineNr">116 </span> <span class="Comment"># discard args</span> +<span id="L117" class="LineNr">117 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L118" class="LineNr">118 </span> <span class="Comment"># EAX = write(_test-stream, "Ab")</span> +<span id="L119" class="LineNr">119 </span> <span class="Comment"># push args</span> +<span id="L120" class="LineNr">120 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L121" class="LineNr">121 </span> 68/push _test-stream/imm32 +<span id="L122" class="LineNr">122 </span> <span class="Comment"># call</span> +<span id="L123" class="LineNr">123 </span> e8/call write/disp32 +<span id="L124" class="LineNr">124 </span> <span class="Comment"># discard args</span> +<span id="L125" class="LineNr">125 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L126" class="LineNr">126 </span> <span class="Comment"># EAX = write(out, "bb/copy-to-EBX ")</span> +<span id="L127" class="LineNr">127 </span> <span class="Comment"># push args</span> +<span id="L128" class="LineNr">128 </span> 68/push <span class="Constant">"bb/copy-to-EBX "</span>/imm32 +<span id="L129" class="LineNr">129 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L130" class="LineNr">130 </span> <span class="Comment"># call</span> +<span id="L131" class="LineNr">131 </span> e8/call write/disp32 +<span id="L132" class="LineNr">132 </span> <span class="Comment"># discard args</span> +<span id="L133" class="LineNr">133 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L134" class="LineNr">134 </span> <span class="Comment"># write-stream(out, num)</span> +<span id="L135" class="LineNr">135 </span> <span class="Comment"># push args</span> +<span id="L136" class="LineNr">136 </span> 51/push-ECX/num +<span id="L137" class="LineNr">137 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L138" class="LineNr">138 </span> <span class="Comment"># call</span> +<span id="L139" class="LineNr">139 </span> e8/call write-stream/disp32 +<span id="L140" class="LineNr">140 </span> <span class="Comment"># discard args</span> +<span id="L141" class="LineNr">141 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L142" class="LineNr">142 </span> <span class="Comment"># write(out, Newline)</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment"># push args</span> +<span id="L144" class="LineNr">144 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L145" class="LineNr">145 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L146" class="LineNr">146 </span> <span class="Comment"># call</span> +<span id="L147" class="LineNr">147 </span> e8/call write/disp32 +<span id="L148" class="LineNr">148 </span> <span class="Comment"># discard args</span> +<span id="L149" class="LineNr">149 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L150" class="LineNr">150 </span> <span class="Comment"># EAX = write(out, "b8/copy-to-EAX 1/imm32/exit")</span> +<span id="L151" class="LineNr">151 </span> <span class="Comment"># push args</span> +<span id="L152" class="LineNr">152 </span> 68/push <span class="Constant">"b8/copy-to-EAX 1/imm32/exit"</span>/imm32 +<span id="L153" class="LineNr">153 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L154" class="LineNr">154 </span> <span class="Comment"># call</span> +<span id="L155" class="LineNr">155 </span> e8/call write/disp32 +<span id="L156" class="LineNr">156 </span> <span class="Comment"># discard args</span> +<span id="L157" class="LineNr">157 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L158" class="LineNr">158 </span> <span class="Comment"># EAX = write(out, Newline)</span> +<span id="L159" class="LineNr">159 </span> <span class="Comment"># push args</span> +<span id="L160" class="LineNr">160 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L161" class="LineNr">161 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L162" class="LineNr">162 </span> <span class="Comment"># call</span> +<span id="L163" class="LineNr">163 </span> e8/call write/disp32 +<span id="L164" class="LineNr">164 </span> <span class="Comment"># discard args</span> +<span id="L165" class="LineNr">165 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L166" class="LineNr">166 </span> <span class="Comment"># EAX = write(out, "cd/syscall 0x80/imm8")</span> +<span id="L167" class="LineNr">167 </span> <span class="Comment"># push args</span> +<span id="L168" class="LineNr">168 </span> 68/push <span class="Constant">"cd/syscall 0x80/imm8"</span>/imm32 +<span id="L169" class="LineNr">169 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L170" class="LineNr">170 </span> <span class="Comment"># call</span> +<span id="L171" class="LineNr">171 </span> e8/call write/disp32 +<span id="L172" class="LineNr">172 </span> <span class="Comment"># discard args</span> +<span id="L173" class="LineNr">173 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L174" class="LineNr">174 </span> <span class="Comment"># EAX = write(out, Newline)</span> +<span id="L175" class="LineNr">175 </span> <span class="Comment"># push args</span> +<span id="L176" class="LineNr">176 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L177" class="LineNr">177 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L178" class="LineNr">178 </span> <span class="Comment"># call</span> +<span id="L179" class="LineNr">179 </span> e8/call write/disp32 +<span id="L180" class="LineNr">180 </span> <span class="Comment"># discard args</span> +<span id="L181" class="LineNr">181 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L182" class="LineNr">182 </span> <span class="Comment"># restore registers</span> +<span id="L183" class="LineNr">183 </span> 59/pop-to-ECX +<span id="L184" class="LineNr">184 </span> 58/pop-to-EAX +<span id="L185" class="LineNr">185 </span> <span class="Comment"># epilog</span> +<span id="L186" class="LineNr">186 </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="L187" class="LineNr">187 </span> 5d/pop-to-EBP +<span id="L188" class="LineNr">188 </span> c3/return +<span id="L189" class="LineNr">189 </span> +<span id="L190" class="LineNr">190 </span><span class="Comment"># Read a sequence of digits into 'out'. Abort if there are none, or if there is</span> +<span id="L191" class="LineNr">191 </span><span class="Comment"># no space in 'out'.</span> +<span id="L192" class="LineNr">192 </span><span class="Comment"># Input comes from the global variable 'Look' (first byte) and the argument</span> +<span id="L193" class="LineNr">193 </span><span class="Comment"># 'in' (rest). We leave the next byte from 'in' into 'Look' on exit.</span> +<span id="L194" class="LineNr">194 </span>get-num: <span class="Comment"># in : (address buffered-file), out : (address stream), err : fd or (address stream), ed : (address exit-descriptor) -> <void></span> +<span id="L195" class="LineNr">195 </span> <span class="Comment"># pseudocode:</span> +<span id="L196" class="LineNr">196 </span> <span class="Comment"># if !is-digit?(Look) expected(ed, err, "integer")</span> +<span id="L197" class="LineNr">197 </span> <span class="Comment"># do</span> +<span id="L198" class="LineNr">198 </span> <span class="Comment"># if out.write >= out.length</span> +<span id="L199" class="LineNr">199 </span> <span class="Comment"># write(err, "Error: too many digits in number\n")</span> +<span id="L200" class="LineNr">200 </span> <span class="Comment"># stop(ed, 1)</span> +<span id="L201" class="LineNr">201 </span> <span class="Comment"># out.data[out.write] = LSB(Look)</span> +<span id="L202" class="LineNr">202 </span> <span class="Comment"># ++out.write</span> +<span id="L203" class="LineNr">203 </span> <span class="Comment"># Look = get-char(in)</span> +<span id="L204" class="LineNr">204 </span> <span class="Comment"># while is-digit?(Look)</span> +<span id="L205" class="LineNr">205 </span> <span class="Comment"># This is complicated because I don't want to hard-code the error strategy in</span> +<span id="L206" class="LineNr">206 </span> <span class="Comment"># a general helper like write-byte. Maybe I should just create a local helper.</span> +<span id="L207" class="LineNr">207 </span> <span class="Comment">#</span> +<span id="L208" class="LineNr">208 </span> <span class="Comment"># within the loop we'll try to keep things in registers:</span> +<span id="L209" class="LineNr">209 </span> <span class="Comment"># ESI : in</span> +<span id="L210" class="LineNr">210 </span> <span class="Comment"># EDI : out</span> +<span id="L211" class="LineNr">211 </span> <span class="Comment"># EAX : temp</span> +<span id="L212" class="LineNr">212 </span> <span class="Comment"># ECX : out->write</span> +<span id="L213" class="LineNr">213 </span> <span class="Comment"># EDX : out->length</span> +<span id="L214" class="LineNr">214 </span> <span class="Comment"># EBX : temp2</span> +<span id="L215" class="LineNr">215 </span> <span class="Comment"># We can't allocate Look to a register because it gets written implicitly in</span> +<span id="L216" class="LineNr">216 </span> <span class="Comment"># get-char in each iteration of the loop. (Thereby demonstrating that it's</span> +<span id="L217" class="LineNr">217 </span> <span class="Comment"># not the right interface for us. But we'll keep it just to follow Crenshaw.)</span> +<span id="L218" class="LineNr">218 </span> <span class="Comment">#</span> +<span id="L219" class="LineNr">219 </span> <span class="Comment"># prolog</span> +<span id="L220" class="LineNr">220 </span> 55/push-EBP +<span id="L221" class="LineNr">221 </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="L222" class="LineNr">222 </span> <span class="Comment"># EAX = is-digit?(Look)</span> +<span id="L223" class="LineNr">223 </span> <span class="Comment"># push args</span> +<span id="L224" class="LineNr">224 </span> ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># push *Look</span> +<span id="L225" class="LineNr">225 </span> <span class="Comment"># call</span> +<span id="L226" class="LineNr">226 </span> e8/call is-digit?/disp32 +<span id="L227" class="LineNr">227 </span> <span class="Comment"># discard args</span> +<span id="L228" class="LineNr">228 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L229" class="LineNr">229 </span> <span class="Comment"># if EAX == 0 error</span> +<span id="L230" class="LineNr">230 </span> 3d/compare-EAX 0/imm32 +<span id="L231" class="LineNr">231 </span> 75/jump-if-not-equal $get-num:main/disp8 +<span id="L232" class="LineNr">232 </span> <span class="Comment"># expected(ed, err, "integer")</span> +<span id="L233" class="LineNr">233 </span> <span class="Comment"># push args</span> +<span id="L234" class="LineNr">234 </span> 68/push <span class="Constant">"integer"</span>/imm32 +<span id="L235" class="LineNr">235 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L236" class="LineNr">236 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+20)</span> +<span id="L237" class="LineNr">237 </span> <span class="Comment"># call</span> +<span id="L238" class="LineNr">238 </span> e8/call expected/disp32 <span class="Comment"># never returns</span> +<span id="L239" class="LineNr">239 </span> <span class="Comment"># discard args</span> +<span id="L240" class="LineNr">240 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L241" class="LineNr">241 </span>$get-num:main: +<span id="L242" class="LineNr">242 </span> <span class="Comment"># save registers</span> +<span id="L243" class="LineNr">243 </span> 50/push-EAX +<span id="L244" class="LineNr">244 </span> 51/push-ECX +<span id="L245" class="LineNr">245 </span> 52/push-EDX +<span id="L246" class="LineNr">246 </span> 53/push-EBX +<span id="L247" class="LineNr">247 </span> 56/push-ESI +<span id="L248" class="LineNr">248 </span> 57/push-EDI +<span id="L249" class="LineNr">249 </span> <span class="Comment"># read necessary variables to registers</span> +<span id="L250" class="LineNr">250 </span> <span class="Comment"># ESI = in</span> +<span id="L251" class="LineNr">251 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ESI</span> +<span id="L252" class="LineNr">252 </span> <span class="Comment"># EDI = out</span> +<span id="L253" class="LineNr">253 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDI</span> +<span id="L254" class="LineNr">254 </span> <span class="Comment"># ECX = out->write</span> +<span id="L255" class="LineNr">255 </span> 8b/copy 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EDI to ECX</span> +<span id="L256" class="LineNr">256 </span> <span class="Comment"># EDX = out->length</span> +<span id="L257" class="LineNr">257 </span> 8b/copy 1/mod/*+disp8 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 2/r32/EDX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EDI+8) to EDX</span> +<span id="L258" class="LineNr">258 </span>$get-num:loop: +<span id="L259" class="LineNr">259 </span> <span class="Comment"># if out->write >= out->length error</span> +<span id="L260" class="LineNr">260 </span> 3b/compare 3/mod/direct 1/rm32/ECX <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"># compare EDX with ECX</span> +<span id="L261" class="LineNr">261 </span> 7d/jump-if-lesser $get-num:loop-stage2/disp8 +<span id="L262" class="LineNr">262 </span> <span class="Comment"># error(ed, err, "get-num: too many digits in number") # TODO: show full number</span> +<span id="L263" class="LineNr">263 </span> <span class="Comment"># push args</span> +<span id="L264" class="LineNr">264 </span> 68/push <span class="Constant">"get-num: too many digits in number"</span>/imm32 +<span id="L265" class="LineNr">265 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L266" class="LineNr">266 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x14/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+20)</span> +<span id="L267" class="LineNr">267 </span> <span class="Comment"># call</span> +<span id="L268" class="LineNr">268 </span> e8/call error/disp32 <span class="Comment"># never returns</span> +<span id="L269" class="LineNr">269 </span> <span class="Comment"># discard args</span> +<span id="L270" class="LineNr">270 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L271" class="LineNr">271 </span>$get-num:loop-stage2: +<span id="L272" class="LineNr">272 </span> <span class="Comment"># out->data[out->write] = LSB(Look)</span> +<span id="L273" class="LineNr">273 </span> 8d/copy-address 1/mod/*+disp8 4/rm32/sib 7/base/EDI 1/index/ECX <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy EDI+ECX+12 to EBX</span> +<span id="L274" class="LineNr">274 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># copy *Look to EAX</span> +<span id="L275" class="LineNr">275 </span> 88/copy-byte 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/AL <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at AL to *EBX</span> +<span id="L276" class="LineNr">276 </span> <span class="Comment"># ++out->write</span> +<span id="L277" class="LineNr">277 </span> 41/increment-ECX +<span id="L278" class="LineNr">278 </span> <span class="Comment"># Look = get-char(in)</span> +<span id="L279" class="LineNr">279 </span> <span class="Comment"># push args</span> +<span id="L280" class="LineNr">280 </span> 56/push-ESI +<span id="L281" class="LineNr">281 </span> <span class="Comment"># call</span> +<span id="L282" class="LineNr">282 </span> e8/call get-char/disp32 +<span id="L283" class="LineNr">283 </span> <span class="Comment"># discard args</span> +<span id="L284" class="LineNr">284 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L285" class="LineNr">285 </span> <span class="Comment"># EAX = is-digit?(Look)</span> +<span id="L286" class="LineNr">286 </span> <span class="Comment"># push args</span> +<span id="L287" class="LineNr">287 </span> ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># push *Look</span> +<span id="L288" class="LineNr">288 </span> <span class="Comment"># call</span> +<span id="L289" class="LineNr">289 </span> e8/call is-digit?/disp32 +<span id="L290" class="LineNr">290 </span> <span class="Comment"># discard args</span> +<span id="L291" class="LineNr">291 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L292" class="LineNr">292 </span> <span class="Comment"># if EAX loop</span> +<span id="L293" class="LineNr">293 </span> 3d/compare-EAX 0/imm32 +<span id="L294" class="LineNr">294 </span> 0f 85/jump-if-not-equal $get-num:loop/disp32 +<span id="L295" class="LineNr">295 </span>$get-num:loop-end: +<span id="L296" class="LineNr">296 </span> <span class="Comment"># persist necessary variables from registers</span> +<span id="L297" class="LineNr">297 </span> 89/copy 0/mod/indirect 7/rm32/EDI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ECX to *EDI</span> +<span id="L298" class="LineNr">298 </span> <span class="Comment"># restore registers</span> +<span id="L299" class="LineNr">299 </span> 5f/pop-to-EDI +<span id="L300" class="LineNr">300 </span> 5e/pop-to-ESI +<span id="L301" class="LineNr">301 </span> 5b/pop-to-EBX +<span id="L302" class="LineNr">302 </span> 5a/pop-to-EDX +<span id="L303" class="LineNr">303 </span> 59/pop-to-ECX +<span id="L304" class="LineNr">304 </span> 58/pop-to-EAX +<span id="L305" class="LineNr">305 </span> <span class="Comment"># epilog</span> +<span id="L306" class="LineNr">306 </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="L307" class="LineNr">307 </span> 5d/pop-to-EBP +<span id="L308" class="LineNr">308 </span> c3/return +<span id="L309" class="LineNr">309 </span> +<span id="L310" class="LineNr">310 </span>test-get-num-reads-single-digit: +<span id="L311" class="LineNr">311 </span> <span class="SalientComment">## check that get-num returns first character if it's a digit</span> +<span id="L312" class="LineNr">312 </span> <span class="Comment"># This test uses exit-descriptors. Use EBP for setting up local variables.</span> +<span id="L313" class="LineNr">313 </span> 55/push-EBP +<span id="L314" class="LineNr">314 </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="L315" class="LineNr">315 </span> <span class="SalientComment">## clear all streams</span> +<span id="L316" class="LineNr">316 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L317" class="LineNr">317 </span> <span class="Comment"># push args</span> +<span id="L318" class="LineNr">318 </span> 68/push _test-stream/imm32 +<span id="L319" class="LineNr">319 </span> <span class="Comment"># call</span> +<span id="L320" class="LineNr">320 </span> e8/call clear-stream/disp32 +<span id="L321" class="LineNr">321 </span> <span class="Comment"># discard args</span> +<span id="L322" class="LineNr">322 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L323" class="LineNr">323 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L324" class="LineNr">324 </span> <span class="Comment"># push args</span> +<span id="L325" class="LineNr">325 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L326" class="LineNr">326 </span> 05/add-to-EAX 4/imm32 +<span id="L327" class="LineNr">327 </span> 50/push-EAX +<span id="L328" class="LineNr">328 </span> <span class="Comment"># call</span> +<span id="L329" class="LineNr">329 </span> e8/call clear-stream/disp32 +<span id="L330" class="LineNr">330 </span> <span class="Comment"># discard args</span> +<span id="L331" class="LineNr">331 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L332" class="LineNr">332 </span> <span class="Comment"># clear-stream(_test-output-stream)</span> +<span id="L333" class="LineNr">333 </span> <span class="Comment"># push args</span> +<span id="L334" class="LineNr">334 </span> 68/push _test-output-stream/imm32 +<span id="L335" class="LineNr">335 </span> <span class="Comment"># call</span> +<span id="L336" class="LineNr">336 </span> e8/call clear-stream/disp32 +<span id="L337" class="LineNr">337 </span> <span class="Comment"># discard args</span> +<span id="L338" class="LineNr">338 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L339" class="LineNr">339 </span> <span class="Comment"># clear-stream(_test-error-stream)</span> +<span id="L340" class="LineNr">340 </span> <span class="Comment"># push args</span> +<span id="L341" class="LineNr">341 </span> 68/push _test-error-stream/imm32 +<span id="L342" class="LineNr">342 </span> <span class="Comment"># call</span> +<span id="L343" class="LineNr">343 </span> e8/call clear-stream/disp32 +<span id="L344" class="LineNr">344 </span> <span class="Comment"># discard args</span> +<span id="L345" class="LineNr">345 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L346" class="LineNr">346 </span> <span class="SalientComment">## initialize 'in'</span> +<span id="L347" class="LineNr">347 </span> <span class="Comment"># write(_test-stream, "3")</span> +<span id="L348" class="LineNr">348 </span> <span class="Comment"># push args</span> +<span id="L349" class="LineNr">349 </span> 68/push <span class="Constant">"3"</span>/imm32 +<span id="L350" class="LineNr">350 </span> 68/push _test-stream/imm32 +<span id="L351" class="LineNr">351 </span> <span class="Comment"># call</span> +<span id="L352" class="LineNr">352 </span> e8/call write/disp32 +<span id="L353" class="LineNr">353 </span> <span class="Comment"># discard args</span> +<span id="L354" class="LineNr">354 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L355" class="LineNr">355 </span> <span class="SalientComment">## initialize exit-descriptor 'ed'</span> +<span id="L356" class="LineNr">356 </span> <span class="Comment"># allocate on stack</span> +<span id="L357" class="LineNr">357 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L358" class="LineNr">358 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L359" class="LineNr">359 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L360" class="LineNr">360 </span> <span class="Comment"># size the exit-descriptor for the call to get-num below</span> +<span id="L361" class="LineNr">361 </span> <span class="Comment"># tailor-exit-descriptor(ed, 16)</span> +<span id="L362" class="LineNr">362 </span> <span class="Comment"># push args</span> +<span id="L363" class="LineNr">363 </span> 68/push 0x10/imm32/nbytes-of-args-for-get-num +<span id="L364" class="LineNr">364 </span> 50/push-EAX/ed +<span id="L365" class="LineNr">365 </span> <span class="Comment"># call</span> +<span id="L366" class="LineNr">366 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L367" class="LineNr">367 </span> <span class="Comment"># discard args</span> +<span id="L368" class="LineNr">368 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L369" class="LineNr">369 </span> <span class="SalientComment">## prime the pump</span> +<span id="L370" class="LineNr">370 </span> <span class="Comment"># get-char(_test-buffered-file)</span> +<span id="L371" class="LineNr">371 </span> <span class="Comment"># push args</span> +<span id="L372" class="LineNr">372 </span> 68/push _test-buffered-file/imm32 +<span id="L373" class="LineNr">373 </span> <span class="Comment"># call</span> +<span id="L374" class="LineNr">374 </span> e8/call get-char/disp32 +<span id="L375" class="LineNr">375 </span> <span class="Comment"># discard args</span> +<span id="L376" class="LineNr">376 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L377" class="LineNr">377 </span> <span class="SalientComment">## get-num(in, out, err, ed)</span> +<span id="L378" class="LineNr">378 </span> <span class="Comment"># push args</span> +<span id="L379" class="LineNr">379 </span> 50/push-EAX/ed +<span id="L380" class="LineNr">380 </span> 68/push _test-error-stream/imm32 +<span id="L381" class="LineNr">381 </span> 68/push _test-output-stream/imm32 +<span id="L382" class="LineNr">382 </span> 68/push _test-buffered-file/imm32 +<span id="L383" class="LineNr">383 </span> <span class="Comment"># call</span> +<span id="L384" class="LineNr">384 </span> e8/call get-num/disp32 +<span id="L385" class="LineNr">385 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L386" class="LineNr">386 </span> <span class="Comment"># discard args</span> +<span id="L387" class="LineNr">387 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L388" class="LineNr">388 </span> <span class="Comment"># check-ints-equal(*_test-output-stream.data, '3')</span> +<span id="L389" class="LineNr">389 </span> <span class="Comment"># push args</span> +<span id="L390" class="LineNr">390 </span> 68/push <span class="Constant">"F - test-get-num-reads-single-digit"</span>/imm32 +<span id="L391" class="LineNr">391 </span> 68/push 0x33/imm32 +<span id="L392" class="LineNr">392 </span> b8/copy-to-EAX _test-output-stream/imm32 +<span id="L393" class="LineNr">393 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L394" class="LineNr">394 </span> <span class="Comment"># call</span> +<span id="L395" class="LineNr">395 </span> e8/call check-ints-equal/disp32 +<span id="L396" class="LineNr">396 </span> <span class="Comment"># discard args</span> +<span id="L397" class="LineNr">397 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L398" class="LineNr">398 </span> <span class="Comment"># reclaim locals</span> +<span id="L399" class="LineNr">399 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L400" class="LineNr">400 </span> 5d/pop-to-EBP +<span id="L401" class="LineNr">401 </span> c3/return +<span id="L402" class="LineNr">402 </span> +<span id="L403" class="LineNr">403 </span>test-get-num-aborts-on-non-digit-in-Look: +<span id="L404" class="LineNr">404 </span> <span class="SalientComment">## check that get-num returns first character if it's a digit</span> +<span id="L405" class="LineNr">405 </span> <span class="Comment"># This test uses exit-descriptors. Use EBP for setting up local variables.</span> +<span id="L406" class="LineNr">406 </span> 55/push-EBP +<span id="L407" class="LineNr">407 </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="L408" class="LineNr">408 </span> <span class="SalientComment">## clear all streams</span> +<span id="L409" class="LineNr">409 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L410" class="LineNr">410 </span> <span class="Comment"># push args</span> +<span id="L411" class="LineNr">411 </span> 68/push _test-stream/imm32 +<span id="L412" class="LineNr">412 </span> <span class="Comment"># call</span> +<span id="L413" class="LineNr">413 </span> e8/call clear-stream/disp32 +<span id="L414" class="LineNr">414 </span> <span class="Comment"># discard args</span> +<span id="L415" class="LineNr">415 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L416" class="LineNr">416 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L417" class="LineNr">417 </span> <span class="Comment"># push args</span> +<span id="L418" class="LineNr">418 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L419" class="LineNr">419 </span> 05/add-to-EAX 4/imm32 +<span id="L420" class="LineNr">420 </span> 50/push-EAX +<span id="L421" class="LineNr">421 </span> <span class="Comment"># call</span> +<span id="L422" class="LineNr">422 </span> e8/call clear-stream/disp32 +<span id="L423" class="LineNr">423 </span> <span class="Comment"># discard args</span> +<span id="L424" class="LineNr">424 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L425" class="LineNr">425 </span> <span class="Comment"># clear-stream(_test-output-stream)</span> +<span id="L426" class="LineNr">426 </span> <span class="Comment"># push args</span> +<span id="L427" class="LineNr">427 </span> 68/push _test-output-stream/imm32 +<span id="L428" class="LineNr">428 </span> <span class="Comment"># call</span> +<span id="L429" class="LineNr">429 </span> e8/call clear-stream/disp32 +<span id="L430" class="LineNr">430 </span> <span class="Comment"># discard args</span> +<span id="L431" class="LineNr">431 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L432" class="LineNr">432 </span> <span class="Comment"># clear-stream(_test-error-stream)</span> +<span id="L433" class="LineNr">433 </span> <span class="Comment"># push args</span> +<span id="L434" class="LineNr">434 </span> 68/push _test-error-stream/imm32 +<span id="L435" class="LineNr">435 </span> <span class="Comment"># call</span> +<span id="L436" class="LineNr">436 </span> e8/call clear-stream/disp32 +<span id="L437" class="LineNr">437 </span> <span class="Comment"># discard args</span> +<span id="L438" class="LineNr">438 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L439" class="LineNr">439 </span> <span class="SalientComment">## initialize 'in'</span> +<span id="L440" class="LineNr">440 </span> <span class="Comment"># write(_test-stream, "3")</span> +<span id="L441" class="LineNr">441 </span> <span class="Comment"># push args</span> +<span id="L442" class="LineNr">442 </span> 68/push <span class="Constant">"3"</span>/imm32 +<span id="L443" class="LineNr">443 </span> 68/push _test-stream/imm32 +<span id="L444" class="LineNr">444 </span> <span class="Comment"># call</span> +<span id="L445" class="LineNr">445 </span> e8/call write/disp32 +<span id="L446" class="LineNr">446 </span> <span class="Comment"># discard args</span> +<span id="L447" class="LineNr">447 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L448" class="LineNr">448 </span> <span class="SalientComment">## initialize exit-descriptor 'ed'</span> +<span id="L449" class="LineNr">449 </span> <span class="Comment"># allocate on stack</span> +<span id="L450" class="LineNr">450 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L451" class="LineNr">451 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L452" class="LineNr">452 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L453" class="LineNr">453 </span> <span class="Comment"># size the exit-descriptor for the call to get-num below</span> +<span id="L454" class="LineNr">454 </span> <span class="Comment"># tailor-exit-descriptor(ed, 16)</span> +<span id="L455" class="LineNr">455 </span> <span class="Comment"># push args</span> +<span id="L456" class="LineNr">456 </span> 68/push 0x10/imm32/nbytes-of-args-for-get-num +<span id="L457" class="LineNr">457 </span> 50/push-EAX/ed +<span id="L458" class="LineNr">458 </span> <span class="Comment"># call</span> +<span id="L459" class="LineNr">459 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L460" class="LineNr">460 </span> <span class="Comment"># discard args</span> +<span id="L461" class="LineNr">461 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L462" class="LineNr">462 </span> <span class="SalientComment">## don't initialize Look</span> +<span id="L463" class="LineNr">463 </span> <span class="SalientComment">## get-num(in, out, err, ed)</span> +<span id="L464" class="LineNr">464 </span> <span class="Comment"># push args</span> +<span id="L465" class="LineNr">465 </span> 50/push-EAX/ed +<span id="L466" class="LineNr">466 </span> 68/push _test-error-stream/imm32 +<span id="L467" class="LineNr">467 </span> 68/push _test-output-stream/imm32 +<span id="L468" class="LineNr">468 </span> 68/push _test-buffered-file/imm32 +<span id="L469" class="LineNr">469 </span> <span class="Comment"># call</span> +<span id="L470" class="LineNr">470 </span> e8/call get-num/disp32 +<span id="L471" class="LineNr">471 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L472" class="LineNr">472 </span> <span class="Comment"># discard args</span> +<span id="L473" class="LineNr">473 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L474" class="LineNr">474 </span> <span class="SalientComment">## check that get-num tried to call exit(1)</span> +<span id="L475" class="LineNr">475 </span> <span class="Comment"># check-ints-equal(ed->value, 2, msg) # i.e. stop was called with value 1</span> +<span id="L476" class="LineNr">476 </span> <span class="Comment"># push args</span> +<span id="L477" class="LineNr">477 </span> 68/push <span class="Constant">"F - test-get-num-aborts-on-non-digit-in-Look"</span>/imm32 +<span id="L478" class="LineNr">478 </span> 68/push 2/imm32 +<span id="L479" class="LineNr">479 </span> <span class="Comment"># push ed->value</span> +<span id="L480" class="LineNr">480 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+4)</span> +<span id="L481" class="LineNr">481 </span> <span class="Comment"># call</span> +<span id="L482" class="LineNr">482 </span> e8/call check-ints-equal/disp32 +<span id="L483" class="LineNr">483 </span> <span class="Comment"># discard args</span> +<span id="L484" class="LineNr">484 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L485" class="LineNr">485 </span> <span class="Comment"># reclaim locals</span> +<span id="L486" class="LineNr">486 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L487" class="LineNr">487 </span> 5d/pop-to-EBP +<span id="L488" class="LineNr">488 </span> c3/return +<span id="L489" class="LineNr">489 </span> +<span id="L490" class="LineNr">490 </span>test-get-num-reads-multiple-digits: +<span id="L491" class="LineNr">491 </span> <span class="SalientComment">## check that get-num returns all initial digits until it encounters a non-digit</span> +<span id="L492" class="LineNr">492 </span> <span class="Comment"># This test uses exit-descriptors. Use EBP for setting up local variables.</span> +<span id="L493" class="LineNr">493 </span> 55/push-EBP +<span id="L494" class="LineNr">494 </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="L495" class="LineNr">495 </span> <span class="SalientComment">## clear all streams</span> +<span id="L496" class="LineNr">496 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L497" class="LineNr">497 </span> <span class="Comment"># push args</span> +<span id="L498" class="LineNr">498 </span> 68/push _test-stream/imm32 +<span id="L499" class="LineNr">499 </span> <span class="Comment"># call</span> +<span id="L500" class="LineNr">500 </span> e8/call clear-stream/disp32 +<span id="L501" class="LineNr">501 </span> <span class="Comment"># discard args</span> +<span id="L502" class="LineNr">502 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L503" class="LineNr">503 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L504" class="LineNr">504 </span> <span class="Comment"># push args</span> +<span id="L505" class="LineNr">505 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L506" class="LineNr">506 </span> 05/add-to-EAX 4/imm32 +<span id="L507" class="LineNr">507 </span> 50/push-EAX +<span id="L508" class="LineNr">508 </span> <span class="Comment"># call</span> +<span id="L509" class="LineNr">509 </span> e8/call clear-stream/disp32 +<span id="L510" class="LineNr">510 </span> <span class="Comment"># discard args</span> +<span id="L511" class="LineNr">511 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L512" class="LineNr">512 </span> <span class="Comment"># clear-stream(_test-output-stream)</span> +<span id="L513" class="LineNr">513 </span> <span class="Comment"># push args</span> +<span id="L514" class="LineNr">514 </span> 68/push _test-output-stream/imm32 +<span id="L515" class="LineNr">515 </span> <span class="Comment"># call</span> +<span id="L516" class="LineNr">516 </span> e8/call clear-stream/disp32 +<span id="L517" class="LineNr">517 </span> <span class="Comment"># discard args</span> +<span id="L518" class="LineNr">518 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L519" class="LineNr">519 </span> <span class="Comment"># clear-stream(_test-error-stream)</span> +<span id="L520" class="LineNr">520 </span> <span class="Comment"># push args</span> +<span id="L521" class="LineNr">521 </span> 68/push _test-error-stream/imm32 +<span id="L522" class="LineNr">522 </span> <span class="Comment"># call</span> +<span id="L523" class="LineNr">523 </span> e8/call clear-stream/disp32 +<span id="L524" class="LineNr">524 </span> <span class="Comment"># discard args</span> +<span id="L525" class="LineNr">525 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L526" class="LineNr">526 </span> <span class="SalientComment">## initialize 'in'</span> +<span id="L527" class="LineNr">527 </span> <span class="Comment"># write(_test-stream, "3456 x")</span> +<span id="L528" class="LineNr">528 </span> <span class="Comment"># push args</span> +<span id="L529" class="LineNr">529 </span> 68/push <span class="Constant">"3456"</span>/imm32 +<span id="L530" class="LineNr">530 </span> 68/push _test-stream/imm32 +<span id="L531" class="LineNr">531 </span> <span class="Comment"># call</span> +<span id="L532" class="LineNr">532 </span> e8/call write/disp32 +<span id="L533" class="LineNr">533 </span> <span class="Comment"># discard args</span> +<span id="L534" class="LineNr">534 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L535" class="LineNr">535 </span> <span class="SalientComment">## initialize exit-descriptor 'ed'</span> +<span id="L536" class="LineNr">536 </span> <span class="Comment"># allocate on stack</span> +<span id="L537" class="LineNr">537 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L538" class="LineNr">538 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L539" class="LineNr">539 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L540" class="LineNr">540 </span> <span class="Comment"># size the exit-descriptor for the call to get-num below</span> +<span id="L541" class="LineNr">541 </span> <span class="Comment"># tailor-exit-descriptor(ed, 16)</span> +<span id="L542" class="LineNr">542 </span> <span class="Comment"># push args</span> +<span id="L543" class="LineNr">543 </span> 68/push 0x10/imm32/nbytes-of-args-for-get-num +<span id="L544" class="LineNr">544 </span> 50/push-EAX/ed +<span id="L545" class="LineNr">545 </span> <span class="Comment"># call</span> +<span id="L546" class="LineNr">546 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L547" class="LineNr">547 </span> <span class="Comment"># discard args</span> +<span id="L548" class="LineNr">548 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L549" class="LineNr">549 </span> <span class="SalientComment">## prime the pump</span> +<span id="L550" class="LineNr">550 </span> <span class="Comment"># get-char(_test-buffered-file)</span> +<span id="L551" class="LineNr">551 </span> <span class="Comment"># push args</span> +<span id="L552" class="LineNr">552 </span> 68/push _test-buffered-file/imm32 +<span id="L553" class="LineNr">553 </span> <span class="Comment"># call</span> +<span id="L554" class="LineNr">554 </span> e8/call get-char/disp32 +<span id="L555" class="LineNr">555 </span> <span class="Comment"># discard args</span> +<span id="L556" class="LineNr">556 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L557" class="LineNr">557 </span> <span class="SalientComment">## get-num(in, out, err, ed)</span> +<span id="L558" class="LineNr">558 </span> <span class="Comment"># push args</span> +<span id="L559" class="LineNr">559 </span> 50/push-EAX/ed +<span id="L560" class="LineNr">560 </span> 68/push _test-error-stream/imm32 +<span id="L561" class="LineNr">561 </span> 68/push _test-output-stream/imm32 +<span id="L562" class="LineNr">562 </span> 68/push _test-buffered-file/imm32 +<span id="L563" class="LineNr">563 </span> <span class="Comment"># call</span> +<span id="L564" class="LineNr">564 </span> e8/call get-num/disp32 +<span id="L565" class="LineNr">565 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L566" class="LineNr">566 </span> <span class="Comment"># discard args</span> +<span id="L567" class="LineNr">567 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L568" class="LineNr">568 </span> <span class="Comment"># check-ints-equal(*_test-output-stream.data, '3456')</span> +<span id="L569" class="LineNr">569 </span> <span class="Comment"># push args</span> +<span id="L570" class="LineNr">570 </span> 68/push <span class="Constant">"F - test-get-num-reads-multiple-digits"</span>/imm32 +<span id="L571" class="LineNr">571 </span> 68/push 0x36353433/imm32 +<span id="L572" class="LineNr">572 </span> b8/copy-to-EAX _test-output-stream/imm32 +<span id="L573" class="LineNr">573 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L574" class="LineNr">574 </span> <span class="Comment"># call</span> +<span id="L575" class="LineNr">575 </span> e8/call check-ints-equal/disp32 +<span id="L576" class="LineNr">576 </span> <span class="Comment"># discard args</span> +<span id="L577" class="LineNr">577 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L578" class="LineNr">578 </span> <span class="Comment"># reclaim locals</span> +<span id="L579" class="LineNr">579 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L580" class="LineNr">580 </span> 5d/pop-to-EBP +<span id="L581" class="LineNr">581 </span> c3/return +<span id="L582" class="LineNr">582 </span> +<span id="L583" class="LineNr">583 </span>test-get-num-reads-multiple-digits-followed-by-nondigit: +<span id="L584" class="LineNr">584 </span> <span class="SalientComment">## check that get-num returns all initial digits until it encounters a non-digit</span> +<span id="L585" class="LineNr">585 </span> <span class="Comment"># This test uses exit-descriptors. Use EBP for setting up local variables.</span> +<span id="L586" class="LineNr">586 </span> 55/push-EBP +<span id="L587" class="LineNr">587 </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="L588" class="LineNr">588 </span> <span class="SalientComment">## clear all streams</span> +<span id="L589" class="LineNr">589 </span> <span class="Comment"># clear-stream(_test-stream)</span> +<span id="L590" class="LineNr">590 </span> <span class="Comment"># push args</span> +<span id="L591" class="LineNr">591 </span> 68/push _test-stream/imm32 +<span id="L592" class="LineNr">592 </span> <span class="Comment"># call</span> +<span id="L593" class="LineNr">593 </span> e8/call clear-stream/disp32 +<span id="L594" class="LineNr">594 </span> <span class="Comment"># discard args</span> +<span id="L595" class="LineNr">595 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L596" class="LineNr">596 </span> <span class="Comment"># clear-stream(_test-buffered-file+4)</span> +<span id="L597" class="LineNr">597 </span> <span class="Comment"># push args</span> +<span id="L598" class="LineNr">598 </span> b8/copy-to-EAX _test-buffered-file/imm32 +<span id="L599" class="LineNr">599 </span> 05/add-to-EAX 4/imm32 +<span id="L600" class="LineNr">600 </span> 50/push-EAX +<span id="L601" class="LineNr">601 </span> <span class="Comment"># call</span> +<span id="L602" class="LineNr">602 </span> e8/call clear-stream/disp32 +<span id="L603" class="LineNr">603 </span> <span class="Comment"># discard args</span> +<span id="L604" class="LineNr">604 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L605" class="LineNr">605 </span> <span class="Comment"># clear-stream(_test-output-stream)</span> +<span id="L606" class="LineNr">606 </span> <span class="Comment"># push args</span> +<span id="L607" class="LineNr">607 </span> 68/push _test-output-stream/imm32 +<span id="L608" class="LineNr">608 </span> <span class="Comment"># call</span> +<span id="L609" class="LineNr">609 </span> e8/call clear-stream/disp32 +<span id="L610" class="LineNr">610 </span> <span class="Comment"># discard args</span> +<span id="L611" class="LineNr">611 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L612" class="LineNr">612 </span> <span class="Comment"># clear-stream(_test-error-stream)</span> +<span id="L613" class="LineNr">613 </span> <span class="Comment"># push args</span> +<span id="L614" class="LineNr">614 </span> 68/push _test-error-stream/imm32 +<span id="L615" class="LineNr">615 </span> <span class="Comment"># call</span> +<span id="L616" class="LineNr">616 </span> e8/call clear-stream/disp32 +<span id="L617" class="LineNr">617 </span> <span class="Comment"># discard args</span> +<span id="L618" class="LineNr">618 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L619" class="LineNr">619 </span> <span class="SalientComment">## initialize 'in'</span> +<span id="L620" class="LineNr">620 </span> <span class="Comment"># write(_test-stream, "3456 x")</span> +<span id="L621" class="LineNr">621 </span> <span class="Comment"># push args</span> +<span id="L622" class="LineNr">622 </span> 68/push <span class="Constant">"3456 x"</span>/imm32 +<span id="L623" class="LineNr">623 </span> 68/push _test-stream/imm32 +<span id="L624" class="LineNr">624 </span> <span class="Comment"># call</span> +<span id="L625" class="LineNr">625 </span> e8/call write/disp32 +<span id="L626" class="LineNr">626 </span> <span class="Comment"># discard args</span> +<span id="L627" class="LineNr">627 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L628" class="LineNr">628 </span> <span class="SalientComment">## initialize exit-descriptor 'ed'</span> +<span id="L629" class="LineNr">629 </span> <span class="Comment"># allocate on stack</span> +<span id="L630" class="LineNr">630 </span> <span class="Comment"># var ed/EAX : (address exit-descriptor)</span> +<span id="L631" class="LineNr">631 </span> 81 5/subop/subtract 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># subtract from ESP</span> +<span id="L632" class="LineNr">632 </span> 8d/copy-address 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy ESP to EAX</span> +<span id="L633" class="LineNr">633 </span> <span class="Comment"># size the exit-descriptor for the call to get-num below</span> +<span id="L634" class="LineNr">634 </span> <span class="Comment"># tailor-exit-descriptor(ed, 16)</span> +<span id="L635" class="LineNr">635 </span> <span class="Comment"># push args</span> +<span id="L636" class="LineNr">636 </span> 68/push 0x10/imm32/nbytes-of-args-for-get-num +<span id="L637" class="LineNr">637 </span> 50/push-EAX/ed +<span id="L638" class="LineNr">638 </span> <span class="Comment"># call</span> +<span id="L639" class="LineNr">639 </span> e8/call tailor-exit-descriptor/disp32 +<span id="L640" class="LineNr">640 </span> <span class="Comment"># discard args</span> +<span id="L641" class="LineNr">641 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L642" class="LineNr">642 </span> <span class="SalientComment">## prime the pump</span> +<span id="L643" class="LineNr">643 </span> <span class="Comment"># get-char(_test-buffered-file)</span> +<span id="L644" class="LineNr">644 </span> <span class="Comment"># push args</span> +<span id="L645" class="LineNr">645 </span> 68/push _test-buffered-file/imm32 +<span id="L646" class="LineNr">646 </span> <span class="Comment"># call</span> +<span id="L647" class="LineNr">647 </span> e8/call get-char/disp32 +<span id="L648" class="LineNr">648 </span> <span class="Comment"># discard args</span> +<span id="L649" class="LineNr">649 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L650" class="LineNr">650 </span> <span class="SalientComment">## get-num(in, out, err, ed)</span> +<span id="L651" class="LineNr">651 </span> <span class="Comment"># push args</span> +<span id="L652" class="LineNr">652 </span> 50/push-EAX/ed +<span id="L653" class="LineNr">653 </span> 68/push _test-error-stream/imm32 +<span id="L654" class="LineNr">654 </span> 68/push _test-output-stream/imm32 +<span id="L655" class="LineNr">655 </span> 68/push _test-buffered-file/imm32 +<span id="L656" class="LineNr">656 </span> <span class="Comment"># call</span> +<span id="L657" class="LineNr">657 </span> e8/call get-num/disp32 +<span id="L658" class="LineNr">658 </span> <span class="SalientComment">## registers except ESP may be clobbered at this point</span> +<span id="L659" class="LineNr">659 </span> <span class="Comment"># discard args</span> +<span id="L660" class="LineNr">660 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/imm32 <span class="Comment"># add to ESP</span> +<span id="L661" class="LineNr">661 </span> <span class="Comment"># check-ints-equal(*_test-output-stream.data, '3456')</span> +<span id="L662" class="LineNr">662 </span> <span class="Comment"># push args</span> +<span id="L663" class="LineNr">663 </span> 68/push <span class="Constant">"F - test-get-num-reads-multiple-digits-followed-by-nondigit"</span>/imm32 +<span id="L664" class="LineNr">664 </span> 68/push 0x36353433/imm32 +<span id="L665" class="LineNr">665 </span> b8/copy-to-EAX _test-output-stream/imm32 +<span id="L666" class="LineNr">666 </span> ff 6/subop/push 1/mod/*+disp8 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EAX+12)</span> +<span id="L667" class="LineNr">667 </span> <span class="Comment"># call</span> +<span id="L668" class="LineNr">668 </span> e8/call check-ints-equal/disp32 +<span id="L669" class="LineNr">669 </span> <span class="Comment"># discard args</span> +<span id="L670" class="LineNr">670 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L671" class="LineNr">671 </span> <span class="Comment"># reclaim locals</span> +<span id="L672" class="LineNr">672 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L673" class="LineNr">673 </span> 5d/pop-to-EBP +<span id="L674" class="LineNr">674 </span> c3/return +<span id="L675" class="LineNr">675 </span> +<span id="L676" class="LineNr">676 </span><span class="SalientComment">## helpers</span> +<span id="L677" class="LineNr">677 </span> +<span id="L678" class="LineNr">678 </span><span class="Comment"># write(f, "Error: "+s+" expected\n") then stop(ed, 1)</span> +<span id="L679" class="LineNr">679 </span>expected: <span class="Comment"># ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte) -> <void></span> +<span id="L680" class="LineNr">680 </span> <span class="Comment"># prolog</span> +<span id="L681" class="LineNr">681 </span> 55/push-EBP +<span id="L682" class="LineNr">682 </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="L683" class="LineNr">683 </span> <span class="Comment"># write(f, "Error: ")</span> +<span id="L684" class="LineNr">684 </span> <span class="Comment"># push args</span> +<span id="L685" class="LineNr">685 </span> 68/push <span class="Constant">"Error: "</span>/imm32 +<span id="L686" class="LineNr">686 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L687" class="LineNr">687 </span> <span class="Comment"># call</span> +<span id="L688" class="LineNr">688 </span> e8/call write/disp32 +<span id="L689" class="LineNr">689 </span> <span class="Comment"># discard args</span> +<span id="L690" class="LineNr">690 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L691" class="LineNr">691 </span> <span class="Comment"># write(f, s)</span> +<span id="L692" class="LineNr">692 </span> <span class="Comment"># push args</span> +<span id="L693" class="LineNr">693 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L694" class="LineNr">694 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L695" class="LineNr">695 </span> <span class="Comment"># call</span> +<span id="L696" class="LineNr">696 </span> e8/call write/disp32 +<span id="L697" class="LineNr">697 </span> <span class="Comment"># discard args</span> +<span id="L698" class="LineNr">698 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L699" class="LineNr">699 </span> <span class="Comment"># write(f, " expected")</span> +<span id="L700" class="LineNr">700 </span> <span class="Comment"># push args</span> +<span id="L701" class="LineNr">701 </span> 68/push <span class="Constant">" expected"</span>/imm32 +<span id="L702" class="LineNr">702 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L703" class="LineNr">703 </span> <span class="Comment"># call</span> +<span id="L704" class="LineNr">704 </span> e8/call write/disp32 +<span id="L705" class="LineNr">705 </span> <span class="Comment"># discard args</span> +<span id="L706" class="LineNr">706 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L707" class="LineNr">707 </span> <span class="Comment"># write(f, Newline)</span> +<span id="L708" class="LineNr">708 </span> <span class="Comment"># push args</span> +<span id="L709" class="LineNr">709 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L710" class="LineNr">710 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L711" class="LineNr">711 </span> <span class="Comment"># call</span> +<span id="L712" class="LineNr">712 </span> e8/call write/disp32 +<span id="L713" class="LineNr">713 </span> <span class="Comment"># discard args</span> +<span id="L714" class="LineNr">714 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L715" class="LineNr">715 </span> <span class="Comment"># stop(ed, 1)</span> +<span id="L716" class="LineNr">716 </span> <span class="Comment"># push args</span> +<span id="L717" class="LineNr">717 </span> 68/push 1/imm32 +<span id="L718" class="LineNr">718 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L719" class="LineNr">719 </span> <span class="Comment"># call</span> +<span id="L720" class="LineNr">720 </span> e8/call stop/disp32 +<span id="L721" class="LineNr">721 </span> <span class="SalientComment">## should never get past this point</span> +<span id="L722" class="LineNr">722 </span> <span class="Comment"># epilog</span> +<span id="L723" class="LineNr">723 </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="L724" class="LineNr">724 </span> 5d/pop-to-EBP +<span id="L725" class="LineNr">725 </span> c3/return +<span id="L726" class="LineNr">726 </span> +<span id="L727" class="LineNr">727 </span><span class="Comment"># write(f, "Error: "+s+"\n") then stop(ed, 1)</span> +<span id="L728" class="LineNr">728 </span>error: <span class="Comment"># ed : (address exit-descriptor), f : fd or (address stream), s : (address array byte) -> <void></span> +<span id="L729" class="LineNr">729 </span> <span class="Comment"># prolog</span> +<span id="L730" class="LineNr">730 </span> 55/push-EBP +<span id="L731" class="LineNr">731 </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="L732" class="LineNr">732 </span> <span class="Comment"># write(f, "Error: ")</span> +<span id="L733" class="LineNr">733 </span> <span class="Comment"># push args</span> +<span id="L734" class="LineNr">734 </span> 68/push <span class="Constant">"Error: "</span>/imm32 +<span id="L735" class="LineNr">735 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L736" class="LineNr">736 </span> <span class="Comment"># call</span> +<span id="L737" class="LineNr">737 </span> e8/call write/disp32 +<span id="L738" class="LineNr">738 </span> <span class="Comment"># discard args</span> +<span id="L739" class="LineNr">739 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L740" class="LineNr">740 </span> <span class="Comment"># write(f, s)</span> +<span id="L741" class="LineNr">741 </span> <span class="Comment"># push args</span> +<span id="L742" class="LineNr">742 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+16)</span> +<span id="L743" class="LineNr">743 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L744" class="LineNr">744 </span> <span class="Comment"># call</span> +<span id="L745" class="LineNr">745 </span> e8/call write/disp32 +<span id="L746" class="LineNr">746 </span> <span class="Comment"># discard args</span> +<span id="L747" class="LineNr">747 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L748" class="LineNr">748 </span> <span class="Comment"># write(f, Newline)</span> +<span id="L749" class="LineNr">749 </span> <span class="Comment"># push args</span> +<span id="L750" class="LineNr">750 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L751" class="LineNr">751 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L752" class="LineNr">752 </span> <span class="Comment"># call</span> +<span id="L753" class="LineNr">753 </span> e8/call write/disp32 +<span id="L754" class="LineNr">754 </span> <span class="Comment"># discard args</span> +<span id="L755" class="LineNr">755 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L756" class="LineNr">756 </span> <span class="Comment"># stop(ed, 1)</span> +<span id="L757" class="LineNr">757 </span> <span class="Comment"># push args</span> +<span id="L758" class="LineNr">758 </span> 68/push 1/imm32 +<span id="L759" class="LineNr">759 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L760" class="LineNr">760 </span> <span class="Comment"># call</span> +<span id="L761" class="LineNr">761 </span> e8/call stop/disp32 +<span id="L762" class="LineNr">762 </span> <span class="SalientComment">## should never get past this point</span> +<span id="L763" class="LineNr">763 </span> <span class="Comment"># epilog</span> +<span id="L764" class="LineNr">764 </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="L765" class="LineNr">765 </span> 5d/pop-to-EBP +<span id="L766" class="LineNr">766 </span> c3/return +<span id="L767" class="LineNr">767 </span> +<span id="L768" class="LineNr">768 </span><span class="Comment"># read a byte from 'f', and store it in 'Look'</span> +<span id="L769" class="LineNr">769 </span>get-char: <span class="Comment"># f : (address buffered-file) -> <void></span> +<span id="L770" class="LineNr">770 </span> <span class="Comment"># prolog</span> +<span id="L771" class="LineNr">771 </span> 55/push-EBP +<span id="L772" class="LineNr">772 </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="L773" class="LineNr">773 </span> <span class="Comment"># save registers</span> +<span id="L774" class="LineNr">774 </span> 50/push-EAX +<span id="L775" class="LineNr">775 </span> <span class="Comment"># read-byte(f)</span> +<span id="L776" class="LineNr">776 </span> <span class="Comment"># push args</span> +<span id="L777" class="LineNr">777 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L778" class="LineNr">778 </span> <span class="Comment"># call</span> +<span id="L779" class="LineNr">779 </span> e8/call read-byte/disp32 +<span id="L780" class="LineNr">780 </span> <span class="Comment"># discard args</span> +<span id="L781" class="LineNr">781 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L782" class="LineNr">782 </span> <span class="Comment"># save EAX to Look</span> +<span id="L783" class="LineNr">783 </span> 89/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX <span class="Special">Look</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># copy EAX to *Look</span> +<span id="L784" class="LineNr">784 </span> <span class="Comment"># restore registers</span> +<span id="L785" class="LineNr">785 </span> 58/pop-to-EAX +<span id="L786" class="LineNr">786 </span> <span class="Comment"># epilog</span> +<span id="L787" class="LineNr">787 </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="L788" class="LineNr">788 </span> 5d/pop-to-EBP +<span id="L789" class="LineNr">789 </span> c3/return +<span id="L790" class="LineNr">790 </span> +<span id="L791" class="LineNr">791 </span>is-digit?: <span class="Comment"># c : int -> bool/EAX</span> +<span id="L792" class="LineNr">792 </span> <span class="Comment"># prolog</span> +<span id="L793" class="LineNr">793 </span> 55/push-EBP +<span id="L794" class="LineNr">794 </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="L795" class="LineNr">795 </span> <span class="Comment"># EAX = false</span> +<span id="L796" class="LineNr">796 </span> b8/copy-to-EAX 0/imm32 +<span id="L797" class="LineNr">797 </span> <span class="Comment"># if c < '0' return false</span> +<span id="L798" class="LineNr">798 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 0x30/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L799" class="LineNr">799 </span> 7c/jump-if-lesser $is-digit?:end/disp8 +<span id="L800" class="LineNr">800 </span> <span class="Comment"># if c > '9' return false</span> +<span id="L801" class="LineNr">801 </span> 81 7/subop/compare 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 0x39/imm32 <span class="Comment"># compare *(EBP+8)</span> +<span id="L802" class="LineNr">802 </span> 7f/jump-if-greater $is-digit?:end/disp8 +<span id="L803" class="LineNr">803 </span> <span class="Comment"># otherwise return true</span> +<span id="L804" class="LineNr">804 </span> b8/copy-to-EAX 1/imm32 +<span id="L805" class="LineNr">805 </span>$is-digit?:end: +<span id="L806" class="LineNr">806 </span> <span class="Comment"># epilog</span> +<span id="L807" class="LineNr">807 </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="L808" class="LineNr">808 </span> 5d/pop-to-EBP +<span id="L809" class="LineNr">809 </span> c3/return +<span id="L810" class="LineNr">810 </span> +<span id="L811" class="LineNr">811 </span>== data +<span id="L812" class="LineNr">812 </span> +<span id="L813" class="LineNr">813 </span><span class="Special">Look</span>: +<span id="L814" class="LineNr">814 </span> 00 00 00 00 +<span id="L815" class="LineNr">815 </span> +<span id="L816" class="LineNr">816 </span>_test-output-stream: +<span id="L817" class="LineNr">817 </span> <span class="Comment"># current write index</span> +<span id="L818" class="LineNr">818 </span> 00 00 00 00 +<span id="L819" class="LineNr">819 </span> <span class="Comment"># current read index</span> +<span id="L820" class="LineNr">820 </span> 00 00 00 00 +<span id="L821" class="LineNr">821 </span> <span class="Comment"># length (= 8)</span> +<span id="L822" class="LineNr">822 </span> 08 00 00 00 +<span id="L823" class="LineNr">823 </span> <span class="Comment"># data</span> +<span id="L824" class="LineNr">824 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L825" class="LineNr">825 </span> +<span id="L826" class="LineNr">826 </span>_test-error-stream: +<span id="L827" class="LineNr">827 </span> <span class="Comment"># current write index</span> +<span id="L828" class="LineNr">828 </span> 00 00 00 00 +<span id="L829" class="LineNr">829 </span> <span class="Comment"># current read index</span> +<span id="L830" class="LineNr">830 </span> 00 00 00 00 +<span id="L831" class="LineNr">831 </span> <span class="Comment"># length (= 8)</span> +<span id="L832" class="LineNr">832 </span> 08 00 00 00 +<span id="L833" class="LineNr">833 </span> <span class="Comment"># data</span> +<span id="L834" class="LineNr">834 </span> 00 00 00 00 00 00 00 00 <span class="Comment"># 8 bytes</span> +<span id="L835" class="LineNr">835 </span> +<span id="L836" class="LineNr">836 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +</pre> +</body> +</html> +<!-- vim: set foldmethod=manual : --> diff --git a/html/subx/apps/factorial.subx.html b/html/subx/apps/factorial.subx.html index a30495cb..ea499438 100644 --- a/html/subx/apps/factorial.subx.html +++ b/html/subx/apps/factorial.subx.html @@ -16,7 +16,9 @@ a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -83,7 +85,7 @@ if ('onhashchange' in window) { <span id="L27" class="LineNr"> 27 </span> 7e/jump-if-lesser-or-equal $run-main/disp8 <span id="L28" class="LineNr"> 28 </span> <span class="Comment"># and if (argv[1] == "test")</span> <span id="L29" class="LineNr"> 29 </span> <span class="Comment"># push args</span> -<span id="L30" class="LineNr"> 30 </span> 68/push "test"/imm32 +<span id="L30" class="LineNr"> 30 </span> 68/push <span class="Constant">"test"</span>/imm32 <span id="L31" class="LineNr"> 31 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> <span id="L32" class="LineNr"> 32 </span> <span class="Comment"># call</span> <span id="L33" class="LineNr"> 33 </span> e8/call kernel-string-equal/disp32 @@ -94,7 +96,7 @@ if ('onhashchange' in window) { <span id="L38" class="LineNr"> 38 </span> 75/jump-if-not-equal $run-main/disp8 <span id="L39" class="LineNr"> 39 </span> <span class="Comment"># then return run-tests()</span> <span id="L40" class="LineNr"> 40 </span> e8/call run-tests/disp32 -<span id="L41" class="LineNr"> 41 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX Num-test-failures/disp32 <span class="Comment"># copy *Num-test-failures to EAX</span> +<span id="L41" class="LineNr"> 41 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/r32/EAX <span class="Special">Num-test-failures</span>/disp32 <span class="Comment"># copy *Num-test-failures to EAX</span> <span id="L42" class="LineNr"> 42 </span> eb/jump $main:end/disp8 <span class="Comment"># where EAX will get copied to EBX</span> <span id="L43" class="LineNr"> 43 </span> <span class="Comment"># else EAX = factorial(5)</span> <span id="L44" class="LineNr"> 44 </span>$run-main: @@ -151,7 +153,7 @@ if ('onhashchange' in window) { <span id="L95" class="LineNr"> 95 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> <span id="L96" class="LineNr"> 96 </span> <span class="Comment"># check-ints-equal(EAX, 120, failure message)</span> <span id="L97" class="LineNr"> 97 </span> <span class="Comment"># push args</span> -<span id="L98" class="LineNr"> 98 </span> 68/push "F - test-factorial"/imm32 +<span id="L98" class="LineNr"> 98 </span> 68/push <span class="Constant">"F - test-factorial"</span>/imm32 <span id="L99" class="LineNr"> 99 </span> 68/push 0x78/imm32/expected-120 <span id="L100" class="LineNr">100 </span> 50/push-EAX <span id="L101" class="LineNr">101 </span> <span class="Comment"># call</span> diff --git a/html/subx/examples/ex1.subx.html b/html/subx/examples/ex1.subx.html index df3bcacb..3f11f2b5 100644 --- a/html/subx/examples/ex1.subx.html +++ b/html/subx/examples/ex1.subx.html @@ -64,12 +64,13 @@ if ('onhashchange' in window) { <span id="L9" class="LineNr"> 9 </span><span class="Comment"># 42</span> <span id="L10" class="LineNr">10 </span> <span id="L11" class="LineNr">11 </span>== code -<span id="L12" class="LineNr">12 </span>bb/copy-to-EBX 2a/imm32 -<span id="L13" class="LineNr">13 </span><span class="Comment"># exit(EBX)</span> -<span id="L14" class="LineNr">14 </span>b8/copy-to-EAX 1/imm32 -<span id="L15" class="LineNr">15 </span>cd/syscall 0x80/imm8 -<span id="L16" class="LineNr">16 </span> -<span id="L17" class="LineNr">17 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L12" class="LineNr">12 </span> +<span id="L13" class="LineNr">13 </span>bb/copy-to-EBX 2a/imm32 +<span id="L14" class="LineNr">14 </span><span class="Comment"># exit(EBX)</span> +<span id="L15" class="LineNr">15 </span>b8/copy-to-EAX 1/imm32 +<span id="L16" class="LineNr">16 </span>cd/syscall 0x80/imm8 +<span id="L17" class="LineNr">17 </span> +<span id="L18" class="LineNr">18 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex11.subx.html b/html/subx/examples/ex11.subx.html index 7ac67838..0c4da4c4 100644 --- a/html/subx/examples/ex11.subx.html +++ b/html/subx/examples/ex11.subx.html @@ -16,7 +16,9 @@ a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Constant { color: #00a0a0; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -71,337 +73,337 @@ if ('onhashchange' in window) { <span id="L15" class="LineNr"> 15 </span><span class="Comment"># would cause tests to not run, rather than to fail as we'd like.)</span> <span id="L16" class="LineNr"> 16 </span> <span id="L17" class="LineNr"> 17 </span>== code -<span id="L18" class="LineNr"> 18 </span> -<span id="L19" class="LineNr"> 19 </span><span class="Comment"># instruction effective address operand displacement immediate</span> -<span id="L20" class="LineNr"> 20 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> -<span id="L21" class="LineNr"> 21 </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> -<span id="L22" class="LineNr"> 22 </span> -<span id="L23" class="LineNr"> 23 </span><span class="Comment"># main:</span> -<span id="L24" class="LineNr"> 24 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> -<span id="L25" class="LineNr"> 25 </span> <span class="Comment"># syscall(exit, EAX)</span> -<span id="L26" class="LineNr"> 26 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> -<span id="L27" class="LineNr"> 27 </span> b8/copy-to-EAX 1/imm32 -<span id="L28" class="LineNr"> 28 </span> cd/syscall 0x80/imm8 -<span id="L29" class="LineNr"> 29 </span> -<span id="L30" class="LineNr"> 30 </span><span class="Comment"># compare a null-terminated ascii string with a more idiomatic length-prefixed byte array</span> -<span id="L31" class="LineNr"> 31 </span><span class="Comment"># reason for the name: the only place we should have null-terminated ascii strings is from commandline args</span> -<span id="L32" class="LineNr"> 32 </span>kernel-string-equal: <span class="Comment"># s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean</span> -<span id="L33" class="LineNr"> 33 </span> <span class="Comment"># prolog</span> -<span id="L34" class="LineNr"> 34 </span> 55/push-EBP -<span id="L35" class="LineNr"> 35 </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="L36" class="LineNr"> 36 </span> <span class="Comment"># save registers</span> -<span id="L37" class="LineNr"> 37 </span> 51/push-ECX -<span id="L38" class="LineNr"> 38 </span> 52/push-EDX -<span id="L39" class="LineNr"> 39 </span> 53/push-EBX -<span id="L40" class="LineNr"> 40 </span> 56/push-ESI -<span id="L41" class="LineNr"> 41 </span> 57/push-EDI -<span id="L42" class="LineNr"> 42 </span> -<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># pseudocode:</span> -<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># initialize n = b.length</span> -<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># initialize s1 = s</span> -<span id="L46" class="LineNr"> 46 </span> <span class="Comment"># initialize s2 = b.data</span> -<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># i = 0</span> -<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># for (i = 0; i < n; ++n)</span> -<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># c1 = *s1</span> -<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># c2 = *s2</span> -<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># if c1 == 0</span> -<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># return false</span> -<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># if c1 != c2</span> -<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># return false</span> -<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># return *s1 == 0</span> -<span id="L56" class="LineNr"> 56 </span> <span class="Comment"># initialize s into EDI</span> -<span id="L57" class="LineNr"> 57 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> -<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># initialize benchmark length n into EDX</span> -<span id="L59" class="LineNr"> 59 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> -<span id="L60" class="LineNr"> 60 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> -<span id="L61" class="LineNr"> 61 </span> <span class="Comment"># initialize benchmark data into ESI</span> -<span id="L62" class="LineNr"> 62 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> -<span id="L63" class="LineNr"> 63 </span> 81 0/subop/add 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESI</span> -<span id="L64" class="LineNr"> 64 </span> <span class="Comment"># initialize loop counter i into ECX</span> -<span id="L65" class="LineNr"> 65 </span> b9/copy-to-ECX 0/imm32/exit -<span id="L66" class="LineNr"> 66 </span> <span class="Comment"># while (i/ECX < n/EDX)</span> -<span id="L67" class="LineNr"> 67 </span>$kernel-string-equal:loop: -<span id="L68" class="LineNr"> 68 </span> 39/compare 3/mod/direct 1/rm32/ECX <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"># compare ECX with EDX</span> -<span id="L69" class="LineNr"> 69 </span> 74/jump-if-equal $kernel-string-equal:break/disp8 -<span id="L70" class="LineNr"> 70 </span> <span class="Comment"># c1/EAX, c2/EBX = *s, *benchmark</span> -<span id="L71" class="LineNr"> 71 </span> b8/copy-to-EAX 0/imm32 -<span id="L72" class="LineNr"> 72 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> -<span id="L73" class="LineNr"> 73 </span> bb/copy-to-EBX 0/imm32 -<span id="L74" class="LineNr"> 74 </span> 8a/copy 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *ESI to lower byte of EBX</span> -<span id="L75" class="LineNr"> 75 </span> <span class="Comment"># if (c1 == 0) return false</span> -<span id="L76" class="LineNr"> 76 </span> 3d/compare-EAX 0/imm32 -<span id="L77" class="LineNr"> 77 </span> 74/jump-if-equal $kernel-string-equal:false/disp8 -<span id="L78" class="LineNr"> 78 </span> <span class="Comment"># if (c1 != c2) return false</span> -<span id="L79" class="LineNr"> 79 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with EBX</span> -<span id="L80" class="LineNr"> 80 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 -<span id="L81" class="LineNr"> 81 </span> <span class="Comment"># ++s1, ++s2, ++i</span> -<span id="L82" class="LineNr"> 82 </span> 41/inc-ECX -<span id="L83" class="LineNr"> 83 </span> 46/inc-ESI -<span id="L84" class="LineNr"> 84 </span> 47/inc-EDI -<span id="L85" class="LineNr"> 85 </span> <span class="Comment"># end while</span> -<span id="L86" class="LineNr"> 86 </span> eb/jump $kernel-string-equal:loop/disp8 -<span id="L87" class="LineNr"> 87 </span>$kernel-string-equal:break: -<span id="L88" class="LineNr"> 88 </span> <span class="Comment"># if (*s/EDI == 0) return true</span> -<span id="L89" class="LineNr"> 89 </span> b8/copy-to-EAX 0/imm32 -<span id="L90" class="LineNr"> 90 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> -<span id="L91" class="LineNr"> 91 </span> 81 7/subop/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare EAX</span> -<span id="L92" class="LineNr"> 92 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 -<span id="L93" class="LineNr"> 93 </span> b8/copy-to-EAX 1/imm32 -<span id="L94" class="LineNr"> 94 </span>$kernel-string-equal:true: -<span id="L95" class="LineNr"> 95 </span> eb/jump $kernel-string-equal:end/disp8 -<span id="L96" class="LineNr"> 96 </span> <span class="Comment"># return false</span> -<span id="L97" class="LineNr"> 97 </span>$kernel-string-equal:false: -<span id="L98" class="LineNr"> 98 </span> b8/copy-to-EAX 0/imm32 -<span id="L99" class="LineNr"> 99 </span> -<span id="L100" class="LineNr">100 </span>$kernel-string-equal:end: -<span id="L101" class="LineNr">101 </span> <span class="Comment"># restore registers</span> -<span id="L102" class="LineNr">102 </span> 5f/pop-to-EDI -<span id="L103" class="LineNr">103 </span> 5e/pop-to-ESI -<span id="L104" class="LineNr">104 </span> 5b/pop-to-EBX -<span id="L105" class="LineNr">105 </span> 5a/pop-to-EDX -<span id="L106" class="LineNr">106 </span> 59/pop-to-ECX -<span id="L107" class="LineNr">107 </span> <span class="Comment"># end</span> -<span id="L108" class="LineNr">108 </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="L109" class="LineNr">109 </span> 5d/pop-to-EBP -<span id="L110" class="LineNr">110 </span> c3/return -<span id="L111" class="LineNr">111 </span> -<span id="L112" class="LineNr">112 </span><span class="SalientComment">## tests</span> -<span id="L113" class="LineNr">113 </span> -<span id="L114" class="LineNr">114 </span>test-compare-null-kernel-string-with-empty-array: -<span id="L115" class="LineNr">115 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "")</span> -<span id="L116" class="LineNr">116 </span> <span class="Comment"># push args</span> -<span id="L117" class="LineNr">117 </span> 68/push ""/imm32 -<span id="L118" class="LineNr">118 </span> 68/push Null-kernel-string/imm32 -<span id="L119" class="LineNr">119 </span> <span class="Comment"># call</span> -<span id="L120" class="LineNr">120 </span> e8/call kernel-string-equal/disp32 -<span id="L121" class="LineNr">121 </span> <span class="Comment"># discard args</span> -<span id="L122" class="LineNr">122 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L123" class="LineNr">123 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> -<span id="L124" class="LineNr">124 </span> <span class="Comment"># push args</span> -<span id="L125" class="LineNr">125 </span> 68/push "F - test-compare-null-kernel-string-with-empty-array"/imm32 -<span id="L126" class="LineNr">126 </span> 68/push 1/imm32/true -<span id="L127" class="LineNr">127 </span> 50/push-EAX -<span id="L128" class="LineNr">128 </span> <span class="Comment"># call</span> -<span id="L129" class="LineNr">129 </span> e8/call check-ints-equal/disp32 -<span id="L130" class="LineNr">130 </span> <span class="Comment"># discard args</span> -<span id="L131" class="LineNr">131 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L132" class="LineNr">132 </span> c3/return -<span id="L133" class="LineNr">133 </span> -<span id="L134" class="LineNr">134 </span>test-compare-null-kernel-string-with-non-empty-array: -<span id="L135" class="LineNr">135 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "Abc")</span> -<span id="L136" class="LineNr">136 </span> <span class="Comment"># push args</span> -<span id="L137" class="LineNr">137 </span> 68/push "Abc"/imm32 -<span id="L138" class="LineNr">138 </span> 68/push Null-kernel-string/imm32 -<span id="L139" class="LineNr">139 </span> <span class="Comment"># call</span> -<span id="L140" class="LineNr">140 </span> e8/call kernel-string-equal/disp32 -<span id="L141" class="LineNr">141 </span> <span class="Comment"># discard args</span> -<span id="L142" class="LineNr">142 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L143" class="LineNr">143 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> -<span id="L144" class="LineNr">144 </span> <span class="Comment"># push args</span> -<span id="L145" class="LineNr">145 </span> 68/push "F - test-compare-null-kernel-string-with-non-empty-array"/imm32 -<span id="L146" class="LineNr">146 </span> 68/push 0/imm32/false -<span id="L147" class="LineNr">147 </span> 50/push-EAX -<span id="L148" class="LineNr">148 </span> <span class="Comment"># call</span> -<span id="L149" class="LineNr">149 </span> e8/call check-ints-equal/disp32 -<span id="L150" class="LineNr">150 </span> <span class="Comment"># discard args</span> -<span id="L151" class="LineNr">151 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L152" class="LineNr">152 </span> c3/return -<span id="L153" class="LineNr">153 </span> -<span id="L154" class="LineNr">154 </span>test-compare-kernel-string-with-equal-array: -<span id="L155" class="LineNr">155 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abc")</span> -<span id="L156" class="LineNr">156 </span> <span class="Comment"># push args</span> -<span id="L157" class="LineNr">157 </span> 68/push "Abc"/imm32 -<span id="L158" class="LineNr">158 </span> 68/push Abc-kernel-string/imm32 -<span id="L159" class="LineNr">159 </span> <span class="Comment"># call</span> -<span id="L160" class="LineNr">160 </span> e8/call kernel-string-equal/disp32 -<span id="L161" class="LineNr">161 </span> <span class="Comment"># discard args</span> -<span id="L162" class="LineNr">162 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L163" class="LineNr">163 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> -<span id="L164" class="LineNr">164 </span> <span class="Comment"># push args</span> -<span id="L165" class="LineNr">165 </span> 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 -<span id="L166" class="LineNr">166 </span> 68/push 1/imm32/true -<span id="L167" class="LineNr">167 </span> 50/push-EAX -<span id="L168" class="LineNr">168 </span> <span class="Comment"># call</span> -<span id="L169" class="LineNr">169 </span> e8/call check-ints-equal/disp32 -<span id="L170" class="LineNr">170 </span> <span class="Comment"># discard args</span> -<span id="L171" class="LineNr">171 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L172" class="LineNr">172 </span> c3/return -<span id="L173" class="LineNr">173 </span> -<span id="L174" class="LineNr">174 </span>test-compare-kernel-string-with-inequal-array: -<span id="L175" class="LineNr">175 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Adc")</span> -<span id="L176" class="LineNr">176 </span> <span class="Comment"># push args</span> -<span id="L177" class="LineNr">177 </span> 68/push "Adc"/imm32 -<span id="L178" class="LineNr">178 </span> 68/push Abc-kernel-string/imm32 -<span id="L179" class="LineNr">179 </span> <span class="Comment"># call</span> -<span id="L180" class="LineNr">180 </span> e8/call kernel-string-equal/disp32 -<span id="L181" class="LineNr">181 </span> <span class="Comment"># discard args</span> -<span id="L182" class="LineNr">182 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L183" class="LineNr">183 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> -<span id="L184" class="LineNr">184 </span> <span class="Comment"># push args</span> -<span id="L185" class="LineNr">185 </span> 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 -<span id="L186" class="LineNr">186 </span> 68/push 0/imm32/false -<span id="L187" class="LineNr">187 </span> 50/push-EAX -<span id="L188" class="LineNr">188 </span> <span class="Comment"># call</span> -<span id="L189" class="LineNr">189 </span> e8/call check-ints-equal/disp32 -<span id="L190" class="LineNr">190 </span> <span class="Comment"># discard args</span> -<span id="L191" class="LineNr">191 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L192" class="LineNr">192 </span> c3/return -<span id="L193" class="LineNr">193 </span> -<span id="L194" class="LineNr">194 </span>test-compare-kernel-string-with-empty-array: -<span id="L195" class="LineNr">195 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "")</span> -<span id="L196" class="LineNr">196 </span> <span class="Comment"># push args</span> -<span id="L197" class="LineNr">197 </span> 68/push ""/imm32 -<span id="L198" class="LineNr">198 </span> 68/push Abc-kernel-string/imm32 -<span id="L199" class="LineNr">199 </span> <span class="Comment"># call</span> -<span id="L200" class="LineNr">200 </span> e8/call kernel-string-equal/disp32 -<span id="L201" class="LineNr">201 </span> <span class="Comment"># discard args</span> -<span id="L202" class="LineNr">202 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L203" class="LineNr">203 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> -<span id="L204" class="LineNr">204 </span> <span class="Comment"># push args</span> -<span id="L205" class="LineNr">205 </span> 68/push "F - test-compare-kernel-string-with-equal-array"/imm32 -<span id="L206" class="LineNr">206 </span> 68/push 0/imm32/false -<span id="L207" class="LineNr">207 </span> 50/push-EAX -<span id="L208" class="LineNr">208 </span> <span class="Comment"># call</span> -<span id="L209" class="LineNr">209 </span> e8/call check-ints-equal/disp32 -<span id="L210" class="LineNr">210 </span> <span class="Comment"># discard args</span> -<span id="L211" class="LineNr">211 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L212" class="LineNr">212 </span> c3/return -<span id="L213" class="LineNr">213 </span> -<span id="L214" class="LineNr">214 </span>test-compare-kernel-string-with-shorter-array: -<span id="L215" class="LineNr">215 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Ab")</span> -<span id="L216" class="LineNr">216 </span> <span class="Comment"># push args</span> -<span id="L217" class="LineNr">217 </span> 68/push "Ab"/imm32 -<span id="L218" class="LineNr">218 </span> 68/push Abc-kernel-string/imm32 -<span id="L219" class="LineNr">219 </span> <span class="Comment"># call</span> -<span id="L220" class="LineNr">220 </span> e8/call kernel-string-equal/disp32 -<span id="L221" class="LineNr">221 </span> <span class="Comment"># discard args</span> -<span id="L222" class="LineNr">222 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L223" class="LineNr">223 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> -<span id="L224" class="LineNr">224 </span> <span class="Comment"># push args</span> -<span id="L225" class="LineNr">225 </span> 68/push "F - test-compare-kernel-string-with-shorter-array"/imm32 -<span id="L226" class="LineNr">226 </span> 68/push 0/imm32/false -<span id="L227" class="LineNr">227 </span> 50/push-EAX -<span id="L228" class="LineNr">228 </span> <span class="Comment"># call</span> -<span id="L229" class="LineNr">229 </span> e8/call check-ints-equal/disp32 -<span id="L230" class="LineNr">230 </span> <span class="Comment"># discard args</span> -<span id="L231" class="LineNr">231 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L232" class="LineNr">232 </span> c3/return -<span id="L233" class="LineNr">233 </span> -<span id="L234" class="LineNr">234 </span>test-compare-kernel-string-with-longer-array: -<span id="L235" class="LineNr">235 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abcd")</span> -<span id="L236" class="LineNr">236 </span> <span class="Comment"># push args</span> -<span id="L237" class="LineNr">237 </span> 68/push "Abcd"/imm32 -<span id="L238" class="LineNr">238 </span> 68/push Abc-kernel-string/imm32 -<span id="L239" class="LineNr">239 </span> <span class="Comment"># call</span> -<span id="L240" class="LineNr">240 </span> e8/call kernel-string-equal/disp32 -<span id="L241" class="LineNr">241 </span> <span class="Comment"># discard args</span> -<span id="L242" class="LineNr">242 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L243" class="LineNr">243 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> -<span id="L244" class="LineNr">244 </span> <span class="Comment"># push args</span> -<span id="L245" class="LineNr">245 </span> 68/push "F - test-compare-kernel-string-with-longer-array"/imm32 -<span id="L246" class="LineNr">246 </span> 68/push 0/imm32/false -<span id="L247" class="LineNr">247 </span> 50/push-EAX -<span id="L248" class="LineNr">248 </span> <span class="Comment"># call</span> -<span id="L249" class="LineNr">249 </span> e8/call check-ints-equal/disp32 -<span id="L250" class="LineNr">250 </span> <span class="Comment"># discard args</span> -<span id="L251" class="LineNr">251 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> -<span id="L252" class="LineNr">252 </span> c3/return -<span id="L253" class="LineNr">253 </span> -<span id="L254" class="LineNr">254 </span><span class="SalientComment">## helpers</span> -<span id="L255" class="LineNr">255 </span> -<span id="L256" class="LineNr">256 </span><span class="Comment"># print msg to stderr if a != b, otherwise print "."</span> -<span id="L257" class="LineNr">257 </span>check-ints-equal: <span class="Comment"># (a : int, b : int, msg : (address array byte)) -> boolean</span> -<span id="L258" class="LineNr">258 </span> <span class="Comment"># prolog</span> -<span id="L259" class="LineNr">259 </span> 55/push-EBP -<span id="L260" class="LineNr">260 </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="L261" class="LineNr">261 </span> <span class="Comment"># save registers</span> -<span id="L262" class="LineNr">262 </span> 51/push-ECX -<span id="L263" class="LineNr">263 </span> 53/push-EBX -<span id="L264" class="LineNr">264 </span> <span class="Comment"># load args into EAX, EBX and ECX</span> -<span id="L265" class="LineNr">265 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> -<span id="L266" class="LineNr">266 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EBX</span> -<span id="L267" class="LineNr">267 </span> <span class="Comment"># if EAX == b/EBX</span> -<span id="L268" class="LineNr">268 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX and EBX</span> -<span id="L269" class="LineNr">269 </span> 75/jump-if-unequal $check-ints-equal:else/disp8 -<span id="L270" class="LineNr">270 </span> <span class="Comment"># print('.')</span> -<span id="L271" class="LineNr">271 </span> <span class="Comment"># push args</span> -<span id="L272" class="LineNr">272 </span> 68/push "."/imm32 -<span id="L273" class="LineNr">273 </span> <span class="Comment"># call</span> -<span id="L274" class="LineNr">274 </span> e8/call write-stderr/disp32 -<span id="L275" class="LineNr">275 </span> <span class="Comment"># discard args</span> -<span id="L276" class="LineNr">276 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L277" class="LineNr">277 </span> <span class="Comment"># return</span> -<span id="L278" class="LineNr">278 </span> eb/jump $check-ints-equal:end/disp8 -<span id="L279" class="LineNr">279 </span> <span class="Comment"># else:</span> -<span id="L280" class="LineNr">280 </span>$check-ints-equal:else: -<span id="L281" class="LineNr">281 </span> <span class="Comment"># copy msg into ECX</span> -<span id="L282" class="LineNr">282 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to ECX</span> -<span id="L283" class="LineNr">283 </span> <span class="Comment"># print(ECX)</span> -<span id="L284" class="LineNr">284 </span> <span class="Comment"># push args</span> -<span id="L285" class="LineNr">285 </span> 51/push-ECX -<span id="L286" class="LineNr">286 </span> <span class="Comment"># call</span> -<span id="L287" class="LineNr">287 </span> e8/call write-stderr/disp32 -<span id="L288" class="LineNr">288 </span> <span class="Comment"># discard args</span> -<span id="L289" class="LineNr">289 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L290" class="LineNr">290 </span> <span class="Comment"># print newline</span> -<span id="L291" class="LineNr">291 </span> <span class="Comment"># push args</span> -<span id="L292" class="LineNr">292 </span> 68/push Newline/imm32 -<span id="L293" class="LineNr">293 </span> <span class="Comment"># call</span> -<span id="L294" class="LineNr">294 </span> e8/call write-stderr/disp32 -<span id="L295" class="LineNr">295 </span> <span class="Comment"># discard args</span> -<span id="L296" class="LineNr">296 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L297" class="LineNr">297 </span>$check-ints-equal:end: -<span id="L298" class="LineNr">298 </span> <span class="Comment"># restore registers</span> -<span id="L299" class="LineNr">299 </span> 5b/pop-to-EBX -<span id="L300" class="LineNr">300 </span> 59/pop-to-ECX -<span id="L301" class="LineNr">301 </span> <span class="Comment"># end</span> -<span id="L302" class="LineNr">302 </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="L303" class="LineNr">303 </span> 5d/pop-to-EBP -<span id="L304" class="LineNr">304 </span> c3/return -<span id="L305" class="LineNr">305 </span> -<span id="L306" class="LineNr">306 </span>write-stderr: <span class="Comment"># s : (address array byte) -> <void></span> -<span id="L307" class="LineNr">307 </span> <span class="Comment"># prolog</span> -<span id="L308" class="LineNr">308 </span> 55/push-EBP -<span id="L309" class="LineNr">309 </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="L310" class="LineNr">310 </span> <span class="Comment"># save registers</span> -<span id="L311" class="LineNr">311 </span> 50/push-EAX -<span id="L312" class="LineNr">312 </span> 51/push-ECX -<span id="L313" class="LineNr">313 </span> 52/push-EDX -<span id="L314" class="LineNr">314 </span> 53/push-EBX -<span id="L315" class="LineNr">315 </span> <span class="Comment"># syscall(write, 2/stderr, (data) s+4, (size) *s)</span> -<span id="L316" class="LineNr">316 </span> <span class="Comment"># fd = 2 (stderr)</span> -<span id="L317" class="LineNr">317 </span> bb/copy-to-EBX 2/imm32 -<span id="L318" class="LineNr">318 </span> <span class="Comment"># x = s+4</span> -<span id="L319" class="LineNr">319 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ECX</span> -<span id="L320" class="LineNr">320 </span> 81 0/subop/add 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ECX</span> -<span id="L321" class="LineNr">321 </span> <span class="Comment"># size = *s</span> -<span id="L322" class="LineNr">322 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDX</span> -<span id="L323" class="LineNr">323 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> -<span id="L324" class="LineNr">324 </span> <span class="Comment"># syscall</span> -<span id="L325" class="LineNr">325 </span> b8/copy-to-EAX 4/imm32/write -<span id="L326" class="LineNr">326 </span> cd/syscall 0x80/imm8 -<span id="L327" class="LineNr">327 </span> <span class="Comment"># restore registers</span> -<span id="L328" class="LineNr">328 </span> 5b/pop-to-EBX -<span id="L329" class="LineNr">329 </span> 5a/pop-to-EDX -<span id="L330" class="LineNr">330 </span> 59/pop-to-ECX -<span id="L331" class="LineNr">331 </span> 58/pop-to-EAX -<span id="L332" class="LineNr">332 </span> <span class="Comment"># end</span> -<span id="L333" class="LineNr">333 </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="L334" class="LineNr">334 </span> 5d/pop-to-EBP -<span id="L335" class="LineNr">335 </span> c3/return -<span id="L336" class="LineNr">336 </span> -<span id="L337" class="LineNr">337 </span>== data -<span id="L338" class="LineNr">338 </span>Newline: +<span id="L18" class="LineNr"> 18 </span><span class="Comment"># instruction effective address operand displacement immediate</span> +<span id="L19" class="LineNr"> 19 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> +<span id="L20" class="LineNr"> 20 </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> +<span id="L21" class="LineNr"> 21 </span> +<span id="L22" class="LineNr"> 22 </span><span class="Comment"># main:</span> +<span id="L23" class="LineNr"> 23 </span> e8/call run-tests/disp32 <span class="Comment"># 'run-tests' is a function created automatically by SubX. It calls all functions that start with 'test-'.</span> +<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># syscall(exit, EAX)</span> +<span id="L25" class="LineNr"> 25 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> +<span id="L26" class="LineNr"> 26 </span> b8/copy-to-EAX 1/imm32 +<span id="L27" class="LineNr"> 27 </span> cd/syscall 0x80/imm8 +<span id="L28" class="LineNr"> 28 </span> +<span id="L29" class="LineNr"> 29 </span><span class="Comment"># compare a null-terminated ascii string with a more idiomatic length-prefixed byte array</span> +<span id="L30" class="LineNr"> 30 </span><span class="Comment"># reason for the name: the only place we should have null-terminated ascii strings is from commandline args</span> +<span id="L31" class="LineNr"> 31 </span>kernel-string-equal: <span class="Comment"># s : null-terminated ascii string, benchmark : length-prefixed ascii string -> EAX : boolean</span> +<span id="L32" class="LineNr"> 32 </span> <span class="Comment"># prolog</span> +<span id="L33" class="LineNr"> 33 </span> 55/push-EBP +<span id="L34" class="LineNr"> 34 </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="L35" class="LineNr"> 35 </span> <span class="Comment"># save registers</span> +<span id="L36" class="LineNr"> 36 </span> 51/push-ECX +<span id="L37" class="LineNr"> 37 </span> 52/push-EDX +<span id="L38" class="LineNr"> 38 </span> 53/push-EBX +<span id="L39" class="LineNr"> 39 </span> 56/push-ESI +<span id="L40" class="LineNr"> 40 </span> 57/push-EDI +<span id="L41" class="LineNr"> 41 </span> +<span id="L42" class="LineNr"> 42 </span> <span class="Comment"># pseudocode:</span> +<span id="L43" class="LineNr"> 43 </span> <span class="Comment"># initialize n = b.length</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># initialize s1 = s</span> +<span id="L45" class="LineNr"> 45 </span> <span class="Comment"># initialize s2 = b.data</span> +<span id="L46" class="LineNr"> 46 </span> <span class="Comment"># i = 0</span> +<span id="L47" class="LineNr"> 47 </span> <span class="Comment"># for (i = 0; i < n; ++n)</span> +<span id="L48" class="LineNr"> 48 </span> <span class="Comment"># c1 = *s1</span> +<span id="L49" class="LineNr"> 49 </span> <span class="Comment"># c2 = *s2</span> +<span id="L50" class="LineNr"> 50 </span> <span class="Comment"># if c1 == 0</span> +<span id="L51" class="LineNr"> 51 </span> <span class="Comment"># return false</span> +<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># if c1 != c2</span> +<span id="L53" class="LineNr"> 53 </span> <span class="Comment"># return false</span> +<span id="L54" class="LineNr"> 54 </span> <span class="Comment"># return *s1 == 0</span> +<span id="L55" class="LineNr"> 55 </span> <span class="Comment"># initialize s into EDI</span> +<span id="L56" class="LineNr"> 56 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 7/r32/EDI 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDI</span> +<span id="L57" class="LineNr"> 57 </span> <span class="Comment"># initialize benchmark length n into EDX</span> +<span id="L58" class="LineNr"> 58 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EDX</span> +<span id="L59" class="LineNr"> 59 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> +<span id="L60" class="LineNr"> 60 </span> <span class="Comment"># initialize benchmark data into ESI</span> +<span id="L61" class="LineNr"> 61 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 6/r32/ESI 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to ESI</span> +<span id="L62" class="LineNr"> 62 </span> 81 0/subop/add 3/mod/direct 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESI</span> +<span id="L63" class="LineNr"> 63 </span> <span class="Comment"># initialize loop counter i into ECX</span> +<span id="L64" class="LineNr"> 64 </span> b9/copy-to-ECX 0/imm32/exit +<span id="L65" class="LineNr"> 65 </span> <span class="Comment"># while (i/ECX < n/EDX)</span> +<span id="L66" class="LineNr"> 66 </span>$kernel-string-equal:loop: +<span id="L67" class="LineNr"> 67 </span> 39/compare 3/mod/direct 1/rm32/ECX <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"># compare ECX with EDX</span> +<span id="L68" class="LineNr"> 68 </span> 74/jump-if-equal $kernel-string-equal:break/disp8 +<span id="L69" class="LineNr"> 69 </span> <span class="Comment"># c1/EAX, c2/EBX = *s, *benchmark</span> +<span id="L70" class="LineNr"> 70 </span> b8/copy-to-EAX 0/imm32 +<span id="L71" class="LineNr"> 71 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> +<span id="L72" class="LineNr"> 72 </span> bb/copy-to-EBX 0/imm32 +<span id="L73" class="LineNr"> 73 </span> 8a/copy 0/mod/indirect 6/rm32/ESI <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *ESI to lower byte of EBX</span> +<span id="L74" class="LineNr"> 74 </span> <span class="Comment"># if (c1 == 0) return false</span> +<span id="L75" class="LineNr"> 75 </span> 3d/compare-EAX 0/imm32 +<span id="L76" class="LineNr"> 76 </span> 74/jump-if-equal $kernel-string-equal:false/disp8 +<span id="L77" class="LineNr"> 77 </span> <span class="Comment"># if (c1 != c2) return false</span> +<span id="L78" class="LineNr"> 78 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX with EBX</span> +<span id="L79" class="LineNr"> 79 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 +<span id="L80" class="LineNr"> 80 </span> <span class="Comment"># ++s1, ++s2, ++i</span> +<span id="L81" class="LineNr"> 81 </span> 41/inc-ECX +<span id="L82" class="LineNr"> 82 </span> 46/inc-ESI +<span id="L83" class="LineNr"> 83 </span> 47/inc-EDI +<span id="L84" class="LineNr"> 84 </span> <span class="Comment"># end while</span> +<span id="L85" class="LineNr"> 85 </span> eb/jump $kernel-string-equal:loop/disp8 +<span id="L86" class="LineNr"> 86 </span>$kernel-string-equal:break: +<span id="L87" class="LineNr"> 87 </span> <span class="Comment"># if (*s/EDI == 0) return true</span> +<span id="L88" class="LineNr"> 88 </span> b8/copy-to-EAX 0/imm32 +<span id="L89" class="LineNr"> 89 </span> 8a/copy 0/mod/indirect 7/rm32/EDI <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"># copy byte at *EDI to lower byte of EAX</span> +<span id="L90" class="LineNr"> 90 </span> 81 7/subop/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare EAX</span> +<span id="L91" class="LineNr"> 91 </span> 75/jump-if-not-equal $kernel-string-equal:false/disp8 +<span id="L92" class="LineNr"> 92 </span> b8/copy-to-EAX 1/imm32 +<span id="L93" class="LineNr"> 93 </span>$kernel-string-equal:true: +<span id="L94" class="LineNr"> 94 </span> eb/jump $kernel-string-equal:end/disp8 +<span id="L95" class="LineNr"> 95 </span> <span class="Comment"># return false</span> +<span id="L96" class="LineNr"> 96 </span>$kernel-string-equal:false: +<span id="L97" class="LineNr"> 97 </span> b8/copy-to-EAX 0/imm32 +<span id="L98" class="LineNr"> 98 </span> +<span id="L99" class="LineNr"> 99 </span>$kernel-string-equal:end: +<span id="L100" class="LineNr">100 </span> <span class="Comment"># restore registers</span> +<span id="L101" class="LineNr">101 </span> 5f/pop-to-EDI +<span id="L102" class="LineNr">102 </span> 5e/pop-to-ESI +<span id="L103" class="LineNr">103 </span> 5b/pop-to-EBX +<span id="L104" class="LineNr">104 </span> 5a/pop-to-EDX +<span id="L105" class="LineNr">105 </span> 59/pop-to-ECX +<span id="L106" class="LineNr">106 </span> <span class="Comment"># end</span> +<span id="L107" class="LineNr">107 </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="L108" class="LineNr">108 </span> 5d/pop-to-EBP +<span id="L109" class="LineNr">109 </span> c3/return +<span id="L110" class="LineNr">110 </span> +<span id="L111" class="LineNr">111 </span><span class="SalientComment">## tests</span> +<span id="L112" class="LineNr">112 </span> +<span id="L113" class="LineNr">113 </span>test-compare-null-kernel-string-with-empty-array: +<span id="L114" class="LineNr">114 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "")</span> +<span id="L115" class="LineNr">115 </span> <span class="Comment"># push args</span> +<span id="L116" class="LineNr">116 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L117" class="LineNr">117 </span> 68/push <span class="Special">Null-kernel-string</span>/imm32 +<span id="L118" class="LineNr">118 </span> <span class="Comment"># call</span> +<span id="L119" class="LineNr">119 </span> e8/call kernel-string-equal/disp32 +<span id="L120" class="LineNr">120 </span> <span class="Comment"># discard args</span> +<span id="L121" class="LineNr">121 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L122" class="LineNr">122 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> +<span id="L123" class="LineNr">123 </span> <span class="Comment"># push args</span> +<span id="L124" class="LineNr">124 </span> 68/push <span class="Constant">"F - test-compare-null-kernel-string-with-empty-array"</span>/imm32 +<span id="L125" class="LineNr">125 </span> 68/push 1/imm32/true +<span id="L126" class="LineNr">126 </span> 50/push-EAX +<span id="L127" class="LineNr">127 </span> <span class="Comment"># call</span> +<span id="L128" class="LineNr">128 </span> e8/call check-ints-equal/disp32 +<span id="L129" class="LineNr">129 </span> <span class="Comment"># discard args</span> +<span id="L130" class="LineNr">130 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L131" class="LineNr">131 </span> c3/return +<span id="L132" class="LineNr">132 </span> +<span id="L133" class="LineNr">133 </span>test-compare-null-kernel-string-with-non-empty-array: +<span id="L134" class="LineNr">134 </span> <span class="Comment"># EAX = kernel-string-equal(Null-kernel-string, "Abc")</span> +<span id="L135" class="LineNr">135 </span> <span class="Comment"># push args</span> +<span id="L136" class="LineNr">136 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L137" class="LineNr">137 </span> 68/push <span class="Special">Null-kernel-string</span>/imm32 +<span id="L138" class="LineNr">138 </span> <span class="Comment"># call</span> +<span id="L139" class="LineNr">139 </span> e8/call kernel-string-equal/disp32 +<span id="L140" class="LineNr">140 </span> <span class="Comment"># discard args</span> +<span id="L141" class="LineNr">141 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L142" class="LineNr">142 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> +<span id="L143" class="LineNr">143 </span> <span class="Comment"># push args</span> +<span id="L144" class="LineNr">144 </span> 68/push <span class="Constant">"F - test-compare-null-kernel-string-with-non-empty-array"</span>/imm32 +<span id="L145" class="LineNr">145 </span> 68/push 0/imm32/false +<span id="L146" class="LineNr">146 </span> 50/push-EAX +<span id="L147" class="LineNr">147 </span> <span class="Comment"># call</span> +<span id="L148" class="LineNr">148 </span> e8/call check-ints-equal/disp32 +<span id="L149" class="LineNr">149 </span> <span class="Comment"># discard args</span> +<span id="L150" class="LineNr">150 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L151" class="LineNr">151 </span> c3/return +<span id="L152" class="LineNr">152 </span> +<span id="L153" class="LineNr">153 </span>test-compare-kernel-string-with-equal-array: +<span id="L154" class="LineNr">154 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abc")</span> +<span id="L155" class="LineNr">155 </span> <span class="Comment"># push args</span> +<span id="L156" class="LineNr">156 </span> 68/push <span class="Constant">"Abc"</span>/imm32 +<span id="L157" class="LineNr">157 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L158" class="LineNr">158 </span> <span class="Comment"># call</span> +<span id="L159" class="LineNr">159 </span> e8/call kernel-string-equal/disp32 +<span id="L160" class="LineNr">160 </span> <span class="Comment"># discard args</span> +<span id="L161" class="LineNr">161 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L162" class="LineNr">162 </span> <span class="Comment"># call check-ints-equal(EAX, 1, msg)</span> +<span id="L163" class="LineNr">163 </span> <span class="Comment"># push args</span> +<span id="L164" class="LineNr">164 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-equal-array"</span>/imm32 +<span id="L165" class="LineNr">165 </span> 68/push 1/imm32/true +<span id="L166" class="LineNr">166 </span> 50/push-EAX +<span id="L167" class="LineNr">167 </span> <span class="Comment"># call</span> +<span id="L168" class="LineNr">168 </span> e8/call check-ints-equal/disp32 +<span id="L169" class="LineNr">169 </span> <span class="Comment"># discard args</span> +<span id="L170" class="LineNr">170 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L171" class="LineNr">171 </span> c3/return +<span id="L172" class="LineNr">172 </span> +<span id="L173" class="LineNr">173 </span>test-compare-kernel-string-with-inequal-array: +<span id="L174" class="LineNr">174 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Adc")</span> +<span id="L175" class="LineNr">175 </span> <span class="Comment"># push args</span> +<span id="L176" class="LineNr">176 </span> 68/push <span class="Constant">"Adc"</span>/imm32 +<span id="L177" class="LineNr">177 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L178" class="LineNr">178 </span> <span class="Comment"># call</span> +<span id="L179" class="LineNr">179 </span> e8/call kernel-string-equal/disp32 +<span id="L180" class="LineNr">180 </span> <span class="Comment"># discard args</span> +<span id="L181" class="LineNr">181 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L182" class="LineNr">182 </span> <span class="Comment"># call check-ints-equal(EAX, 0, msg)</span> +<span id="L183" class="LineNr">183 </span> <span class="Comment"># push args</span> +<span id="L184" class="LineNr">184 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-equal-array"</span>/imm32 +<span id="L185" class="LineNr">185 </span> 68/push 0/imm32/false +<span id="L186" class="LineNr">186 </span> 50/push-EAX +<span id="L187" class="LineNr">187 </span> <span class="Comment"># call</span> +<span id="L188" class="LineNr">188 </span> e8/call check-ints-equal/disp32 +<span id="L189" class="LineNr">189 </span> <span class="Comment"># discard args</span> +<span id="L190" class="LineNr">190 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L191" class="LineNr">191 </span> c3/return +<span id="L192" class="LineNr">192 </span> +<span id="L193" class="LineNr">193 </span>test-compare-kernel-string-with-empty-array: +<span id="L194" class="LineNr">194 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "")</span> +<span id="L195" class="LineNr">195 </span> <span class="Comment"># push args</span> +<span id="L196" class="LineNr">196 </span> 68/push <span class="Constant">""</span>/imm32 +<span id="L197" class="LineNr">197 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L198" class="LineNr">198 </span> <span class="Comment"># call</span> +<span id="L199" class="LineNr">199 </span> e8/call kernel-string-equal/disp32 +<span id="L200" class="LineNr">200 </span> <span class="Comment"># discard args</span> +<span id="L201" class="LineNr">201 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L202" class="LineNr">202 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> +<span id="L203" class="LineNr">203 </span> <span class="Comment"># push args</span> +<span id="L204" class="LineNr">204 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-equal-array"</span>/imm32 +<span id="L205" class="LineNr">205 </span> 68/push 0/imm32/false +<span id="L206" class="LineNr">206 </span> 50/push-EAX +<span id="L207" class="LineNr">207 </span> <span class="Comment"># call</span> +<span id="L208" class="LineNr">208 </span> e8/call check-ints-equal/disp32 +<span id="L209" class="LineNr">209 </span> <span class="Comment"># discard args</span> +<span id="L210" class="LineNr">210 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L211" class="LineNr">211 </span> c3/return +<span id="L212" class="LineNr">212 </span> +<span id="L213" class="LineNr">213 </span>test-compare-kernel-string-with-shorter-array: +<span id="L214" class="LineNr">214 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Ab")</span> +<span id="L215" class="LineNr">215 </span> <span class="Comment"># push args</span> +<span id="L216" class="LineNr">216 </span> 68/push <span class="Constant">"Ab"</span>/imm32 +<span id="L217" class="LineNr">217 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L218" class="LineNr">218 </span> <span class="Comment"># call</span> +<span id="L219" class="LineNr">219 </span> e8/call kernel-string-equal/disp32 +<span id="L220" class="LineNr">220 </span> <span class="Comment"># discard args</span> +<span id="L221" class="LineNr">221 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L222" class="LineNr">222 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> +<span id="L223" class="LineNr">223 </span> <span class="Comment"># push args</span> +<span id="L224" class="LineNr">224 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-shorter-array"</span>/imm32 +<span id="L225" class="LineNr">225 </span> 68/push 0/imm32/false +<span id="L226" class="LineNr">226 </span> 50/push-EAX +<span id="L227" class="LineNr">227 </span> <span class="Comment"># call</span> +<span id="L228" class="LineNr">228 </span> e8/call check-ints-equal/disp32 +<span id="L229" class="LineNr">229 </span> <span class="Comment"># discard args</span> +<span id="L230" class="LineNr">230 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L231" class="LineNr">231 </span> c3/return +<span id="L232" class="LineNr">232 </span> +<span id="L233" class="LineNr">233 </span>test-compare-kernel-string-with-longer-array: +<span id="L234" class="LineNr">234 </span> <span class="Comment"># EAX = kernel-string-equal(Abc-kernel-string, "Abcd")</span> +<span id="L235" class="LineNr">235 </span> <span class="Comment"># push args</span> +<span id="L236" class="LineNr">236 </span> 68/push <span class="Constant">"Abcd"</span>/imm32 +<span id="L237" class="LineNr">237 </span> 68/push <span class="Special">Abc-kernel-string</span>/imm32 +<span id="L238" class="LineNr">238 </span> <span class="Comment"># call</span> +<span id="L239" class="LineNr">239 </span> e8/call kernel-string-equal/disp32 +<span id="L240" class="LineNr">240 </span> <span class="Comment"># discard args</span> +<span id="L241" class="LineNr">241 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L242" class="LineNr">242 </span> <span class="Comment"># call check-ints-equal(EAX, 0)</span> +<span id="L243" class="LineNr">243 </span> <span class="Comment"># push args</span> +<span id="L244" class="LineNr">244 </span> 68/push <span class="Constant">"F - test-compare-kernel-string-with-longer-array"</span>/imm32 +<span id="L245" class="LineNr">245 </span> 68/push 0/imm32/false +<span id="L246" class="LineNr">246 </span> 50/push-EAX +<span id="L247" class="LineNr">247 </span> <span class="Comment"># call</span> +<span id="L248" class="LineNr">248 </span> e8/call check-ints-equal/disp32 +<span id="L249" class="LineNr">249 </span> <span class="Comment"># discard args</span> +<span id="L250" class="LineNr">250 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/imm32 <span class="Comment"># add to ESP</span> +<span id="L251" class="LineNr">251 </span> c3/return +<span id="L252" class="LineNr">252 </span> +<span id="L253" class="LineNr">253 </span><span class="SalientComment">## helpers</span> +<span id="L254" class="LineNr">254 </span> +<span id="L255" class="LineNr">255 </span><span class="Comment"># print msg to stderr if a != b, otherwise print "."</span> +<span id="L256" class="LineNr">256 </span>check-ints-equal: <span class="Comment"># (a : int, b : int, msg : (address array byte)) -> boolean</span> +<span id="L257" class="LineNr">257 </span> <span class="Comment"># prolog</span> +<span id="L258" class="LineNr">258 </span> 55/push-EBP +<span id="L259" class="LineNr">259 </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="L260" class="LineNr">260 </span> <span class="Comment"># save registers</span> +<span id="L261" class="LineNr">261 </span> 51/push-ECX +<span id="L262" class="LineNr">262 </span> 53/push-EBX +<span id="L263" class="LineNr">263 </span> <span class="Comment"># load args into EAX, EBX and ECX</span> +<span id="L264" class="LineNr">264 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 0/r32/EAX 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EAX</span> +<span id="L265" class="LineNr">265 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 3/r32/EBX 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+12) to EBX</span> +<span id="L266" class="LineNr">266 </span> <span class="Comment"># if EAX == b/EBX</span> +<span id="L267" class="LineNr">267 </span> 39/compare 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># compare EAX and EBX</span> +<span id="L268" class="LineNr">268 </span> 75/jump-if-unequal $check-ints-equal:else/disp8 +<span id="L269" class="LineNr">269 </span> <span class="Comment"># print('.')</span> +<span id="L270" class="LineNr">270 </span> <span class="Comment"># push args</span> +<span id="L271" class="LineNr">271 </span> 68/push <span class="Constant">"."</span>/imm32 +<span id="L272" class="LineNr">272 </span> <span class="Comment"># call</span> +<span id="L273" class="LineNr">273 </span> e8/call write-stderr/disp32 +<span id="L274" class="LineNr">274 </span> <span class="Comment"># discard args</span> +<span id="L275" class="LineNr">275 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L276" class="LineNr">276 </span> <span class="Comment"># return</span> +<span id="L277" class="LineNr">277 </span> eb/jump $check-ints-equal:end/disp8 +<span id="L278" class="LineNr">278 </span> <span class="Comment"># else:</span> +<span id="L279" class="LineNr">279 </span>$check-ints-equal:else: +<span id="L280" class="LineNr">280 </span> <span class="Comment"># copy msg into ECX</span> +<span id="L281" class="LineNr">281 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 0x10/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+16) to ECX</span> +<span id="L282" class="LineNr">282 </span> <span class="Comment"># print(ECX)</span> +<span id="L283" class="LineNr">283 </span> <span class="Comment"># push args</span> +<span id="L284" class="LineNr">284 </span> 51/push-ECX +<span id="L285" class="LineNr">285 </span> <span class="Comment"># call</span> +<span id="L286" class="LineNr">286 </span> e8/call write-stderr/disp32 +<span id="L287" class="LineNr">287 </span> <span class="Comment"># discard args</span> +<span id="L288" class="LineNr">288 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L289" class="LineNr">289 </span> <span class="Comment"># print newline</span> +<span id="L290" class="LineNr">290 </span> <span class="Comment"># push args</span> +<span id="L291" class="LineNr">291 </span> 68/push <span class="Special">Newline</span>/imm32 +<span id="L292" class="LineNr">292 </span> <span class="Comment"># call</span> +<span id="L293" class="LineNr">293 </span> e8/call write-stderr/disp32 +<span id="L294" class="LineNr">294 </span> <span class="Comment"># discard args</span> +<span id="L295" class="LineNr">295 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L296" class="LineNr">296 </span>$check-ints-equal:end: +<span id="L297" class="LineNr">297 </span> <span class="Comment"># restore registers</span> +<span id="L298" class="LineNr">298 </span> 5b/pop-to-EBX +<span id="L299" class="LineNr">299 </span> 59/pop-to-ECX +<span id="L300" class="LineNr">300 </span> <span class="Comment"># end</span> +<span id="L301" class="LineNr">301 </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="L302" class="LineNr">302 </span> 5d/pop-to-EBP +<span id="L303" class="LineNr">303 </span> c3/return +<span id="L304" class="LineNr">304 </span> +<span id="L305" class="LineNr">305 </span>write-stderr: <span class="Comment"># s : (address array byte) -> <void></span> +<span id="L306" class="LineNr">306 </span> <span class="Comment"># prolog</span> +<span id="L307" class="LineNr">307 </span> 55/push-EBP +<span id="L308" class="LineNr">308 </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="L309" class="LineNr">309 </span> <span class="Comment"># save registers</span> +<span id="L310" class="LineNr">310 </span> 50/push-EAX +<span id="L311" class="LineNr">311 </span> 51/push-ECX +<span id="L312" class="LineNr">312 </span> 52/push-EDX +<span id="L313" class="LineNr">313 </span> 53/push-EBX +<span id="L314" class="LineNr">314 </span> <span class="Comment"># syscall(write, 2/stderr, (data) s+4, (size) *s)</span> +<span id="L315" class="LineNr">315 </span> <span class="Comment"># fd = 2 (stderr)</span> +<span id="L316" class="LineNr">316 </span> bb/copy-to-EBX 2/imm32 +<span id="L317" class="LineNr">317 </span> <span class="Comment"># x = s+4</span> +<span id="L318" class="LineNr">318 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 1/r32/ECX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to ECX</span> +<span id="L319" class="LineNr">319 </span> 81 0/subop/add 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ECX</span> +<span id="L320" class="LineNr">320 </span> <span class="Comment"># size = *s</span> +<span id="L321" class="LineNr">321 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(EBP+8) to EDX</span> +<span id="L322" class="LineNr">322 </span> 8b/copy 0/mod/indirect 2/rm32/EDX <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 EDX</span> +<span id="L323" class="LineNr">323 </span> <span class="Comment"># syscall</span> +<span id="L324" class="LineNr">324 </span> b8/copy-to-EAX 4/imm32/write +<span id="L325" class="LineNr">325 </span> cd/syscall 0x80/imm8 +<span id="L326" class="LineNr">326 </span> <span class="Comment"># restore registers</span> +<span id="L327" class="LineNr">327 </span> 5b/pop-to-EBX +<span id="L328" class="LineNr">328 </span> 5a/pop-to-EDX +<span id="L329" class="LineNr">329 </span> 59/pop-to-ECX +<span id="L330" class="LineNr">330 </span> 58/pop-to-EAX +<span id="L331" class="LineNr">331 </span> <span class="Comment"># end</span> +<span id="L332" class="LineNr">332 </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="L333" class="LineNr">333 </span> 5d/pop-to-EBP +<span id="L334" class="LineNr">334 </span> c3/return +<span id="L335" class="LineNr">335 </span> +<span id="L336" class="LineNr">336 </span>== data +<span id="L337" class="LineNr">337 </span> +<span id="L338" class="LineNr">338 </span><span class="Special">Newline</span>: <span id="L339" class="LineNr">339 </span> <span class="Comment"># size</span> <span id="L340" class="LineNr">340 </span> 01 00 00 00 <span id="L341" class="LineNr">341 </span> <span class="Comment"># data</span> <span id="L342" class="LineNr">342 </span> 0a/newline <span id="L343" class="LineNr">343 </span> <span id="L344" class="LineNr">344 </span><span class="Comment"># for kernel-string-equal tests</span> -<span id="L345" class="LineNr">345 </span>Null-kernel-string: +<span id="L345" class="LineNr">345 </span><span class="Special">Null-kernel-string</span>: <span id="L346" class="LineNr">346 </span> 00/null -<span id="L347" class="LineNr">347 </span>Abc-kernel-string: -<span id="L348" class="LineNr">348 </span> 41/A 62/b 63/c 00/null +<span id="L347" class="LineNr">347 </span><span class="Special">Abc-kernel-string</span>: +<span id="L348" class="LineNr">348 </span> 41/<span class="Special">A</span> 62/b 63/c 00/null <span id="L349" class="LineNr">349 </span> <span id="L350" class="LineNr">350 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> diff --git a/html/subx/examples/ex12.subx.html b/html/subx/examples/ex12.subx.html index b4ad239c..ac02a719 100644 --- a/html/subx/examples/ex12.subx.html +++ b/html/subx/examples/ex12.subx.html @@ -17,6 +17,7 @@ a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -68,7 +69,7 @@ if ('onhashchange' in window) { <span id="L12" class="LineNr">12 </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> <span id="L13" class="LineNr">13 </span> <span id="L14" class="LineNr">14 </span> <span class="Comment"># syscall(mmap, 0x1000)</span> -<span id="L15" class="LineNr">15 </span> bb/copy-to-EBX mmap-new-segment/imm32 +<span id="L15" class="LineNr">15 </span> bb/copy-to-EBX <span class="Special">Mmap-new-segment</span>/imm32 <span id="L16" class="LineNr">16 </span> b8/copy-to-EAX 0x5a/imm32/mmap <span id="L17" class="LineNr">17 </span> cd/syscall 0x80/imm8 <span id="L18" class="LineNr">18 </span> @@ -81,22 +82,23 @@ if ('onhashchange' in window) { <span id="L25" class="LineNr">25 </span> cd/syscall 0x80/imm8 <span id="L26" class="LineNr">26 </span> <span id="L27" class="LineNr">27 </span>== data -<span id="L28" class="LineNr">28 </span><span class="Comment"># various constants used here were found in the Linux sources (search for file mman-common.h)</span> -<span id="L29" class="LineNr">29 </span>mmap-new-segment: <span class="Comment"># type mmap_arg_struct</span> -<span id="L30" class="LineNr">30 </span> <span class="Comment"># addr</span> -<span id="L31" class="LineNr">31 </span> 00 00 00 00 <span class="Comment"># null</span> -<span id="L32" class="LineNr">32 </span> <span class="Comment"># len</span> -<span id="L33" class="LineNr">33 </span> 00 01 00 00 <span class="Comment"># 0x1000</span> -<span id="L34" class="LineNr">34 </span> <span class="Comment"># protection flags</span> -<span id="L35" class="LineNr">35 </span> 03 00 00 00 <span class="Comment"># PROT_READ | PROT_WRITE</span> -<span id="L36" class="LineNr">36 </span> <span class="Comment"># sharing flags</span> -<span id="L37" class="LineNr">37 </span> 22 00 00 00 <span class="Comment"># MAP_PRIVATE | MAP_ANONYMOUS</span> -<span id="L38" class="LineNr">38 </span> <span class="Comment"># fd</span> -<span id="L39" class="LineNr">39 </span> ff ff ff ff <span class="Comment"># -1 since MAP_ANONYMOUS is specified</span> -<span id="L40" class="LineNr">40 </span> <span class="Comment"># offset</span> -<span id="L41" class="LineNr">41 </span> 00 00 00 00 <span class="Comment"># 0 since MAP_ANONYMOUS is specified</span> -<span id="L42" class="LineNr">42 </span> -<span id="L43" class="LineNr">43 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L28" class="LineNr">28 </span> +<span id="L29" class="LineNr">29 </span><span class="Comment"># various constants used here were found in the Linux sources (search for file mman-common.h)</span> +<span id="L30" class="LineNr">30 </span><span class="Special">Mmap-new-segment</span>: <span class="Comment"># type mmap_arg_struct</span> +<span id="L31" class="LineNr">31 </span> <span class="Comment"># addr</span> +<span id="L32" class="LineNr">32 </span> 00 00 00 00 <span class="Comment"># null</span> +<span id="L33" class="LineNr">33 </span> <span class="Comment"># len</span> +<span id="L34" class="LineNr">34 </span> 00 01 00 00 <span class="Comment"># 0x1000</span> +<span id="L35" class="LineNr">35 </span> <span class="Comment"># protection flags</span> +<span id="L36" class="LineNr">36 </span> 03 00 00 00 <span class="Comment"># PROT_READ | PROT_WRITE</span> +<span id="L37" class="LineNr">37 </span> <span class="Comment"># sharing flags</span> +<span id="L38" class="LineNr">38 </span> 22 00 00 00 <span class="Comment"># MAP_PRIVATE | MAP_ANONYMOUS</span> +<span id="L39" class="LineNr">39 </span> <span class="Comment"># fd</span> +<span id="L40" class="LineNr">40 </span> ff ff ff ff <span class="Comment"># -1 since MAP_ANONYMOUS is specified</span> +<span id="L41" class="LineNr">41 </span> <span class="Comment"># offset</span> +<span id="L42" class="LineNr">42 </span> 00 00 00 00 <span class="Comment"># 0 since MAP_ANONYMOUS is specified</span> +<span id="L43" class="LineNr">43 </span> +<span id="L44" class="LineNr">44 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex2.subx.html b/html/subx/examples/ex2.subx.html index 640e0bdf..bb45914d 100644 --- a/html/subx/examples/ex2.subx.html +++ b/html/subx/examples/ex2.subx.html @@ -63,13 +63,14 @@ if ('onhashchange' in window) { <span id="L8" class="LineNr"> 8 </span><span class="Comment"># 2</span> <span id="L9" class="LineNr"> 9 </span> <span id="L10" class="LineNr">10 </span>== code -<span id="L11" class="LineNr">11 </span>bb/copy-to-EBX 1/imm32 -<span id="L12" class="LineNr">12 </span>43/inc-EBX -<span id="L13" class="LineNr">13 </span><span class="Comment"># exit(EBX)</span> -<span id="L14" class="LineNr">14 </span>b8/copy-to-EAX 1/imm32 -<span id="L15" class="LineNr">15 </span>cd/syscall 0x80/imm8 -<span id="L16" class="LineNr">16 </span> -<span id="L17" class="LineNr">17 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L11" class="LineNr">11 </span> +<span id="L12" class="LineNr">12 </span>bb/copy-to-EBX 1/imm32 +<span id="L13" class="LineNr">13 </span>43/inc-EBX +<span id="L14" class="LineNr">14 </span><span class="Comment"># exit(EBX)</span> +<span id="L15" class="LineNr">15 </span>b8/copy-to-EAX 1/imm32 +<span id="L16" class="LineNr">16 </span>cd/syscall 0x80/imm8 +<span id="L17" class="LineNr">17 </span> +<span id="L18" class="LineNr">18 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex3.subx.html b/html/subx/examples/ex3.subx.html index 140d9224..8323af89 100644 --- a/html/subx/examples/ex3.subx.html +++ b/html/subx/examples/ex3.subx.html @@ -67,28 +67,29 @@ if ('onhashchange' in window) { <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> -<span id="L14" class="LineNr">14 </span> <span class="Comment"># result: EBX = 0</span> -<span id="L15" class="LineNr">15 </span> bb/copy-to-EBX 0/imm32 -<span id="L16" class="LineNr">16 </span> <span class="Comment"># counter: ECX = 1</span> -<span id="L17" class="LineNr">17 </span> b9/copy-to-ECX 1/imm32 -<span id="L18" class="LineNr">18 </span> -<span id="L19" class="LineNr">19 </span>$loop: -<span id="L20" class="LineNr">20 </span> <span class="Comment"># while (counter <= 10)</span> -<span id="L21" class="LineNr">21 </span> 81 7/subop/compare 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xa/imm32 <span class="Comment"># compare ECX</span> -<span id="L22" class="LineNr">22 </span> 7f/jump-if-greater $exit/disp8 -<span id="L23" class="LineNr">23 </span> <span class="Comment"># result += counter</span> -<span id="L24" class="LineNr">24 </span> 01/add 3/mod/direct 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># add ECX to EBX</span> -<span id="L25" class="LineNr">25 </span> <span class="Comment"># ++counter</span> -<span id="L26" class="LineNr">26 </span> 41/inc-ECX -<span id="L27" class="LineNr">27 </span> <span class="Comment"># loop</span> -<span id="L28" class="LineNr">28 </span> eb/jump $loop/disp8 -<span id="L29" class="LineNr">29 </span> -<span id="L30" class="LineNr">30 </span>$exit: -<span id="L31" class="LineNr">31 </span> <span class="Comment"># exit(EBX)</span> -<span id="L32" class="LineNr">32 </span> b8/copy-to-EAX 1/imm32 -<span id="L33" class="LineNr">33 </span> cd/syscall 0x80/imm8 -<span id="L34" class="LineNr">34 </span> -<span id="L35" class="LineNr">35 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L14" class="LineNr">14 </span> +<span id="L15" class="LineNr">15 </span> <span class="Comment"># result: EBX = 0</span> +<span id="L16" class="LineNr">16 </span> bb/copy-to-EBX 0/imm32 +<span id="L17" class="LineNr">17 </span> <span class="Comment"># counter: ECX = 1</span> +<span id="L18" class="LineNr">18 </span> b9/copy-to-ECX 1/imm32 +<span id="L19" class="LineNr">19 </span> +<span id="L20" class="LineNr">20 </span>$loop: +<span id="L21" class="LineNr">21 </span> <span class="Comment"># while (counter <= 10)</span> +<span id="L22" class="LineNr">22 </span> 81 7/subop/compare 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xa/imm32 <span class="Comment"># compare ECX</span> +<span id="L23" class="LineNr">23 </span> 7f/jump-if-greater $exit/disp8 +<span id="L24" class="LineNr">24 </span> <span class="Comment"># result += counter</span> +<span id="L25" class="LineNr">25 </span> 01/add 3/mod/direct 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># add ECX to EBX</span> +<span id="L26" class="LineNr">26 </span> <span class="Comment"># ++counter</span> +<span id="L27" class="LineNr">27 </span> 41/inc-ECX +<span id="L28" class="LineNr">28 </span> <span class="Comment"># loop</span> +<span id="L29" class="LineNr">29 </span> eb/jump $loop/disp8 +<span id="L30" class="LineNr">30 </span> +<span id="L31" class="LineNr">31 </span>$exit: +<span id="L32" class="LineNr">32 </span> <span class="Comment"># exit(EBX)</span> +<span id="L33" class="LineNr">33 </span> b8/copy-to-EAX 1/imm32 +<span id="L34" class="LineNr">34 </span> cd/syscall 0x80/imm8 +<span id="L35" class="LineNr">35 </span> +<span id="L36" class="LineNr">36 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex4.subx.html b/html/subx/examples/ex4.subx.html index ba639cde..3db6e2ec 100644 --- a/html/subx/examples/ex4.subx.html +++ b/html/subx/examples/ex4.subx.html @@ -16,6 +16,7 @@ a { color:#eeeeee; text-decoration: none; } a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -60,37 +61,39 @@ if ('onhashchange' in window) { <span id="L5" class="LineNr"> 5 </span><span class="Comment"># $ subx run examples/ex4</span> <span id="L6" class="LineNr"> 6 </span> <span id="L7" class="LineNr"> 7 </span>== code -<span id="L8" class="LineNr"> 8 </span><span class="Comment"># syscall(read, stdin, x, 1)</span> -<span id="L9" class="LineNr"> 9 </span> <span class="Comment"># fd = 0 (stdin)</span> -<span id="L10" class="LineNr">10 </span>bb/copy-to-EBX 0/imm32 -<span id="L11" class="LineNr">11 </span> <span class="Comment"># initialize x (location to write result to)</span> -<span id="L12" class="LineNr">12 </span>b9/copy-to-ECX x/imm32 -<span id="L13" class="LineNr">13 </span> <span class="Comment"># size = 1 character</span> -<span id="L14" class="LineNr">14 </span>ba/copy-to-EDX 1/imm32 -<span id="L15" class="LineNr">15 </span> <span class="Comment"># syscall</span> -<span id="L16" class="LineNr">16 </span>b8/copy-to-EAX 3/imm32/read -<span id="L17" class="LineNr">17 </span>cd/syscall 0x80/imm8 -<span id="L18" class="LineNr">18 </span> -<span id="L19" class="LineNr">19 </span><span class="Comment"># syscall(write, stdout, x, 1)</span> -<span id="L20" class="LineNr">20 </span> <span class="Comment"># fd = 1 (stdout)</span> -<span id="L21" class="LineNr">21 </span>bb/copy-to-EBX 1/imm32 -<span id="L22" class="LineNr">22 </span> <span class="Comment"># initialize x (location to read from)</span> -<span id="L23" class="LineNr">23 </span>b9/copy-to-ECX x/imm32 -<span id="L24" class="LineNr">24 </span> <span class="Comment"># size = 1 character</span> -<span id="L25" class="LineNr">25 </span>ba/copy-to-EDX 1/imm32 -<span id="L26" class="LineNr">26 </span> <span class="Comment"># syscall</span> -<span id="L27" class="LineNr">27 </span>b8/copy-to-EAX 4/imm32/write -<span id="L28" class="LineNr">28 </span>cd/syscall 0x80/imm8 -<span id="L29" class="LineNr">29 </span> -<span id="L30" class="LineNr">30 </span><span class="Comment"># syscall(exit, EBX)</span> -<span id="L31" class="LineNr">31 </span>b8/copy-to-EAX 1/imm32/exit -<span id="L32" class="LineNr">32 </span>cd/syscall 0x80/imm8 -<span id="L33" class="LineNr">33 </span> -<span id="L34" class="LineNr">34 </span>== data -<span id="L35" class="LineNr">35 </span>x: -<span id="L36" class="LineNr">36 </span> 00 00 00 00 <span class="Comment"># space for read() to write to</span> -<span id="L37" class="LineNr">37 </span> -<span id="L38" class="LineNr">38 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L8" class="LineNr"> 8 </span> +<span id="L9" class="LineNr"> 9 </span><span class="Comment"># syscall(read, stdin, X, 1)</span> +<span id="L10" class="LineNr">10 </span> <span class="Comment"># fd = 0 (stdin)</span> +<span id="L11" class="LineNr">11 </span>bb/copy-to-EBX 0/imm32 +<span id="L12" class="LineNr">12 </span> <span class="Comment"># initialize X (location to write result to)</span> +<span id="L13" class="LineNr">13 </span>b9/copy-to-ECX <span class="Special">X</span>/imm32 +<span id="L14" class="LineNr">14 </span> <span class="Comment"># size = 1 character</span> +<span id="L15" class="LineNr">15 </span>ba/copy-to-EDX 1/imm32 +<span id="L16" class="LineNr">16 </span> <span class="Comment"># syscall</span> +<span id="L17" class="LineNr">17 </span>b8/copy-to-EAX 3/imm32/read +<span id="L18" class="LineNr">18 </span>cd/syscall 0x80/imm8 +<span id="L19" class="LineNr">19 </span> +<span id="L20" class="LineNr">20 </span><span class="Comment"># syscall(write, stdout, X, 1)</span> +<span id="L21" class="LineNr">21 </span> <span class="Comment"># fd = 1 (stdout)</span> +<span id="L22" class="LineNr">22 </span>bb/copy-to-EBX 1/imm32 +<span id="L23" class="LineNr">23 </span> <span class="Comment"># initialize X (location to read from)</span> +<span id="L24" class="LineNr">24 </span>b9/copy-to-ECX <span class="Special">X</span>/imm32 +<span id="L25" class="LineNr">25 </span> <span class="Comment"># size = 1 character</span> +<span id="L26" class="LineNr">26 </span>ba/copy-to-EDX 1/imm32 +<span id="L27" class="LineNr">27 </span> <span class="Comment"># syscall</span> +<span id="L28" class="LineNr">28 </span>b8/copy-to-EAX 4/imm32/write +<span id="L29" class="LineNr">29 </span>cd/syscall 0x80/imm8 +<span id="L30" class="LineNr">30 </span> +<span id="L31" class="LineNr">31 </span><span class="Comment"># syscall(exit, EBX)</span> +<span id="L32" class="LineNr">32 </span>b8/copy-to-EAX 1/imm32/exit +<span id="L33" class="LineNr">33 </span>cd/syscall 0x80/imm8 +<span id="L34" class="LineNr">34 </span> +<span id="L35" class="LineNr">35 </span>== data +<span id="L36" class="LineNr">36 </span> +<span id="L37" class="LineNr">37 </span><span class="Special">X</span>: +<span id="L38" class="LineNr">38 </span> 00 00 00 00 <span class="Comment"># space for read() to write to</span> +<span id="L39" class="LineNr">39 </span> +<span id="L40" class="LineNr">40 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex6.subx.html b/html/subx/examples/ex6.subx.html index 5df92a48..ccf6e032 100644 --- a/html/subx/examples/ex6.subx.html +++ b/html/subx/examples/ex6.subx.html @@ -17,6 +17,7 @@ a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -66,13 +67,13 @@ if ('onhashchange' in window) { <span id="L10" class="LineNr">10 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> <span id="L11" class="LineNr">11 </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> <span id="L12" class="LineNr">12 </span> -<span id="L13" class="LineNr">13 </span> <span class="Comment"># syscall(write, stdout, x, size)</span> +<span id="L13" class="LineNr">13 </span> <span class="Comment"># syscall(write, stdout, X, size)</span> <span id="L14" class="LineNr">14 </span> <span class="Comment"># fd = 1 (stdout)</span> <span id="L15" class="LineNr">15 </span> bb/copy-to-EBX 1/imm32 -<span id="L16" class="LineNr">16 </span> <span class="Comment"># initialize x (location to write result to)</span> -<span id="L17" class="LineNr">17 </span> b9/copy-to-ECX x/imm32 +<span id="L16" class="LineNr">16 </span> <span class="Comment"># initialize X (location to write result to)</span> +<span id="L17" class="LineNr">17 </span> b9/copy-to-ECX <span class="Special">X</span>/imm32 <span id="L18" class="LineNr">18 </span> <span class="Comment"># initialize size</span> -<span id="L19" class="LineNr">19 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 2/r32/EDX size/disp32 <span class="Delimiter"> . </span> <span class="Comment"># copy *size to EDX</span> +<span id="L19" class="LineNr">19 </span> 8b/copy 0/mod/indirect 5/rm32/.disp32 <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 2/r32/EDX <span class="Special">Size</span>/disp32 <span class="Delimiter"> . </span> <span class="Comment"># copy *size to EDX</span> <span id="L20" class="LineNr">20 </span> <span class="Comment"># syscall</span> <span id="L21" class="LineNr">21 </span> b8/copy-to-EAX 4/imm32/write <span id="L22" class="LineNr">22 </span> cd/syscall 0x80/imm8 @@ -82,13 +83,14 @@ if ('onhashchange' in window) { <span id="L26" class="LineNr">26 </span> cd/syscall 0x80/imm8 <span id="L27" class="LineNr">27 </span> <span id="L28" class="LineNr">28 </span>== data -<span id="L29" class="LineNr">29 </span>size: <span class="Comment"># size of string</span> -<span id="L30" class="LineNr">30 </span> 0e 00 00 00 <span class="Comment"># 14</span> -<span id="L31" class="LineNr">31 </span>x: <span class="Comment"># string to print</span> -<span id="L32" class="LineNr">32 </span> 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00 -<span id="L33" class="LineNr">33 </span><span class="Comment"># H e l l o , ␣ w o r l d ! newline null</span> -<span id="L34" class="LineNr">34 </span> -<span id="L35" class="LineNr">35 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L29" class="LineNr">29 </span> +<span id="L30" class="LineNr">30 </span><span class="Special">Size</span>: <span class="Comment"># size of string</span> +<span id="L31" class="LineNr">31 </span> 0e 00 00 00 <span class="Comment"># 14</span> +<span id="L32" class="LineNr">32 </span><span class="Special">X</span>: <span class="Comment"># string to print</span> +<span id="L33" class="LineNr">33 </span> 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21 0a 00 +<span id="L34" class="LineNr">34 </span><span class="Comment"># H e l l o , ␣ w o r l d ! newline null</span> +<span id="L35" class="LineNr">35 </span> +<span id="L36" class="LineNr">36 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex7.subx.html b/html/subx/examples/ex7.subx.html index 3ffc6a49..c41eccbf 100644 --- a/html/subx/examples/ex7.subx.html +++ b/html/subx/examples/ex7.subx.html @@ -17,6 +17,7 @@ a:hover { text-decoration: underline; } * { font-size: 12pt; font-size: 1em; } .LineNr { color: #444444; } .Delimiter { color: #800080; } +.Special { color: #c00000; } .Comment { color: #9090ff; } .Comment a { color:#0000ee; text-decoration:underline; } .SalientComment { color: #00ffff; } @@ -71,92 +72,93 @@ if ('onhashchange' in window) { <span id="L15" class="LineNr"> 15 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> <span id="L16" class="LineNr"> 16 </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> <span id="L17" class="LineNr"> 17 </span> -<span id="L18" class="LineNr"> 18 </span> <span class="Comment"># syscall(creat, filename)</span> -<span id="L19" class="LineNr"> 19 </span> bb/copy-to-EBX filename/imm32 +<span id="L18" class="LineNr"> 18 </span> <span class="Comment"># syscall(creat, Filename)</span> +<span id="L19" class="LineNr"> 19 </span> bb/copy-to-EBX <span class="Special">Filename</span>/imm32 <span id="L20" class="LineNr"> 20 </span> b9/copy-to-ECX 0x180/imm32/fixed-perms <span id="L21" class="LineNr"> 21 </span> b8/copy-to-EAX 8/imm32/creat <span id="L22" class="LineNr"> 22 </span> cd/syscall 0x80/imm8 <span id="L23" class="LineNr"> 23 </span> -<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># stream = syscall(open, filename, O_WRONLY, 0) # we can't use 'fd' because it looks like a hex byte</span> -<span id="L25" class="LineNr"> 25 </span> bb/copy-to-EBX filename/imm32 +<span id="L24" class="LineNr"> 24 </span> <span class="Comment"># stream = syscall(open, Filename, O_WRONLY, 0) # we can't use 'fd' because it looks like a hex byte</span> +<span id="L25" class="LineNr"> 25 </span> bb/copy-to-EBX <span class="Special">Filename</span>/imm32 <span id="L26" class="LineNr"> 26 </span> b9/copy-to-ECX 1/imm32/wronly <span id="L27" class="LineNr"> 27 </span> ba/copy-to-EDX 0x180/imm32/fixed-perms <span id="L28" class="LineNr"> 28 </span> b8/copy-to-EAX 5/imm32/open <span id="L29" class="LineNr"> 29 </span> cd/syscall 0x80/imm8 <span id="L30" class="LineNr"> 30 </span> <span class="Comment"># save stream</span> -<span id="L31" class="LineNr"> 31 </span> bb/copy-to-EBX stream/imm32 +<span id="L31" class="LineNr"> 31 </span> bb/copy-to-EBX <span class="Special">Stream</span>/imm32 <span id="L32" class="LineNr"> 32 </span> 89/copy 0/mod/indirect 3/rm32/EBX <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"># copy EAX to *EBX</span> <span id="L33" class="LineNr"> 33 </span> -<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># syscall(write, stream, "a", 1)</span> +<span id="L34" class="LineNr"> 34 </span> <span class="Comment"># syscall(write, Stream, "a", 1)</span> <span id="L35" class="LineNr"> 35 </span> <span class="Comment"># load stream</span> -<span id="L36" class="LineNr"> 36 </span> bb/copy-to-EBX stream/imm32 +<span id="L36" class="LineNr"> 36 </span> bb/copy-to-EBX <span class="Special">Stream</span>/imm32 <span id="L37" class="LineNr"> 37 </span> 8b/copy 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EBX to EBX</span> <span id="L38" class="LineNr"> 38 </span> <span class="Comment">#</span> -<span id="L39" class="LineNr"> 39 </span> b9/copy-to-ECX a/imm32 +<span id="L39" class="LineNr"> 39 </span> b9/copy-to-ECX <span class="Special">A</span>/imm32 <span id="L40" class="LineNr"> 40 </span> ba/copy-to-EDX 1/imm32/size <span id="L41" class="LineNr"> 41 </span> b8/copy-to-EAX 4/imm32/write <span id="L42" class="LineNr"> 42 </span> cd/syscall 0x80/imm8 <span id="L43" class="LineNr"> 43 </span> -<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># syscall(close, stream)</span> +<span id="L44" class="LineNr"> 44 </span> <span class="Comment"># syscall(close, Stream)</span> <span id="L45" class="LineNr"> 45 </span> <span class="Comment"># load stream</span> -<span id="L46" class="LineNr"> 46 </span> bb/copy-to-EBX stream/imm32 +<span id="L46" class="LineNr"> 46 </span> bb/copy-to-EBX <span class="Special">Stream</span>/imm32 <span id="L47" class="LineNr"> 47 </span> 8b/copy 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EBX to EBX</span> <span id="L48" class="LineNr"> 48 </span> <span class="Comment">#</span> <span id="L49" class="LineNr"> 49 </span> b8/copy-to-EAX 6/imm32/close <span id="L50" class="LineNr"> 50 </span> cd/syscall 0x80/imm8 <span id="L51" class="LineNr"> 51 </span> -<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># stream = syscall(open, filename, O_RDONLY, 0)</span> -<span id="L53" class="LineNr"> 53 </span> bb/copy-to-EBX filename/imm32 +<span id="L52" class="LineNr"> 52 </span> <span class="Comment"># stream = syscall(open, Filename, O_RDONLY, 0)</span> +<span id="L53" class="LineNr"> 53 </span> bb/copy-to-EBX <span class="Special">Filename</span>/imm32 <span id="L54" class="LineNr"> 54 </span> b9/copy-to-ECX 0/imm32/rdonly <span id="L55" class="LineNr"> 55 </span> ba/copy-to-EDX 0x180/imm32/fixed-perms <span id="L56" class="LineNr"> 56 </span> b8/copy-to-EAX 5/imm32/open <span id="L57" class="LineNr"> 57 </span> cd/syscall 0x80/imm8 -<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># save stream</span> -<span id="L59" class="LineNr"> 59 </span> bb/copy-to-EBX stream/imm32 +<span id="L58" class="LineNr"> 58 </span> <span class="Comment"># save Stream</span> +<span id="L59" class="LineNr"> 59 </span> bb/copy-to-EBX <span class="Special">Stream</span>/imm32 <span id="L60" class="LineNr"> 60 </span> 89/copy 0/mod/indirect 3/rm32/EBX <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"># copy EAX to *EBX</span> <span id="L61" class="LineNr"> 61 </span> -<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># syscall(read, stream, b, 1)</span> +<span id="L62" class="LineNr"> 62 </span> <span class="Comment"># syscall(read, Stream, B, 1)</span> <span id="L63" class="LineNr"> 63 </span> <span class="Comment"># load stream</span> -<span id="L64" class="LineNr"> 64 </span> bb/copy-to-EBX stream/imm32 +<span id="L64" class="LineNr"> 64 </span> bb/copy-to-EBX <span class="Special">Stream</span>/imm32 <span id="L65" class="LineNr"> 65 </span> 8b/copy 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EBX to EBX</span> <span id="L66" class="LineNr"> 66 </span> <span class="Comment">#</span> -<span id="L67" class="LineNr"> 67 </span> b9/copy-to-ECX b/imm32 +<span id="L67" class="LineNr"> 67 </span> b9/copy-to-ECX <span class="Special">B</span>/imm32 <span id="L68" class="LineNr"> 68 </span> ba/copy-to-EDX 1/imm32/size <span id="L69" class="LineNr"> 69 </span> b8/copy-to-EAX 3/imm32/read <span id="L70" class="LineNr"> 70 </span> cd/syscall 0x80/imm8 <span id="L71" class="LineNr"> 71 </span> -<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># syscall(close, stream)</span> +<span id="L72" class="LineNr"> 72 </span> <span class="Comment"># syscall(close, Stream)</span> <span id="L73" class="LineNr"> 73 </span> <span class="Comment"># load stream</span> -<span id="L74" class="LineNr"> 74 </span> bb/copy-to-EBX stream/imm32 +<span id="L74" class="LineNr"> 74 </span> bb/copy-to-EBX <span class="Special">Stream</span>/imm32 <span id="L75" class="LineNr"> 75 </span> 8b/copy 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EBX to EBX</span> <span id="L76" class="LineNr"> 76 </span> <span class="Comment">#</span> <span id="L77" class="LineNr"> 77 </span> b8/copy-to-EAX 6/imm32/close <span id="L78" class="LineNr"> 78 </span> cd/syscall 0x80/imm8 <span id="L79" class="LineNr"> 79 </span> <span id="L80" class="LineNr"> 80 </span> <span class="Comment"># syscall(unlink, filename)</span> -<span id="L81" class="LineNr"> 81 </span> bb/copy-to-EBX filename/imm32 +<span id="L81" class="LineNr"> 81 </span> bb/copy-to-EBX <span class="Special">Filename</span>/imm32 <span id="L82" class="LineNr"> 82 </span> b8/copy-to-EAX 0xa/imm32/unlink <span id="L83" class="LineNr"> 83 </span> cd/syscall 0x80/imm8 <span id="L84" class="LineNr"> 84 </span> <span id="L85" class="LineNr"> 85 </span> <span class="Comment"># syscall(exit, b)</span> <span id="L86" class="LineNr"> 86 </span> <span class="Comment"># load b</span> -<span id="L87" class="LineNr"> 87 </span> bb/copy-to-EBX b/imm32 +<span id="L87" class="LineNr"> 87 </span> bb/copy-to-EBX <span class="Special">B</span>/imm32 <span id="L88" class="LineNr"> 88 </span> 8b/copy 0/mod/indirect 3/rm32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 3/r32/EBX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *EBX to EBX</span> <span id="L89" class="LineNr"> 89 </span> <span class="Comment">#</span> <span id="L90" class="LineNr"> 90 </span> b8/copy-to-EAX 1/imm32/exit <span id="L91" class="LineNr"> 91 </span> cd/syscall 0x80/imm8 <span id="L92" class="LineNr"> 92 </span> <span id="L93" class="LineNr"> 93 </span>== data -<span id="L94" class="LineNr"> 94 </span>stream: -<span id="L95" class="LineNr"> 95 </span> 00 00 00 00 -<span id="L96" class="LineNr"> 96 </span>a: -<span id="L97" class="LineNr"> 97 </span> 61 00 00 00 -<span id="L98" class="LineNr"> 98 </span>b: -<span id="L99" class="LineNr"> 99 </span> 00 00 00 00 -<span id="L100" class="LineNr">100 </span>filename: -<span id="L101" class="LineNr">101 </span> 2e 66 6f 6f 00 00 00 00 -<span id="L102" class="LineNr">102 </span> -<span id="L103" class="LineNr">103 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L94" class="LineNr"> 94 </span> +<span id="L95" class="LineNr"> 95 </span><span class="Special">Stream</span>: +<span id="L96" class="LineNr"> 96 </span> 00 00 00 00 +<span id="L97" class="LineNr"> 97 </span><span class="Special">A</span>: +<span id="L98" class="LineNr"> 98 </span> 61 00 00 00 +<span id="L99" class="LineNr"> 99 </span><span class="Special">B</span>: +<span id="L100" class="LineNr">100 </span> 00 00 00 00 +<span id="L101" class="LineNr">101 </span><span class="Special">Filename</span>: +<span id="L102" class="LineNr">102 </span> 2e 66 6f 6f 00 00 00 00 +<span id="L103" class="LineNr">103 </span> +<span id="L104" class="LineNr">104 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex8.subx.html b/html/subx/examples/ex8.subx.html index f0770c2f..f1868a61 100644 --- a/html/subx/examples/ex8.subx.html +++ b/html/subx/examples/ex8.subx.html @@ -74,43 +74,44 @@ if ('onhashchange' in window) { <span id="L18" class="LineNr">18 </span><span class="Comment"># instruction effective address operand displacement immediate</span> <span id="L19" class="LineNr">19 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> <span id="L20" class="LineNr">20 </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> -<span id="L21" class="LineNr">21 </span> <span class="Comment"># prolog</span> -<span id="L22" class="LineNr">22 </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="L23" class="LineNr">23 </span> <span class="Comment"># call ascii-length(argv[1])</span> -<span id="L24" class="LineNr">24 </span> <span class="Comment"># push args</span> -<span id="L25" class="LineNr">25 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> -<span id="L26" class="LineNr">26 </span> <span class="Comment"># call</span> -<span id="L27" class="LineNr">27 </span> e8/call ascii-length/disp32 -<span id="L28" class="LineNr">28 </span> <span class="Comment"># discard args</span> -<span id="L29" class="LineNr">29 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> -<span id="L30" class="LineNr">30 </span> -<span id="L31" class="LineNr">31 </span> <span class="Comment"># exit(EAX)</span> -<span id="L32" class="LineNr">32 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> -<span id="L33" class="LineNr">33 </span> b8/copy-to-EAX 1/imm32/exit -<span id="L34" class="LineNr">34 </span> cd/syscall 0x80/imm8 -<span id="L35" class="LineNr">35 </span> -<span id="L36" class="LineNr">36 </span>ascii-length: <span class="Comment"># (s)</span> -<span id="L37" class="LineNr">37 </span> <span class="Comment"># initialize s (EDX)</span> -<span id="L38" class="LineNr">38 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+4) to EDX</span> -<span id="L39" class="LineNr">39 </span> <span class="Comment"># var result = 0 (EAX)</span> -<span id="L40" class="LineNr">40 </span> b8/copy-to-EAX 0/imm32 -<span id="L41" class="LineNr">41 </span>$ascii-length-loop: -<span id="L42" class="LineNr">42 </span> <span class="Comment"># var c = *s (ECX)</span> -<span id="L43" class="LineNr">43 </span> 8a/copy 0/mod/* 2/rm32/EDX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *EDX to lower byte of ECX</span> -<span id="L44" class="LineNr">44 </span> <span class="Comment"># if c == '\0' break</span> -<span id="L45" class="LineNr">45 </span> 81 7/subop/compare 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare ECX</span> -<span id="L46" class="LineNr">46 </span> 74/jump-if-equal $ascii-length-ret/disp8 -<span id="L47" class="LineNr">47 </span> <span class="Comment"># ++s</span> -<span id="L48" class="LineNr">48 </span> 81 0/subop/add 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"># add to EDX</span> -<span id="L49" class="LineNr">49 </span> <span class="Comment"># ++result</span> -<span id="L50" class="LineNr">50 </span> 40/inc-EAX -<span id="L51" class="LineNr">51 </span> <span class="Comment"># loop</span> -<span id="L52" class="LineNr">52 </span> eb/jump $ascii-length-loop/disp8 -<span id="L53" class="LineNr">53 </span>$ascii-length-ret: -<span id="L54" class="LineNr">54 </span> <span class="Comment"># return (result in EAX)</span> -<span id="L55" class="LineNr">55 </span> c3/return -<span id="L56" class="LineNr">56 </span> -<span id="L57" class="LineNr">57 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L21" class="LineNr">21 </span> +<span id="L22" class="LineNr">22 </span> <span class="Comment"># prolog</span> +<span id="L23" class="LineNr">23 </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="L24" class="LineNr">24 </span> <span class="Comment"># call ascii-length(argv[1])</span> +<span id="L25" class="LineNr">25 </span> <span class="Comment"># push args</span> +<span id="L26" class="LineNr">26 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L27" class="LineNr">27 </span> <span class="Comment"># call</span> +<span id="L28" class="LineNr">28 </span> e8/call ascii-length/disp32 +<span id="L29" class="LineNr">29 </span> <span class="Comment"># discard args</span> +<span id="L30" class="LineNr">30 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 4/imm32 <span class="Comment"># add to ESP</span> +<span id="L31" class="LineNr">31 </span> +<span id="L32" class="LineNr">32 </span> <span class="Comment"># exit(EAX)</span> +<span id="L33" class="LineNr">33 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> +<span id="L34" class="LineNr">34 </span> b8/copy-to-EAX 1/imm32/exit +<span id="L35" class="LineNr">35 </span> cd/syscall 0x80/imm8 +<span id="L36" class="LineNr">36 </span> +<span id="L37" class="LineNr">37 </span>ascii-length: <span class="Comment"># (s)</span> +<span id="L38" class="LineNr">38 </span> <span class="Comment"># initialize s (EDX)</span> +<span id="L39" class="LineNr">39 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none <span class="Delimiter"> . </span> 2/r32/EDX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+4) to EDX</span> +<span id="L40" class="LineNr">40 </span> <span class="Comment"># var result = 0 (EAX)</span> +<span id="L41" class="LineNr">41 </span> b8/copy-to-EAX 0/imm32 +<span id="L42" class="LineNr">42 </span>$ascii-length-loop: +<span id="L43" class="LineNr">43 </span> <span class="Comment"># var c = *s (ECX)</span> +<span id="L44" class="LineNr">44 </span> 8a/copy 0/mod/* 2/rm32/EDX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy byte at *EDX to lower byte of ECX</span> +<span id="L45" class="LineNr">45 </span> <span class="Comment"># if c == '\0' break</span> +<span id="L46" class="LineNr">46 </span> 81 7/subop/compare 3/mod/direct 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0/imm32 <span class="Comment"># compare ECX</span> +<span id="L47" class="LineNr">47 </span> 74/jump-if-equal $ascii-length-ret/disp8 +<span id="L48" class="LineNr">48 </span> <span class="Comment"># ++s</span> +<span id="L49" class="LineNr">49 </span> 81 0/subop/add 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"># add to EDX</span> +<span id="L50" class="LineNr">50 </span> <span class="Comment"># ++result</span> +<span id="L51" class="LineNr">51 </span> 40/inc-EAX +<span id="L52" class="LineNr">52 </span> <span class="Comment"># loop</span> +<span id="L53" class="LineNr">53 </span> eb/jump $ascii-length-loop/disp8 +<span id="L54" class="LineNr">54 </span>$ascii-length-ret: +<span id="L55" class="LineNr">55 </span> <span class="Comment"># return (result in EAX)</span> +<span id="L56" class="LineNr">56 </span> c3/return +<span id="L57" class="LineNr">57 </span> +<span id="L58" class="LineNr">58 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> diff --git a/html/subx/examples/ex9.subx.html b/html/subx/examples/ex9.subx.html index 32f81d1c..f949f02a 100644 --- a/html/subx/examples/ex9.subx.html +++ b/html/subx/examples/ex9.subx.html @@ -76,34 +76,35 @@ if ('onhashchange' in window) { <span id="L20" class="LineNr">20 </span><span class="Comment"># instruction effective address operand displacement immediate</span> <span id="L21" class="LineNr">21 </span><span class="Comment"># op subop mod rm32 base index scale r32</span> <span id="L22" class="LineNr">22 </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> -<span id="L23" class="LineNr">23 </span> <span class="Comment"># prolog</span> -<span id="L24" class="LineNr">24 </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="L25" class="LineNr">25 </span> <span class="Comment"># call ascii-difference(argv[1], argv[2])</span> -<span id="L26" class="LineNr">26 </span> <span class="Comment"># push argv[2]</span> -<span id="L27" class="LineNr">27 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> -<span id="L28" class="LineNr">28 </span> <span class="Comment"># push argv[1]</span> -<span id="L29" class="LineNr">29 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> -<span id="L30" class="LineNr">30 </span> <span class="Comment"># call</span> -<span id="L31" class="LineNr">31 </span> e8/call ascii-difference/disp32 -<span id="L32" class="LineNr">32 </span> <span class="Comment"># discard args</span> -<span id="L33" class="LineNr">33 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> -<span id="L34" class="LineNr">34 </span> <span class="Comment"># exit(EAX)</span> -<span id="L35" class="LineNr">35 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> -<span id="L36" class="LineNr">36 </span> b8/copy-to-EAX 1/imm32/exit -<span id="L37" class="LineNr">37 </span> cd/syscall 0x80/imm8 -<span id="L38" class="LineNr">38 </span> -<span id="L39" class="LineNr">39 </span>ascii-difference: <span class="Comment"># (s1, s2) : null-terminated ascii strings</span> -<span id="L40" class="LineNr">40 </span> <span class="Comment"># a = first letter of s1 (ECX)</span> -<span id="L41" class="LineNr">41 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+4) to EAX</span> -<span id="L42" class="LineNr">42 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <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"># copy *EAX to EAX</span> -<span id="L43" class="LineNr">43 </span> <span class="Comment"># b = first letter of s2 (EDX)</span> -<span id="L44" class="LineNr">44 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX 8/disp8 <span class="Comment"># copy *(ESP+8) to ECX</span> -<span id="L45" class="LineNr">45 </span> 8b/copy 0/mod/indirect 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *ECX to ECX</span> -<span id="L46" class="LineNr">46 </span> <span class="Comment"># a-b</span> -<span id="L47" class="LineNr">47 </span> 29/subtract 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># subtract ECX from EAX</span> -<span id="L48" class="LineNr">48 </span> c3/return -<span id="L49" class="LineNr">49 </span> -<span id="L50" class="LineNr">50 </span><span class="Comment"># vim:nowrap:textwidth=0</span> +<span id="L23" class="LineNr">23 </span> +<span id="L24" class="LineNr">24 </span> <span class="Comment"># prolog</span> +<span id="L25" class="LineNr">25 </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="L26" class="LineNr">26 </span> <span class="Comment"># call ascii-difference(argv[1], argv[2])</span> +<span id="L27" class="LineNr">27 </span> <span class="Comment"># push argv[2]</span> +<span id="L28" class="LineNr">28 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0xc/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+12)</span> +<span id="L29" class="LineNr">29 </span> <span class="Comment"># push argv[1]</span> +<span id="L30" class="LineNr">30 </span> ff 6/subop/push 1/mod/*+disp8 4/rm32/sib 5/base/EBP 4/index/none <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 0x8/disp8 <span class="Delimiter"> . </span> <span class="Comment"># push *(EBP+8)</span> +<span id="L31" class="LineNr">31 </span> <span class="Comment"># call</span> +<span id="L32" class="LineNr">32 </span> e8/call ascii-difference/disp32 +<span id="L33" class="LineNr">33 </span> <span class="Comment"># discard args</span> +<span id="L34" class="LineNr">34 </span> 81 0/subop/add 3/mod/direct 4/rm32/ESP <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 8/imm32 <span class="Comment"># add to ESP</span> +<span id="L35" class="LineNr">35 </span> <span class="Comment"># exit(EAX)</span> +<span id="L36" class="LineNr">36 </span> 89/copy 3/mod/direct 3/rm32/EBX <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"># copy EAX to EBX</span> +<span id="L37" class="LineNr">37 </span> b8/copy-to-EAX 1/imm32/exit +<span id="L38" class="LineNr">38 </span> cd/syscall 0x80/imm8 +<span id="L39" class="LineNr">39 </span> +<span id="L40" class="LineNr">40 </span>ascii-difference: <span class="Comment"># (s1, s2) : null-terminated ascii strings</span> +<span id="L41" class="LineNr">41 </span> <span class="Comment"># a = first letter of s1 (ECX)</span> +<span id="L42" class="LineNr">42 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 0/r32/EAX 4/disp8 <span class="Delimiter"> . </span> <span class="Comment"># copy *(ESP+4) to EAX</span> +<span id="L43" class="LineNr">43 </span> 8b/copy 0/mod/indirect 0/rm32/EAX <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"># copy *EAX to EAX</span> +<span id="L44" class="LineNr">44 </span> <span class="Comment"># b = first letter of s2 (EDX)</span> +<span id="L45" class="LineNr">45 </span> 8b/copy 1/mod/*+disp8 4/rm32/sib 4/base/ESP 4/index/none 1/r32/ECX 8/disp8 <span class="Comment"># copy *(ESP+8) to ECX</span> +<span id="L46" class="LineNr">46 </span> 8b/copy 0/mod/indirect 1/rm32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># copy *ECX to ECX</span> +<span id="L47" class="LineNr">47 </span> <span class="Comment"># a-b</span> +<span id="L48" class="LineNr">48 </span> 29/subtract 3/mod/direct 0/rm32/EAX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> 1/r32/ECX <span class="Delimiter"> . </span> <span class="Delimiter"> . </span> <span class="Comment"># subtract ECX from EAX</span> +<span id="L49" class="LineNr">49 </span> c3/return +<span id="L50" class="LineNr">50 </span> +<span id="L51" class="LineNr">51 </span><span class="Comment"># vim:nowrap:textwidth=0</span> </pre> </body> </html> |