Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This has gotta be the most frequently asked question of all time. If you can't find an example, upgrade your search skills.</p> <p>From what you've got... you're going to need a subfunction in <code>al</code>(edit: <code>ah</code>!) for that <code>int 21h</code>. You check for a valid decimal digit correctly. The <code>shl</code> isn't going to help you with a decimal number (but possibly useful for hex).</p> <p>To convert from text to a number, which is what your code appears to be doing, zero out a register for "result so far". Each time you find a valid decimal digit (working left to right), subtract '0' (30h or 48 decimal, but '0' is clearer to read), multiply "result so far" by ten, and add the new digit. Until done...</p> <p>To convert from a number to text so you can print it, which your question actually asks, divide by ten repeatedly - pay attention to what <code>div</code> divides by what! The remainders (in <code>ah</code>, <code>dx</code>, or <code>edx</code>, depending) are the decimal digits. Add '0' to each. You'll get the digits from right-to-left, and you want to print 'em left-to-right - there are several ways to deal with this...</p> <p>Find an example, or fire up a debugger and work it out. The most likely reason your program will crash is that you haven't paid attention to what <code>div</code> divides by what! Ask if you have a specific problem...</p> <p>Edit: Sigh... <code></p> <pre><code>mov ax, the_number xor cx, cx ; digit counter mov bx, 10 pushem: xor dx, dx ; important! div bx ; quotient in ax, remainder in dx add dl, '0' ; convert to character push dx ; save 'em to get back in right order inc cx ; count 'em test ax, ax ; done? jnz pushem ; no, do more popem: pop ax ; we're only interested in al int 29h ; print al loop popem ; until done </code></pre> <p></code> That's about the simplest way I know (not the "best" perhaps). Your current set of numbers will fit in a byte, but it's just as easy to do a full word.</p>
    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. 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