Mixing C and Ass.

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using Winavr and Studio, If I create a GCC pjt. with .S as kernel file ( but i need to call a c function )are there any advantages to doing it that way other than I guess i don't have to worry about init. the MCU ( thanks crt.* ) ? If not i can just make the kernel file *.c and call the *.S function.

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You have the option (assuming CRT) of either providing main: in a .S file or main() in a .c file as your entry point. Unless you do something to prevent it the CRT will continue to provide reset jump, ISR vector table, stack setup, .data and .bss loops. This is actually a nice feature in that you can write mainly Asm in .S but put some variable definitions (some initialised, some not) in a linked .c file and the Asm gets it's data initialisers automatically copied from flash copy to SRAM (a chore you'd have to implement yourself otherwise).

OTOH if writing a "tight" bootloader you may prefer your initial (first linked) .S to locate at 0x0000 and you then take control of the reset jump and any vector entries you need (and it's up to you about stack setup and whether you want to have .data and .bss) in this case build the project with -nostartfiles or -nodefaultlibs but remember that if you are providing some .c files that now any globals will not be initialised or wiped to 0.

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you, sir ! I can get that type of deep knowledge by reading ( only )that fat GNU manual ?

1) Studio 4.18 build 716 (SP3)
2) WinAvr 20100110
3) PN, all on Doze XP... For Now
A) Avr Dragon ver. 1
B) Avr MKII ISP, 2009 model
C) MKII JTAGICE ver. 1

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sad to say but reading manuals IS one of the key skills of programming - there's no avoiding it.