将部分内存复制到另一个位置
Copy part of the memory to another location
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
我的代码有错误,但我看不出是什么。我是不是做错了什么?
我建议你学习如何在代码不工作时调试它,这仍然是学习恕我直言的最佳方式。
例如,您可以使用在线 assembler/debugger/emulator,例如 cpulator。
copy/paste你要测试的代码,
assemble它,
在一步步执行程序的同时查看寄存器值、内存内容并进入其中。
.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
如果您是 Windows 用户并且对 Linux 一无所知,另一种方法是使用 qemu-system-arm
和 [=12] 的 Windows 版本=],但在这个阶段这对你来说可能更难做到。
如果您是 familiar/using 一个 Linux 系统,使用 Peter Cordes 在他的评论中建议的 qemu-user
也是一个很好的解决方案。这可以在本机 Linux 系统上完成,或者通过在 Windows 上使用 VirtualBox
虚拟机,或者使用 WSL
或 WSL2
Windows 子系统。
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
我的代码有错误,但我看不出是什么。我是不是做错了什么?
我建议你学习如何在代码不工作时调试它,这仍然是学习恕我直言的最佳方式。
例如,您可以使用在线 assembler/debugger/emulator,例如 cpulator。
copy/paste你要测试的代码, assemble它, 在一步步执行程序的同时查看寄存器值、内存内容并进入其中。
.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
如果您是 Windows 用户并且对 Linux 一无所知,另一种方法是使用 qemu-system-arm
和 [=12] 的 Windows 版本=],但在这个阶段这对你来说可能更难做到。
如果您是 familiar/using 一个 Linux 系统,使用 Peter Cordes 在他的评论中建议的 qemu-user
也是一个很好的解决方案。这可以在本机 Linux 系统上完成,或者通过在 Windows 上使用 VirtualBox
虚拟机,或者使用 WSL
或 WSL2
Windows 子系统。