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

一笑奈何 提交于 2019-12-29 09:41:11

问题


i am looking for a solution for the question abowe. I need to generate 100,1000 and 10000(decimal numbers). Because the whole exercise is to caluclate:

10000*X+1000*Y+100*Y+10*V+1*C

I know i can do it by the mul command,but in that case i have to work a lot with stack.

I was thinking some kind of Shifting, but don't know how to do it with decimal numbers.

With binary numbers

mov al,2h;mov al,10b;
shl al,1

Preferebla is masm enviroment.Thank you for your help

Update1: I dont want to use mul nor imul(less then 32 bit number) I have a number as string(db) lets say 24575,i have hier the pseudo code,not finished

    mov cx,5
    Calc:
mov di,offset first
add di,2;so we are on the adress of "2"


;ASCI number is 2 and i want to get 20000
    mov al,10d

    ;than ASCI number is 4 and i want to get 4000

    ;than ASCI number is 5 and i want to get 500

    ;than ASCI number is 7 and i want to get 70

    ;than ASCI number is 5 and i want to get 5


inc di
    loop Calc

first:db"A$"
number :db"24575$"

回答1:


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


来源:https://stackoverflow.com/questions/26337518/how-can-i-make-10000-1000-100-from-10-the-easiest-way

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!