【ARM】ARM汇编程序设计(二)

00. 目录

文章目录

    • 00. 目录
    • 01. mla指令
    • 02. umull指令
    • 03. umlal指令
    • 04. smull指令
    • 05. smlal指令
    • 06. adc指令
    • 07. sbc指令
    • 08. mrs指令
    • 09. msr指令
    • 10. 综合应用一
    • 11. 综合应用二
    • 12. 综合应用三
    • 13. 综合应用四
    • 14. 综合应用五
    • 15. 综合应用六
    • 16. 综合应用七
    • 17. 综合应用八
    • 18. 综合应用九
    • 19. 综合应用十
    • 20. 附录

01. mla指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r1, #10
    mov r2, #20
    mov r3, #30

    @r1 = r1 * r2 + r3
    mla r1, r1, r2, r3

    bl printf

    
    mov r0, #0
    pop {pc}

02. umull指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r3, #3
    mov r4, #5

    umull r1, r2, r3, r4
    
    bl printf

    
    mov r0, #0
    pop {pc}

03. umlal指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r1, #1
    mov r2, #0
    mov r3, #3
    mov r4, #5

    umlal r1, r2, r3, r4
    
    bl printf

    
    mov r0, #0
    pop {pc}

04. smull指令

    .section .rodata
    .align 2
.LC0:
    .string "val = %d %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r1, #1
    mov r2, #0
    mov r3, #3
    mov r4, #5

    smull r1, r2, r3, r4
    
    bl printf

    
    mov r0, #0
    pop {pc}

05. smlal指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r1, #1
    mov r2, #0
    mov r3, #3
    mov r4, #5

    smlal r1, r2, r3, r4
    
    bl printf

    
    mov r0, #0
    pop {pc}

06. adc指令

程序示例:

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r1, #2
    mvn r2, #0

    mov r3, #10
    mov r4, #20

	@会设置C位
    add r1, r1, r2

    adc r1, r3, r4
    bl printf

    
    mov r0, #0
    pop {pc}

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0

    mov r3, #10
    mov r4, #20

    adc r1, r3, r4
    bl printf

    
    mov r0, #0
    pop {pc}

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0


    mov r1, #0
    msr cpsr, r1

    mov r3, #10
    mov r4, #20

    adc r1, r3, r4
    bl printf

    
    mov r0, #0
    pop {pc}

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC0


    mov r1, #0
    msr cpsr, r1

    mov r1, #-1
    mov r2, #3
    adds r1, r1, r2

    mov r3, #10
    mov r4, #20

    adc r1, r3, r4
    bl printf

    
    mov r0, #0
    pop {pc}

07. sbc指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

.LC1:
    .string "cpsr = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    mrs r1, cpsr

    mvn r1, #0
    msr cpsr, r1

    
    ldr r0, =.LC1
    mrs r1, cpsr
    bl printf

    mov r3, #10
    mov r4, #20
    sbc r1, r4, r3
    ldr r0, =.LC0
    bl printf
        
    mov r0, #0
    pop {pc}

08. mrs指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

.LC1:
    .string "cpsr = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC1
    mrs r1, cpsr
    bl printf

    mov r3, #10
    mov r4, #20
    adc r1, r3, r4

    ldr r0, =.LC0
    bl printf

        
    mov r0, #0
    pop {pc}

09. msr指令

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

.LC1:
    .string "cpsr = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    ldr r0, =.LC1
    mrs r1, cpsr

    bic r1, r1, #(1 << 29)
    msr cpsr, r1


    mov r3, #10
    mov r4, #20
    adc r1, r3, r4

    ldr r0, =.LC0
    bl printf

        
    mov r0, #0
    pop {pc}

程序示例

    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

.LC1:
    .string "cpsr = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    mrs r1, cpsr

    mvn r1, #0
    msr cpsr, r1

    
    ldr r0, =.LC1
    mrs r1, cpsr
    bl printf


    mov r3, #10
    mov r4, #20
    adc r1, r3, r4

    ldr r0, =.LC0
    bl printf

        
    mov r0, #0
    pop {pc}

10. 综合应用一

程序示例

@r1 = 100*230-(236&(1<<7))+(157|(1<<17))-(123^456);
    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

       
    @100 * 230
    mov r3, #100
    mov r4, #230
    mul r1, r3, r4

    mov r2, #236
    and r2, r2, #(1 << 7)

    sub r1, r1, r2

    mov r2, #157
    orr r2, r2, #(1 << 17)

    add r1, r1, r2

    mov r2, #123
    mov r3, #456
    eor r2, r2, r3
    
    sub r1, r1, r2
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

11. 综合应用二

程序示例

@ r1 = 255 把r1的第4位清0,第15位置一;
    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    mov r2, #0xff

    bic r2, r2, #(1 << 4)

    orr r1, r2, #(1 << 15)
       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}


12. 综合应用三

程序示例

@r1 = 255 只把r1的第4位和第7位清0;
    .section .rodata
    .align 2
.LC0:
    .string "val = %d\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}

    mov r2, #0xff

    bic r1, r2, #(1 << 4 | 1 << 7)

       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

13. 综合应用四

程序示例

@ r1 = 0x3456 把r1的第4到第10位清0,其他位不变;

    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x56

    bic r1, r2, #(0x7f << 4)
       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

14. 综合应用五

程序示例

@r1 = 0x3456 把r1的第4到第10位置1,其他位不变;
    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x56

    orr r1, r2, #(0x7f << 4)
       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

15. 综合应用六

程序示例

@r1 = 0x3456 把r1的第4到第10位设成0b1001110,其他位不变;
    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x56

    bic r1, r2, #(0x7f << 4)
    orr r1, r1, #(0b1001110 << 4)
       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

16. 综合应用七

程序示例

@r1 = 0x3456 把r1的第4到第10位取反,其他位不变;
    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x56


    eor r1, r2, #(0x7f << 4)
       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

17. 综合应用八

@r1 = 0x3456 取出r1的第4到第10位的值;
    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x56

    and r1, r2, #(0x7f << 4)
    mov r1, r1,  LSR #4
       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

18. 综合应用九

@ r1 = 0x3458把r1中最后的1清除,其他位保持不变;

    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x58

    sub r3, r2, #1

    and r1, r2, r3

       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

19. 综合应用十

@r1 = 0x3458 把r1中倒数二个的1清除,其他位保持不变;
    .section .rodata
    .align 2
.LC0:
    .string "val = %p\n"

    .section .text
    .align 2
    .global main
main:
    push {lr}


    mov r2, #0x3400
    add r2, r2, #0x58

    sub r3, r2, #1

    and r1, r2, r3

    sub r2, r1, #1
    and r1, r1, r2

       
    ldr r0, =.LC0
    bl printf


    mov r0, #0
    pop {pc}

20. 附录

你可能感兴趣的:(ARM,ARM,ARM汇编,ARM汇编语言,ARM汇编程序,汇编程序)