ARM程序集乘法错误

时间:2015-05-13 06:23:05

标签: assembly arm multiplication

我在尝试将两个数字相乘并将它们存储在ARM程序集的内存位置时遇到问题。我正在模拟ARM Cortex M0 Plus。当我评论乘法时,一切似乎都工作正常。我不确定我是否需要使用MUL或MULS,但无论哪种方式,我都不明白为什么它不起作用。我试图解决的等式是:

A = 2
B = 4
C = 6
D = A+(C*B)-2

当我取消对乘法的注释时,我得到的错误是“错误:无法加载文件。调试器已中止!” *错误是由错误顺序的寄存器引起的。首先添加位置更容易,然后用于乘法的寄存器

代码:

    AREA |.text|, CODE, READONLY, ALIGN=2
    EXPORT __main

    ;equate x20000000 with some x
A   EQU 0x20000000
B   EQU 0x20000004
C   EQU 0x20000008
D   EQU 0x2000000C

__main
    ;A = 2
    MOVS R0, #2
    ;move pointer to =0x20000000
    LDR R7, =A
    ;Store R0 in memory cell of address R7
    STR R0, [R7]

    ;B = 4
    MOVS R0, #4
    LDR R7, =B
    STR R0, [R7]

    ;C = 6
    MOVS R0, #6
    LDR R7, =C
    STR R0, [R7]

    ;A+(C*B)-2
    LDR R7, =C
    LDR R0, [R7]
    LDR R7, =B
    LDR R1, [R7]
;   MUL R0, R1 ;C*B

;EDIT FIXED above line should be:
    MULS R0, R1, R0
;   This stores in location R0, multiplication R1, R0

    LDR R7, =A
    LDR R1, [R7]
    ADDS R0, R1 ;A+(C*B)
    SUBS R0, #2 ;(A+(C*B))-2

    ;D = R0
    LDR R7, =D ;storing result in D
    STR R0, [R7]

done
    B done
    END

0 个答案:

没有答案