Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>It's not the <code>push cs</code> that ensures this, it's the <code>push cs; pop ds;</code> combination that does.</p> <p>The first instruction copies the current value of <code>cs</code> onto the stack, and the second pulls that value off the stack and puts it into the <code>ds</code> register.</p> <hr> <p>In response to your request for more information, let's start with the following stack and registers:</p> <pre><code>stack=[1,2,3], cs=7, ds=6 </code></pre> <p>After <code>push cs</code>, which pushes the value of the <code>cs</code> register onto the stack:</p> <pre><code>stack=[1,2,3,7], cs=7, ds=6 </code></pre> <p>After <code>pop ds</code>, which pops a value off the stack and put it into the <code>ds</code> register:</p> <pre><code>stack=[1,2,3], cs=7, ds=7 </code></pre> <p>And that's basically it.</p> <hr> <p>I can't recall of the top of my head whether it was possible to transfer between segment registers with a <code>mov</code> instruction (I don't think it was, but I may be wrong, and this would necessitate the push/pop sequence). This <a href="http://www.penguin.cz/~literakl/intel/m.html#MOV" rel="nofollow">link</a> would seem to confirm that: there is no <code>mov</code> option with a segment register as both source <em>and</em> destination.</p> <p>But even if it were, assembler coders often chose more suitable instructions, either for speed or compact code (or both), things like using <code>xor ax, ax</code> instead of <code>mov ax, 0</code> for example.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload