Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Just giving it a try, though I'm not sure, and I can't quickly test this.</p> <p>But instead of using two loops I'd recommend using one for the whole bunch of numbers.</p> <p>Furthermore I have the feeling that the problem has to do with the <code>DAA</code> instruction, which I'm not used to, since it is not supported in 64 bit mode.</p> <p>Anyway, here's what I'd do:</p> <pre><code> mov cx,20 mov al,1 mov bl,10 ; divisor mov bp,offset Result ; no need to load this in the loop!!! L1: mov dx,ax ; save to register, not to stack cmp ax,09d ja L2 ; number has two digits add al,30h ; ASCII addend ; insert your output code here jmp L3 ; jump over the two digit code L2: xor ah,ah div bl ; divides AX by ten (no rotate or shift needed) ; quotient in AL, remainder in AH (correct order for little endian) add ax,3030h ; insert your output code here (note that the buffer/string address is loaded to BP) L3: mov ax,dx inc ax loop L1 ; done </code></pre> <p>If you wouldn't mind if one-digit numbers had a leading zero, it'd be even easier.</p> <p>The <code>div</code> instruction is probably more expensive than <code>daa</code> plus <code>ror</code> plus <code>shr</code>, but your quad-rotate/shift will be even worse :-/</p> <p>(As I said, I could not try it... leaving this open to you... if it doesn't work, just ask back.)</p> <p>&mdash;</p> <p>[update:</p> <p>Another approach, especially to spare the <code>div</code> in this trivial case of digit separation, would be to add 6 to numbers greater nine (i. e. 10d = 0ah --(+6)--> 16d = 10h; this is what <code>daa</code> also does), then you can get along with the rotate/shift combination you used before.</p> <p>Even better were to add 246, then to <code>AX</code>, after which you can simply use <code>ror ax,8</code> (or <code>rol</code> &mdash; doesn't matter in this case), i. e. 10d = 0ah --(+246)--> 256d = 100h, as well 15d = 0fh --(+246)--> 261 = 105h. Rotate it to be 0001h or 0501h respectively, add 3030h, and you're done.</p> <p>/update]</p> <p>[update level="2"</p> <p>What the fun... I actually intended to write it in the first level update, but forgot it somehow: instead of <code>rol</code>ling by 8, or &mdash; if your TASM really doesn't support <code>rol</code>ling by immediate &mdash; eight times rolling by one, you can of course also make use of the <code>xchg</code> instruction, which swaps values between registers, in this case</p> <pre><code> xchg al,ah </code></pre> <p>would do the job of swapping the contents of those two registers.</p> <p>There's also a <code>bswap</code> instruction for reversing the byte order within a register, but it's obviously only available for registers of 32+ bits width.</p> <p>/update]</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. 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.
 

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