You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

LPC2148 ARM7TDMI汇编代码内存读写及LUT数据拷贝问题求助

Hey there! Let's break down the two issues you're facing with your ARM7TDMI (LPC2148) assembly code one by one, and fix them up.

Fixing Your ARM7TDMI Assembly Code Issues

1. Why does SourceL show empty data when reading from memory?

First, let's clear this up: your SourceL is defined correctly in the READWRITE data section with DCW &1234, so the data is stored there. The empty/incorrect value you're seeing is likely due to one of these reasons:

  • You're checking the wrong register in your debugger: your code reads SourceL into r2, but never uses r2 afterward. If you're looking at r3 or DestinationL before the final str r4, [r1] line, you'll see uninitialized garbage or overwritten values.
  • Linker script misconfiguration: Double-check that your linker script properly places the MyData section into LPC2148's RAM (starting at 0x40000000). If the data section isn't loaded into RAM correctly, labels will show empty values.

2. Fixing the Lookup Table (LUT) Copy from SourceL to DestinationL

Your current code doesn't actually copy the LUT data—here's why, plus a corrected version:

  • You load SourceL's value into r2, but then write uninitialized r3 (garbage data) to DestinationL.
  • You immediately overwrite DestinationL with r4's value (245), erasing any chance to see the copied LUT data.

Corrected Code

AREA Program, CODE, READONLY
EXPORT __main
ENTRY
__main
    ; Load addresses of source and destination
    ldr r0, =SourceL       ; Address of 16-bit source data
    ldr r1, =DestinationL  ; Address of 16-bit destination

    ; Read 16-bit value from SourceL into r2 (use ldrh for half-word)
    ldrh r2, [r0]
    ; Note: ldr works too if data is word-aligned, but ldrh is safer for DCW (16-bit)

    ; Write the copied value to DestinationL
    strh r2, [r1]

    ; Optional: Verify the copy by reading back DestinationL into r3
    ldrh r3, [r1]

    ; Exit debug session
    SWI &11

AREA MyData, DATA, READWRITE
SourceL      DCW &1234     ; 16-bit source lookup value
ALIGN
DestinationL DCW &0        ; 16-bit destination (initialized to 0)
ALIGN
END

Key Fixes Explained

  • Use ldrh/strh for 16-bit data: Since you're using DCW (16-bit constant), half-word operations avoid alignment issues and match the data size exactly.
  • Copy the correct register: We write r2 (which holds SourceL's value) to DestinationL, not uninitialized r3.
  • Removed the overwriting str r4, [r1] line: This line was erasing your copied LUT data. If you need to write 245 later, move it after verifying the copy works.

Quick Debugging Tips

  • Set breakpoints after each ldr/str instruction to check register values (r0, r1, r2) and memory locations (SourceL, DestinationL).
  • Confirm your debugger is set to view the correct RAM region (LPC2148's RAM starts at 0x40000000) when inspecting data labels.

内容的提问来源于stack exchange,提问作者user9603264

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.22 08:11:15