Dav*_*vid 1 memory assembly arm cpu-registers
该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
Run Code Online (Sandbox Code Playgroud)
我的代码有错误,但我看不出它是什么。我做错了什么吗?
我建议您学习如何在代码不起作用时对其进行调试,这仍然是学习恕我直言的最佳方法。
例如,您可以使用在线汇编器/调试器/模拟器,例如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
Run Code Online (Sandbox Code Playgroud)
如果您是 Windows 用户并且对 Linux 一无所知,另一种选择是使用 Windows 版本的qemu-system-arm
和GDB
,但现阶段这对您来说可能会更困难。
如果您熟悉/使用 Linux 系统,那么qemu-user
按照 Peter Cordes 在他的评论中建议的方式使用也是一个很好的解决方案。这可以在本机 Linux 系统上完成,或者通过使用VirtualBox
Windows 上的虚拟机,或者使用 Windows 子系统之一来WSL
完成WSL2
。