Some Header Files - PowerPoint PPT Presentation

1 / 12
About This Presentation
Title:

Some Header Files

Description:

msoe/time.h delay routines. msoe/display.h hex to ascii and ... bin executables. man documentation. lib libraries startup, std, msoe. More Usage ... – PowerPoint PPT presentation

Number of Views:26
Avg rating:3.0/5.0
Slides: 13
Provided by: ROTH8
Category:

less

Transcript and Presenter's Notes

Title: Some Header Files


1
Some Header Files
  • msoe/ports.h defines standard ports
  • ports_fox11.h Fox11 ports (Dr. Durant)
  • msoe/common.h defines
  • byte unsigned char
  • word unsigned short
  • size_t long unsigned
  • msoe/time.h delay routines
  • msoe/display.h hex to ascii and other routines
    for Wookie/Briefcase display
  • msoe/string.h simple string handling routines

2
Compiler Usage
  • Located at c\usr\... ? you installed it first
    week (with assembler)
  • bin executables
  • man documentation
  • lib libraries startup, std, msoe

3
More Usage
  • For each C/C module
  • gcc g mshort Wall fno-exceptions O2 S
    name.cpp
  • as o name.o name.s
  • Link
  • ld
  • -T (include our memory map file)
  • -relax (optimize page0 addressing)
  • crt1.o ? startup code
  • list of .o files
  • -L (library search directories)
  • -l (other libraries)

4
Mixing AS and C/C
  • Note, for C/C
  • gcc g mshort Wall fno-exceptions O2 S
    name.cpp
  • as o name.o name.s
  • For each ASM module
  • as o name.o name.s
  • Simply link object files together
  • We do need some glue code

5
C Calling Assembly Subroutines
  • Linker will need find the routine at link time
  • We need a placeholder so C can compile
  • Do it with a prototype this tells C what data
    types to send the routine and what type to expect
    in return.
  • Must declare assembly routines with extern C
  • extern so that the compiler will defer resolution
    until link time
  • C so that the compiler will assume C linkage
    convention
  • Here C refers to the linkage convention of the
    C language, not the C language itself.
  • C has a different and incompatible linkage
    convention due primarily to its overloading
    capabilities.
  • We can wrap several declarations at once
  • extern C
  • declaration 1
  • declaration
  • Normally put in a header file
  • Assembly must make entry point global
  • Works for variables too

6
Example
  • In C file
  • extern "C" void flashLEDS(void)
  • int main() // gcc 3 requires int return, but
    allows omission of return statement
  • for() // a forever loop - common for
    embedded systems
  • flashLEDS()
  • In .S file
  • .section .text
  • .global flashLEDS
  • flashLEDS
  • ldaa 0xFF
  • staa 0x1404
  • NOP

7
Calling C From Assembly
  • Again, C uses name mangling
  • To allow for overloading, the entry point of a
    C is an encoding of its name and its signature.
  • Different compilers may use different mangling
    algorithms, thus it is difficult to predict what
    a mangled name will be.
  • Better to declare C routine that you want to
    call from assembly as extern C as well.

8
Example
  • In Cpp File
  • extern "C" void flashLEDS(void)
  • extern "C" void flashLEDS2(void)
  • void flashLEDS2(void)
  • unsigned char LEDS (unsigned char )0x1404
  • LEDS 0xFF
  • LEDS 0x00
  • int main() // gcc 3 requires int return, but
    allows omission of return statement
  • for() // a forever loop - common for
    embedded systems
  • flashLEDS()

9
What About Registers?
  • Just like subroutines in assembly language, you
    want to avoid changing any side-effects, such as
    changing
  • GCC doesnt care about A, B, D, X, or Y
    (documented) and CCR does not appear to be an
    issue either.

10
Passing Parameters
  • Typically, parameters would be passed via
    registers.
  • HC11 is very register poor.
  • Uses register B or D for first argument
  • Depending on type
  • Remaining parameters are passed on the stack
  • Return value is passed back in register B or D
  • Depending on type

11
Getting Parameters in Assembly
  • First parameter is
  • in B if it is byte sized
  • A is undefined and may not be 0
  • in D if it is word sized
  • Remember some parameters are passed by reference
    (char for example)
  • The rest are on the stack
  • All parameters consume two bytes or positions on
    the stack regardless of whether they are bytes or
    words
  • The last position of the stack will have the
    2-byte return address needed by RTS
  • Consider using the TSX instruction at the
    beginning of your assembly routine
  • TXS - X now contains SP1, and points to MSB of
    return address
  • LDAX 0,X refers to MSB of return address
  • LDAX 1,X refers to LSB of return address
  • LDAX 2,X refers to MSB of parameter 2 (not used
    if p2 is a byte)
  • LDAX 3,X refers to LSB of parameter 2 (or p2 if
    it is a byte)
  • LDAX 4,X refers to MSB of parameter 3 (not used
    if p3 is a byte)
  • LDAX 5,X refers to LSB of parameter 3 (or p3 if
    it is a byte)

12
Returning Values
  • Put return value in
  • B if it is a byte
  • D if it is a word
  • What about float, double, long, etc?
  • Compiler uses combination of D, X, and Y for
    parameters, and additional stack space
  • Becomes difficult to track
  • Compiler dependent
  • Avoid if possible
Write a Comment
User Comments (0)
About PowerShow.com