MSP432 ARM - Объявление массива констант с использованием ассемблера
Как объявить массив констант во flash используя только ассемблер, а не C?
Вопрос говорит сам за себя, я считаю. Помимо самого кода ассемблера, я хочу получить доступ к этому константному массиву значений и выполнить итерацию по нему.
Я использую Code Composer Studio, MSP432.
В отличие от этого, я знаю, как получить доступ к ОЗУ, потому что я знаю, где эти адреса существуют, и мой код свободен делать с ними что угодно. Таким образом, я могу сделать что-то вроде этого:
;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]
Но я хочу значения из flash, смежные, из известных адресов, как и выше.
ОБНОВИТЬ:
.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
БОЛЬШЕ ОБНОВЛЕНИЯ Я создаю простой C-проект в Code Composer для MSP432. в 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
}
Когда я отлаживал его, получалось так, как я хотел - ряд констант во флэш-памяти, в данном случае расположенный после кода "main()", начиная с адреса флэш-памяти 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 ****
2 ответа
В С const int somearr[] = { 1,2,3,4,5,6,7};
помещает данные в .rodata
сегмент.
Чтобы архивировать то же самое, вам нужно разместить свою таблицу в этом разделе
Я не знаю код составителя, но ассемблер GNU имеет .section
директива
Один из способов сделать это - работать с 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