0

如何仅使用程序集而不是 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 ****
4

2 回答 2

1

在 Cconst int somearr[] = { 1,2,3,4,5,6,7};中,将数据放在.rodata段中。

要存档相同的内容,您需要将表格放在此部分中

我不知道代码编写器,但 gnu 汇编器有.section指令

于 2018-10-25T15:54:18.310 回答
0

一种方法是使用 STM32 Nucleo-64 (Nucleo-F303RE) 为我工作。为了简单起见,我在重置处理程序中运行了代码。

.syntax unified
.cpu cortex-m4

.fpu vfpv4

.thumb

.global vtable
.global reset_handler
.type vtable, %object
vtable:
    .word _estack
    .word reset_handler
.size vtable, .-vtable

/***********************************************************
* 'Array' declaration / initialization begins here
***********************************************************/
.type myarray, %object
myarray:
    .word   0x11111111
    .word   0x22222222
    .word   0x33333333
.size myarray, .-myarray
/***********************************************************
* 'Array' declaration / initialization ends here
***********************************************************/

.equ    myarraysize, 5  //the number of 'elements' in the 'array'.


.type reset_handler, %function
reset_handler:
  LDR  r0, =_estack
  MOV  sp, r0

    /******************************************************************
    *  START - code example using array
    /*****************************************************************/

    LDR  R1,=myarray  // this loads the location value itself (the 1st address),

    MOV  R2,#0        // R2 will keep a count to make sure we don't walk off
                      // end of array.

    LDR  R3,=myarrsize // R3 will be the equivalent of 'myarrsize'.

                       // R0 will hold our data (pretends we're using data).

main_loop:
    LDR R0,[R1]        // Load the data pointed to by R1 ('myarray') into R0.
    CMP R2,R3          // Are we at limit of array?
    BEQ main_loop      // If we are, we're done, so we'll just loop forever.
    ADD R2,#1          // Not done, keep going, keep count.
    ADD R1,#4          // Add 4 to register R1, so it points correctly to next
                       // address..
    B    main_loop     // Loop back.     

    /******************************************************************
    *  END - code example using array
    /*****************************************************************/


.size reset_handler, .-reset_handler
于 2018-10-24T11:24:38.687 回答