Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You basically want to divide by 10, print the remainder (one digit), and then repeat with the quotient.</p> <pre><code> ; assume number is in eax mov ecx, 10 loophere: mov edx, 0 div ecx ; now eax &lt;-- eax/10 ; edx &lt;-- eax % 10 ; print edx ; this is one digit, which we have to convert to ASCII ; the print routine uses edx and eax, so let's push eax ; onto the stack. we clear edx at the beginning of the ; loop anyway, so we don't care if we much around with it push eax ; convert dl to ascii add dl, '0' mov ah,2 ; 2 is the function number of output char in the DOS Services. int 21h ; calls DOS Services ; now restore eax pop eax ; if eax is zero, we can quit cmp eax, 0 jnz loophere </code></pre> <hr> <p>As a side note, you have a bug in your code right here:</p> <pre><code>mov ax, 1 ;put 1 into ax add ax, 2 ; add 2 to ax current value mov ah,2 ; 2 is the function number of output char in the DOS Services. mov dl, ax ; DL takes the value. </code></pre> <p>You put <code>2</code> in <code>ah</code>, and then you put <code>ax</code> in <code>dl</code>. You're basically junking <code>ax</code> before printing it.</p> <p>You also have a size mismatch since <code>dl</code> is 8 bits wide and <code>ax</code> is 16 bits wide.</p> <p>What you should do is flip the last two lines and fix the size mismatch:</p> <pre><code>mov ax, 1 ;put 1 into ax add ax, 2 ; add 2 to ax current value mov dl, al ; DL takes the value. mov ah,2 ; 2 is the function number of output char in the DOS Services. </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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