如何仅使用程序集而不是 C 在闪存中声明常量数组?
这个问题说明了一切,我相信。除了在汇编代码本身之外,我还想访问和遍历那个常量数组。
我正在使用 MSP432 Code Composer Studio。
相比之下,我知道如何访问 RAM,因为我知道这些地址存在于哪里,而且我的代码可以自由地对它们做任何事情。因此,我可以这样做:
;declare 1st RAM address:
FIRST .field 0x20000000,32
;use it:
LDR R1,FIRST
LDRB R0,[R1]
;etc.
或者,如果我正在访问 GPIO,我知道具体的输入地址:
;declare:
PORT1INPUT .field 0x4000C000,32
;use:
LDR R1,PORT1INPUT
LDRB R0,[R1]
但是我想要来自已知地址的连续闪存的值,就像上面一样。
更新:
.thumb
.text
.align 2
;my issue or question is about this section (I think)
;don't know how or what to put here
;to declare a continguous block of
;addresses in flash, containing
;specific values
;i dont want to load just the values,
;i need to know how to start at a certain
;address
; i.e. i want to mimic an array,
; but in flash.
;i know how to initialize and mimic an
;array in RAM.
.global main
.thumbfunc main
main: .asmfunc
mainloop
;code here that starts at
;first address in flash
;containing first value
;and reads it into a register
;
;the code isn't the problem.
;i know how to do this part.
B mainloop
.endasmfunc
.end
更多更新 我在 Code Composer 中为 MSP432 创建了一个简单的 C 项目。在 main() 中,我有:
#include "msp.h"
static const int somearr[] = { 1,2,3,4,5,6,7};
void main(void) {
int i = somearr[0];//needed so compiler would not ignore declaration
}
当我调试它时,结果就像我想要的一样 - flash 中的一系列常量,在这种情况下位于代码“main()”之后,从 flash address 开始0x000005D0
。之后存储在每个连续位置的数据是我指定的 int 值。
但我想直接组装 - 而不是 C.
构建输出(将显示我想象的工具链)是:
**** Build of configuration Debug for project 00.static.global.const.array.of.ints ****
/opt/ti/ccsv8/utils/bin/gmake -k -j 2 all -O
Building file: "../main.c"
Invoking: ARM Compiler
"/opt/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --include_path="/opt/ti/ccsv8/ccs_base/arm/include" --include_path="/opt/ti/ccsv8/ccs_base/arm/include/CMSIS" --include_path="/home/devchu/Development/ti.robotics/tirslk_maze_1_00_00/00.static.global.const.array.of.ints" --include_path="/opt/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/include" --advice:power=all --define=__MSP432P401R__ --define=ccs -g --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi --preproc_with_compile --preproc_dependency="main.d_raw" "../main.c"
"../main.c", line 3: warning #179-D: variable "somearr" was declared but never referenced
Finished building: "../main.c"
Building target: "00.static.global.const.array.of.ints.out"
Invoking: ARM Linker
"/opt/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/bin/armcl" -mv7M4 --code_state=16 --float_support=FPv4SPD16 -me --advice:power=all --define=__MSP432P401R__ --define=ccs -g --gcc --diag_warning=225 --diag_wrap=off --display_error_number --abi=eabi -z -m"00.static.global.const.array.of.ints.map" --heap_size=1024 --stack_size=512 -i"/opt/ti/ccsv8/ccs_base/arm/include" -i"/opt/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/lib" -i"/opt/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/include" --reread_libs --diag_wrap=off --display_error_number --warn_sections --xml_link_info="00.static.global.const.array.of.ints_linkInfo.xml" --rom_model -o "00.static.global.const.array.of.ints.out" "./main.obj" "./startup_msp432p401r_ccs.obj" "./system_msp432p401r.obj" "../msp432p401r.cmd" -llibc.a
<Linking>
remark #10371-D: (ULP 1.1) Detected no uses of low power mode state changing instructions
remark #10372-D: (ULP 4.1) Detected uninitialized Port 1 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 2 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 3 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 4 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 5 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 6 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 7 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 8 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 9 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
remark #10372-D: (ULP 4.1) Detected uninitialized Port 10 in this project. Recommend initializing all unused ports to eliminate wasted current consumption on unused pins.
Finished building target: "00.static.global.const.array.of.ints.out"
Building files: "00.static.global.const.array.of.ints.out"
Invoking: ARM Hex Utility
"/opt/ti/ccsv8/tools/compiler/ti-cgt-arm_18.1.2.LTS/bin/armhex" --memwidth=8 --romwidth=8 -o "00.static.global.const.array.of.ints.hex" "00.static.global.const.array.of.ints.out"
Translating to Extended Tektronix format...
"00.static.global.const.array.of.ints.out" .intvecs ==> .intvecs
"00.static.global.const.array.of.ints.out" .text ==> .text
"00.static.global.const.array.of.ints.out" .cinit ==> .cinit
Finished building: "00.static.global.const.array.of.ints.out"
**** Build Finished ****