How can i make 10000,1000,100 from 10 the easiest way

牧云@^-^@ 提交于 2019-11-29 17:41:31

To calculate 10000*X+1000*Y+100*Z+10*V+1*C use the transformation 10*(10*(10*(10*X+Y)+Z)+V)+C. This way you only need to multiply by 10 in every iteration. As I have written in my comment, you can avoid a mul by using 10=8+2. As such your code may look something like this:

    mov cx, 5               ; number of digits
    mov di, offset number   ; pointer to digits
    xor ax, ax              ; zero result
next:
    mov dx, ax              ; save a copy of current result
    shl ax, 3               ; multiply by 8
    add ax, dx              ; 9
    add ax, dx              ; 10
    movzx dx, byte ptr [di] ; fetch digit
    sub dx, '0'             ; convert from ascii
    add ax, dx              ; add to sum
    inc di                  ; next digit
    loop next
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!