【ARM】ARM汇编程序设计(六) stm和ldm

00. 目录

文章目录

    • 00. 目录
    • 01. ldmea指令
    • 02. ldmed指令
    • 03. ldmfa指令
    • 04. ldmfd指令
    • 05. stmea指令
    • 06. stmed指令
    • 07. stmfa指令
    • 08. stmfd指令
    • 09. swp指令
    • 06. 附录

01. ldmea指令

程序示例


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


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

    adr r4, .L1

    ldmea r4, {r1, r2, r3}
    ldr r0, =.LC1
    bl printf


    mov r0, #0
    pop {pc}

.L0:
    .word 0x1111
    .word 0x2222
    .word 0x3333

.L1:
    .word 0x0


02. ldmed指令

程序示例


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


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

    adr r4, .L0

    ldmed r4, {r1-r3}
    ldr r0, =.LC1
    bl printf


    mov r0, #0
    pop {pc}

.L0:
    .word 0x1111
    .word 0x2222
    .word 0x3333

.L1:
    .word 0x0


03. ldmfa指令

程序示例


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


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

    adr r4, .L1

    ldmfa r4, {r1-r3}
    ldr r0, =.LC1
    bl printf


    mov r0, #0
    pop {pc}

.L0:
    .word 0x1111
    .word 0x2222
    .word 0x3333

.L1:
    .word 0x0


04. ldmfd指令

程序示例


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


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

    adr r4, .L0

    ldmfd r4, {r1-r3}
    ldr r0, =.LC1
    bl printf


    mov r0, #0
    pop {pc}

.L0:
    .word 0x1111
    .word 0x2222
    .word 0x3333

.L1:
    .word 0x0


05. stmea指令

程序示例:


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


    .section .text
    .align 2
    .global main
main:
    stmfd sp!, {lr}
    mov fp, sp

    sub sp, sp, #12

    mov r1, #1
    mov r2, #2
    mov r3, #3
    stmea sp, {r1, r2, r3}


    ldmfd sp, {r1, r2, r3}
    ldr r0, =.LC1
    bl printf



    mov r0, #0
    mov sp, fp
    ldmfd sp!, {lr}

06. stmed指令

程序示例:


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


    .section .text
    .align 2
    .global main
main:
    stmfd sp!, {lr}
    mov fp, sp

    sub sp, sp, #4

    mov r1, #1
    mov r2, #2
    mov r3, #3
    stmed sp!, {r1, r2, r3}


    ldmed sp!, {r1, r2, r3}
    ldr r0, =.LC1
    bl printf



    mov r0, #0
    mov sp, fp
    ldmfd sp!, {lr}

07. stmfa指令

程序示例:


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


    .section .text
    .align 2
    .global main
main:
    stmfd sp!, {lr}
    mov fp, sp

    sub sp, sp, #16

    mov r1, #1
    mov r2, #2
    mov r3, #3
    stmfa sp, {r1, r2, r3}


    ldmed sp, {r1, r2, r3}
    ldr r0, =.LC1
    bl printf



    mov r0, #0
    mov sp, fp
    ldmfd sp!, {lr}

08. stmfd指令

程序示例:


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"


    .section .text
    .align 2
    .global main
main:
    stmfd sp!, {lr}
    mov fp, sp


    mov r1, #1
    mov r2, #2
    mov r3, #3
    stmfd sp, {r1, r2, r3}


    ldmea sp, {r1, r2, r3}
    ldr r0, =.LC1
    bl printf



    mov r0, #0
    mov sp, fp
    ldmfd sp!, {lr}

09. swp指令

程序示例:


    .section .rodata
    .align 2
.LC0:
    .string "hello world\n"
.LC1:
    .string "var = %p %p %p\n"
.LC2:
    .string "val = %d\n"


    .section .text
    .align 2
    .global main
main:
    stmfd sp!, {lr}
    mov fp, sp

    sub sp, sp, #4

    mov r0, #10
    str r0, [sp]
    mov r2, #20

    swp r1, r2, [sp]
    ldr r0, =.LC2
    bl printf

    ldr r1, [sp]
    ldr r0, =.LC2
    bl printf


    mov r0, #0
    mov sp, fp
    ldmfd sp!, {lr}

06. 附录

6.1 【ARM】Load Store指令

你可能感兴趣的:(ARM)