将部分内存复制到另一个位置

问题描述

copyMemory函数必须将部分内存复制到另一个位置。

copyMemory
; The copyMemory function receives the following parameters:
; R0: Address of the first 32-bit word to copy
; R1: Address of the last 32-bit word to copy
; R2: Destination address

ADD R4,R1,#4

Loop
CMP R4,R1
BEQ EndLoop

LDR R3,[R0]
STR R3,[R2]
ADD R0,R0,#4
ADD R2,R2,#4

B Loop
EndLoop

EndcopyMemory
BX LR

我的代码错误,但是我看不到它是什么。我做错了什么吗?

解决方法

我建议您学习在代码不起作用时如何调试代码,这仍然是学习恕我直言的最佳方法。

例如,您可以使用在线汇编器/调试器/仿真器,例如cpulator

复制/粘贴您要测试的代码, 组装它, 在逐步执行程序的同时查看寄存器值和内存内容。

            .global _start
_start:
            ldr r0,= first
            ldr r1,= last
            ldr r2,= dst
            
            // The CopyMemory function receives the following parameters:
            // R0: Address of the first 32-bit word to copy
            // R1: Address of the last 32-bit word to copy
            // R2: Destination address
            add r4,r1,#4

loop:
            cmp r4,r1
            beq endloop

            ldr r3,[r0]
            str r3,[r2]
            add r0,r0,#4
            add r2,r2,#4

            b loop      
endloop:
            b .
            .data                   
first:      .word 0x11111111
            .word 0x22222222
            .word 0x33333333
last:       .word 0x44444444
dst:        .word 0x00000000
            .word 0x00000000
            .word 0x00000000            
            .word 0x00000000
            .end

enter image description here

enter image description here

如果您是Windows用户并且对Linux一无所知,则可以选择使用Windows版本的qemu-system-armGDB,但这可能对您来说更困难在这个阶段。

可以分别从herehere下载它们。

如果您熟悉/使用Linux系统,那么使用Peter Cordes在其评论中建议的qemu-user也是一个很好的解决方案。可以在本机Linux系统上,或者通过在Windows上使用VirtualBox虚拟机,或者通过使用WSLWSL2 Windows子系统之一来完成此操作。