浮动结果(作业)

时间:2013-02-03 14:05:42

标签: assembly arm inline-assembly

我目前正忙着做作业,并请求一些帮助。我们的任务是实现x ^ 4/4!在手臂组装。我已成功计算出x ^ 4和4!的正确值,但我仍然坚持如何计算显然有浮点的除法。我已经实现了一个简单的除法算法,但是根据我的理解,这只适用于整数除法,不是吗?

 CMP             R2, #0
 BEQ divide_end


 MOV      R0,#0     ;clear R0 to accumulate result
 MOV      R3,#1     ;set bit 0 in R3, which will be
                    ;shifted left then right
.start
 CMP      R2,R1
 MOVLS    R2,R2,LSL#1
 MOVLS    R3,R3,LSL#1
 BLS      start
 ;shift R2 left until it is about to
 ;be bigger than R1
 ;shift R3 left in parallel in order
 ;to flag how far we have to go

.next
 CMP       R1,R2      ;carry set if R1>R2
 SUBCS     R1,R1,R2   ;subtract R2 from R1 if this would
                      ;give a positive answer
 ADDCS     R0,R0,R3   ;and add the current bit in R3 to
                      ;the accumulating answer in R0

 MOVS      R3,R3,LSR#1     ;Shift R3 right into carry flag
 MOVCC     R2,R2,LSR#1     ;and if bit 0 of R3 was zero, also
                           ;shift R2 right
 BCC       next            ;If carry not clear, R3 has shifted
                           ;back to where it started, and we
                           ;can end

.divide_end

也许我在这里真的很蠢,但任何帮助都会受到赞赏 非常感谢

1 个答案:

答案 0 :(得分:0)

我只是愚蠢。我们被允许使用FPU指令。所以我可以使用VDIV!