Example of an ASM function in a C project?

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

I want to call an ASM function from C, and I'm stuck at even getting the ASM file to ASM. I created the file via AS6 (call it foo.s) and .include-ed the proper .inc file and a few lines of ASM, and the thing blows up on the .inc file, with

unknown pseudo-op: '.device'

followed by countless

expected comma after XYZ

I also can't figure out the string requirements for adding an include path (the -I argument in properties). In the path I've tried '\' and '\\' and '/' and nothing works (although each fails differently). I need to provide the entire path in the .include to even get the .inc file found.

So what am I !#@$#%^& doing wrong? Even a pointer to a working example would be fine. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#define __SFR_OFFSET 0
#include 

.global add_one
add_one:
  inc 24
  ret

".device" is for a completely different assembler (the Atmel one) not avr-as which is the one GCC uses.

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

Thanks a bunch. Where can I read more about this? AS6 help wasn't very helpful (GIGO?)

EDIT: for example, an AS6 search on ".global" returns no results.................

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

kk6gm wrote:
Thanks a bunch. Where can I read more about this? AS6 help wasn't very helpful (GIGO?)

EDIT: for example, an AS6 search on ".global" returns no results.................

https://sourceware.org/binutils/docs/as/index.html
http://www.nongnu.org/avr-libc/user-manual/assembler.html

Stefan Ernst

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

OK, thanks to all. It's not a bad interface at all, now that I see what's involved.

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

Note that if you use #include, you should probably name your file with a ".S" extension, rather than ".s" (note case.) The difference will be whether gcc runs the pre-processor (which you DO want, usually) before the actual assembler.

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

westfw wrote:
Note that if you use #include, you should probably name your file with a ".S" extension, rather than ".s" (note case.) The difference will be whether gcc runs the pre-processor (which you DO want, usually) before the actual assembler.

OK, thanks for the tip.