AVR

6 avr-libc and assembler programs

siwall 2014. 4. 17. 16:38

6.1 Introduction

AVR 마이크로컨트롤러에서 어셈블러 코드를 사용해야 할 몇가지 이유가 있다.

• Code for devices that do not have RAM and are thus not supported by the C compiler.

• Code for very time-critical applications.

• Special tweaks that cannot be done in C.



6.2 Invoking the compiler



6.3 Example program



6.4 Pseudo-ops and operators

어셈블러에서 사용할 수 있는 pseudo-ops 는 GNU assembler (gas) manual. 에 나와있다. 링크

Some common pseudo-ops include:

• .byte allocates single byte constants

• .ascii allocates a non-terminated string of characters

• .asciz allocates a \0-terminated string of characters (C string)

• .data switches to the .data section (initialized RAM variables)

• .text switches to the .text section (code and ROM constants)

• .set declares a symbol as a constant expression (identical to .equ)

• .global (or .globl) declares a public symbol that is visible to the linker (e. g. function entry point, global variable)

• .extern declares a symbol to be externally defined; this is effectively a comment only, as gas treats all undefined symbols it encounters as globally undefined anyway


주목할만한 operator 들은 다음과 같다:

• lo8 : 16bit integer에서 하위 8bit를 가져온다.(LSB)

• hi8  : 16bit integer에서 상위 8bit를 가져온다.(MSB)

• pm : Takes a program-memory (ROM) address, and converts it into a RAM address. This implies a division by 2 as the AVR handles ROM addresses as 16-bit  words (e.g. in an IJMP or ICALL instruction), and can also handle relocatable symbols on the right-hand side.


Example:

ldi r24, lo8(pm(somefunc))

ldi r25, hi8(pm(somefunc))

call something


This passes the address of function somefunc as the first parameter to function something.



'AVR' 카테고리의 다른 글

8 How to Build a Library  (0) 2014.04.17
7 Inline Assembler Cookbook  (0) 2014.04.17
5 Data in Program Space  (0) 2014.04.17
4 Memory Sections  (0) 2014.04.17
3 Memory Areas and Using malloc()  (0) 2014.04.17