the ARM Cortex-M3 Processor - 9

이재하·2023년 6월 12일

Starting Cortex-M3 Development Using the GNU Tool Chain

19.1 BACKGROUND

Many people use Gnu's Not Unix(GNU) tool chain for ARM product development, and a number of development tools for ARM are based on the GNU tool chain. The GNU tool chains supporing the Cortex -M3 are available from the GNU gcc source , as well as from a number of vendors providing precompiled ready to use tool chains.

19.4 EXAMPLES
Let's look at a few examples using the GNU tool chain.

19.4.1 Example 1: The First Program

====example.s=====

// define constans 

	.equ	STACK_TOP, 0x20000800
    .text
    .syntax unified
    .thumb
    .global _start
    .type start, %function
    
_start:
	.word STACK_TOP, start
    
start :
	movs r0, #10
    
    
    The .word directive here helps us define the stating stack pointer value as 0x20000800 and the reset vector as start

• .word 지시어는 여기에서 시작 스택 포인터 값을 0x20000800으로 정의하는 데 도움을 줍니다. 또한 리셋 벡터를 start로 정의합니다.
• .text는 조립되어야 하는 프로그램 영역을 나타내는 미리 정의된 지시어입니다.
• .syntax unified는 통합 어셈블리어 구문을 사용한다는 것을 나타냅니다.
• .thumb은 프로그램 코드가 Thumb® 명령어 세트에 있는 것을 나타냅니다. 또는 .code16을 사용하여 레거시 Thumb 명령어 구문을 사용할 수도 있습니다.
• .global은 _start 라벨이 다른 오브젝트 파일과 공유될 수 있도록 허용합니다.
• _start는 프로그램 영역의 시작점을 나타내는 라벨입니다.
• start는 별도의 라벨로, 리셋 핸들러를 나타냅니다.
• .type start, %function은 start 심볼이 함수임을 선언합니다. 이것은 벡터 테이블의 모든 예외 벡터에 대해 필요합니다. 그렇지 않으면 어셈블러가 벡터의 가장 작은 유효 비트(LSB)를 0으로 설정합니다.
end는 이 프로그램 파일의 끝을 나타냅니다.

objdump

example1.out: file format elf32-littlearm
Disassembly of section .text:
00000000 <_start>:
0: 20000800 .word 0x20000800
4: 00000009 .word 0x00000009
00000008 <start>:
8: 200a movs r0, #10
a: 2100 movs r1, #0
0000000c <loop>:
c: 1809 adds r1, r1, r0
e: 3801 subs r0, #1
10: d1fc bne.n c <loop>
00000012 <deadloop>:
12: e7fe b.n 12 <deadloop>

19.4.2 Example 2: Linking Multiple Files
As mentioned before, we can create multiple object files and link them together. Here, we have an example of two assemly files : example2a.s and example2b.s; example2a.s contains the vector table only, and exam,ple2b.s contains the program code. The .global is used to pass the address from one file to another :


==example2a.s ==

	.equ STACK_TOP, 0x20000800
    .syntax unified
    .global vectors_table
    .global start
    .global nmi_handler
    .thumb
vectors_table:
	.word STACK_TOP, start, num_handler, 0x00000000
    .end
 

0개의 댓글