如何在ARM Assembly中实现除法算法?

时间:2016-12-04 07:35:40

标签: algorithm assembly arm division

我正在尝试在ARM程序集中实现以下算法,但是当我在ARMSim 1.9.1中运行我的代码时,它打印出的商和余数完全不变(在这种情况下为0和5)。有人能告诉我我做错了什么吗?我想这可能是我试图设置寄存器最右边的位。

s

这是我的代码:

Given: Two positive integers: a Divisor X, and a Dividend Y
Use three General Purpose Registers (R, Q, X)
where R stores the Remainder, Q stores the Quotient, and X stores the Divisor. 
Steps:
    1. Copy Y into the Remainder register (R)
       Register Q will be initialized as 0 
    2. update: R =  R - X
    3. If R >= 0 then
        Shift the Quotient Register (Q) to the left (1 bit)
        and set the new rightmost bit to 1
       Else
        Restore the original value by of R:  R = R + X
            Also, Shift the Quotient Register (Q) to the left (1 bit)
            and set the new least significant bit to 0
    4. Shift the Divisor Register (X) to the right (1 bit)
    5. Repeat 31 more times

0 个答案:

没有答案