编写ARM汇编程序

问题描述 投票:-3回答:1

用下面给出的指令编写一个ARM汇编程序

  1. 声明一个变量'A',它保存9950948。将值加载到寄存器R3中的变量'A'中。

    将R3中存储的值的最后10位复制到R5中,将11到20中的位复制到R6中,并将R7中的21 t0 32位复制并按R6,R5,R7的顺序存储在堆栈中。 (15分)

*我的当前解决方案。编译时,与LSL的行被跳过。怎么解决

        LDR R0,= A
        LDR R3, [R0]

        MOV R1, 0x000003ff  ; mask for last 10 bits - 1111111111
        AND R5, R3, R1      ; Place BitWise AND into R5

        LSL R2, R2, #10



A DCD 0x97D6E4  ; 9950948
;--------------------------------------
stop   B  stop
       END
assembly arm bit-manipulation bitwise-operators
1个回答
0
投票

这是我的解决方法。

        LDR R0,= A
        LDR R3, [R0]

        MOV R1, 0x000003ff  ; mask for last 10 bits - 1111111111
        AND R5, R3, R1      ; Place BitWise AND of R3 & R1 into R5

        LSL R2, R1, #10     ; Shift left R1 ten times to capture 11th - 20th bit
        AND R6, R3, R2      ; Place BitWise AND of R3 & R2 into R6

        LSL R4, R2, #10     ; Further Shift R2 left 12 times to capture 21st - 32nd bit
        AND R7, R3, R4      ; Place BitWise AND of R3 & R4 into R7

        LDR R8,=0x20000014
        MOV SP, R8

        STMIA SP!, {R6, R5, R7}



A DCD 0x97D6E4  ; 9950948 - student ID excluding 00's
;--------------------------------------
stop   B  stop
       END
© www.soinside.com 2019 - 2024. All rights reserved.