190 likes | 539 Views
GNU GCC Assembler. and C/C++ compiler. The Development System is basically the same. Same old AVRStudio: Editor AVR Assembler Simulator/Debugger But in CE2810, instead of the AVR Assembler, we’ll be using: GCC Assembler GCC C compiler. AVRStudio has two Assemblers.
E N D
GNU GCC Assembler and C/C++ compiler CE-2810 Dr. Mark L. Hornick
The Development System is basically the same Same old AVRStudio: • Editor • AVR Assembler • Simulator/Debugger But in CE2810, instead of the AVR Assembler, we’ll be using: • GCC Assembler • GCC C compiler CE-2810 Dr. Mark L. Hornick
AVRStudio has two Assemblers Built-in Atmel AVR Assembler This is the one you’ve been using so far Each project creates a single .hex file from a single .asm file • Other .asm files have to be .included in the main .asm file CE-2810 Dr. Mark L. Hornick
The GNU GCC Assembler/Compiler • Projects can consist of one or more • .s (assembly language) files • .c (C language) files • .cpp (C++ language) files CE-2810 Dr. Mark L. Hornick
Differences between AVR and GNU assemblers Atmel • .include “m32def.inc” • .cseg • .dseg • .db “hello”, 0 • LOW() • HIGH() • <file>.asm • .org 0x2A • GCC • #include <avr/io.h> • .section .text • . section .data • .asciz “hello” • lo8() • hi8() • <file>.s • automatic CE-2810 Dr. Mark L. Hornick
Every .s file should contain the following GCC directives #include <avr/io.h> • Definitions for PORTB, SPL, etc. #define _SFR_ASM_COMPAT 1 #define __SFR_OFFSET 0 • Without this, aliases like PORTB are resolved to their data space address values (0x38) • With this, PORTB is resolved to its corresponding I/O space address value (0x18) • i.e. subtracts 0x20 from the data space address CE-2810 Dr. Mark L. Hornick
Where is the Stack? CS-280 Dr. Mark L. Hornick
Review: Java Edit-Compile-Run Cycle • Step One: Edit the program. • Type in the program, using a text editor, and save the program to a file. • Use the name of the main class and the suffix .java for the filename. • This file is called a source file. CS-1030 Dr. Mark L. Hornick
Review: Java Edit-Compile-Run Cycle • Step 2: Compile the source file. • The process of compiling the source file creates the bytecode file. • The name of the compiler-generated bytecode file will have the suffix .class while its prefix is the same as the source file’s. CS-1030 Dr. Mark L. Hornick
Java Edit-Compile-Run Cycle • A sample source file and its bytecode file. CS-1030 Dr. Mark L. Hornick
Review: Java Edit-Compile-Run Cycle • Step 3: Execute the bytecode file. • A java interpreter (VM) will go through the bytecode file and execute the instructions in it. • If an error occurs while running the program, the interpreter will catch it and stop its execution. • The VM starts execution at the bytecode instructions that correspond to the Java statementpublic static void main() CS-1030 Dr. Mark L. Hornick
Review: Java Edit-Compile-Run Cycle • The result after the interpreter executes the instructions in the bytecode file. CS-1030 Dr. Mark L. Hornick
C Edit-Compile-Link-Run Cycle • An additional step – Link • Step One: Edit the program. • Type in the program, using a text editor, and save the program to a file. • Use the name of the main class and the suffix .c for the filename. • This file is called a source file. CS-1030 Dr. Mark L. Hornick
C Edit-Compile-Run Cycle • Step 2: Compile the source file. • The process of compiling the source file creates the object file. • The name of the compiler-generated object file will have the suffix .o while its prefix is the same as the source file’s. • The object file contains low-level processor-specific instructions, as well as references to functions in other object files or object libraries. • It is not executable; i.e. you cannot run an object file. CS-1030 Dr. Mark L. Hornick
C Edit-Compile-Link-Run Cycle • Step 3: Link the object file(s). • The process of linking the object file(s) creates the executable file. • The name of the linker-generated executable file will have the suffix .hex while its prefix is the same as the primary source file’s. • The executable file contains low-level processor-specific instructions; calls to other object libraries are resolved by the linking process. • The executable file is downloadable to the Atmega32. CS-1030 Dr. Mark L. Hornick
C Edit-Compile-Link-Run Cycle • Step 4: Download the hex file. • The Atmel bootloader loads the machine instructions from the hex file and writes them to Flash memory. • The CPU’s Program Counter is set to the beginning of the program corresponding to main after some initialization code is executed. CS-1030 Dr. Mark L. Hornick