5 you will need to add full c boilerplate to the top

This preview shows page 3 - 5 out of 12 pages.

5.)You will need to add full C boilerplate to the top of this file. Go back to your lab 1 project to find these. Here’s a reminder about what you need: Include xc.h Configuration register setup (all those #pragma config lines). 6.)Clean and Build Main Project to check your syntax, etc. Adding a ASM-based Library to a C-based project1.)Create a new “assemblyFile.s” and add it to your project Remember: Assembler → AssemblyFile.s Name it something like “orser_lab4b_asmLib_v001.s” WARNING: If you name your c-file and assembly-file with the same beginning file name you will cause cryptic errors in compilation! Make sure filename differ by more than just the extension (ie., orser_lab4b_asmLib_v001.s orser_lab4b_main_v001.c) 2.)You will need a different boilerplate for an ASM library. Use the code included below. Specifically you won’t need the following: Configuration registers Global declaration of the _mainfunction/label The .bss section: space for stack is allocated by the C compiler before calling main(). Also, we are not going to define any variables in assembly: we can do all our global variable definitions in C. It’s safer and easier to let the C compiler handle data organization in data memory. Page 3
EE 2361 - Lab # 2bECE Department.include "xc.inc" .text ;BP (put the following data in ROM(program memory)) ; This is a library, thus it can *not* contain a _main function: the C file will ; deine main(). However, we ; we will need a .global statement to make available ASM functions to C code. ; All functions utilized outside of this file will need to have a leading ; underscore (_) and be included in a comment delimited list below. .global _example_public_function, _second_public_function Boilerplate code for ASM-based library source files 3.)Add to this file a few of your pre-made functions from Lab 2a. Rename the labels to start with an underscore (_). This is needed for Global Function. You will need at least the following functions: _write_0() _write_1() _wait_50us() (write this function if you don't already have it) 4.)Add each of the above functions to the .global statement. It should look something like this when you are done (note: “djo” are my initials: David J. Orser. You should use your own initials): .global _write_0, _write_1, _djo_wait_50us _write_0: ; 2 cycles for a function call bsetLATA, #0 Example of properly setup .global statement and first function label 5.)Clean and Build Main Project to check your syntax, etc. 6.)Be polite: if you use any registers in your functions (e.g., if you use w8 in _wait_50us as a loop counter), make sure that you save the value of the register at the beginning of the function, and retrieve the value right before you exit. You can to consider 1 cycle for the push and 1 cycle for the pop instruction . The code would look something like this: _wait_50us: push w5 mov #0x107, w5 ... pop w5 return 11

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture