本文介绍了我怎样才能从10个最简单的方法中赚取10000,1000,100的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找上述问题的解决方案.我需要生成100,1000和10000(十进制数).因为整个练习都是为了计算:

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:

我知道我可以通过mul命令来完成,但是在那种情况下我必须在堆栈上做很多工作.

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.

带有二进制数

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

Preferebla是一种恶劣的环境.感谢您的帮助

Preferebla is masm enviroment.Thank you for your help

Update1:我不想使用mul或imul(少于32位数字)我有一个数字,例如string(db)可以说24575,我有伪代码,但是还没写完

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$"

推荐答案

要计算10000*X+1000*Y+100*Z+10*V+1*C,请使用转换10*(10*(10*(10*X+Y)+Z)+V)+C.这样,您每次迭代只需乘以10.正如我在评论中所写,可以通过使用10=8+2来避免使用mul.因此,您的代码可能看起来像这样:

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

这篇关于我怎样才能从10个最简单的方法中赚取10000,1000,100的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 09:02