ce-2810 dr. mark l. hornick 1 gnu gcc assembler and c/c++ compiler

16
CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

Upload: darlene-riley

Post on 16-Jan-2016

216 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CE-2810Dr. Mark L. Hornick

1

GNU GCC Assembler

and C/C++ compiler

Page 2: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CE-2810Dr. Mark L. Hornick

2

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

Page 3: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CE-2810Dr. Mark L. Hornick

3

AVRStudio has two Assemblers

Built-in Atmel AVR AssemblerThis 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

Page 4: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CE-2810Dr. Mark L. Hornick

4

The GNU GCC Assembler/Compiler

Projects can consist of one or more .s (assembly language) files .c (C language) files .cpp (C++ language) files

Page 5: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CE-2810Dr. Mark L. Hornick

5

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

Page 6: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CE-2810Dr. Mark L. Hornick

6

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

Page 7: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

Where is the Stack?

CS-280Dr. Mark L. Hornick

7

Page 8: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

8

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.

Page 9: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

9

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.

Page 10: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

10

Java Edit-Compile-Run Cycle

A sample source file and its bytecode file.

Page 11: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

11

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()

Page 12: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

12

Review: Java Edit-Compile-Run Cycle

The result after the interpreter executes the instructions in the bytecode file.

Page 13: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

13

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.

Page 14: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

14

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.

Page 15: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

15

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.

Page 16: CE-2810 Dr. Mark L. Hornick 1 GNU GCC Assembler and C/C++ compiler

CS-1030Dr. Mark L. Hornick

16

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.