Re: How to use assembler together with Arduino libraries?

I don’t understand what you mean with this line:

create a .S file by clicking in the upper right arrow in your IDE window, name it as you like (e.g. foo.S) and inside the .ino sketch

Specifically, “upper right arrow”. OS is Win7, IDE is 1.8.3.

I created a directory name “asm_combo” and put two files in that dir. One is name “asm_combo.ino” and the other “my_asm.s”, each file from your examples. The my_asm.s file appears as a clickable tab when the project is open, just what I’d expect.

Compilation fails with “undefined reference to `Print_Hello’”. Complete output is attached, I could not inline as it exceeds the 9k limit.

Any thoughts on what I’m doing wrong?

combinedFileError.txt (23.7 KB)

ard_newbie:
...create a .S...

avr_fred:
...the other "my_asm.s"...

Details are important.

details are important

Yes, they certainly are. What I fail to to understand is why you all too often resort to such drive-by comments. Yes, I know it's obvious to you... lucky you.

You could have helped by pointing me in right direction with just as many words, instead I get a riddle.

avr_fred:
...lucky you...

In this case, luck is irrelevant. And claiming that it is is insulting. I came by the knowledge through experience and hard work.

...instead I get a riddle...

YOUR failure to read and understand does not make it a riddle. The answer is in my post.

In this case, luck is irrelevant. And claiming that it is is insulting.

That wasn’t mean’t to be an insult, it was sarcasm but I see that YOU missed the idiom. See how that works?

I came by the knowledge through experience and hard work.

I don’t doubt that, you demonstrate a keen insight and I’ve seen a few posts where you were very helpful but those posts were devoid of snark. That’s the disappointing factor here, you certainly know the material and we could all benefit from your knowledge but your attitude interferes with your ability to share said knowledge.

YOUR failure to read and understand does not make it a riddle. The answer is in my post.

Okay, thanks for the answer but that doesn’t change the fact that it doesn’t link, filenames make no difference. Same names, same result:

C:\Users\USER1\AppData\Local\Temp\ccDj1dpu.ltrans0.ltrans.o: In function `loop':
C:\Users\USER1\Documents\Arduino\foo/foo.ino:10: undefined reference to `Print_Hello'

You’re free to call me an idiot for because I fail to see what’s wrong, I really don’t care, it’s just the Internet. I can routinely fail to grasp the obvious and this may well be one of those failures but I just want to understand why it doesn’t work. It appears to be defined, compiles fine, it just isn’t recognized in the linker.

For anyone willing to try the files, they’re attached in a zip along with the full compilation output. You cannot attach a dot s assembly file with the forum software so foo.ino and foo.s are in the zip.

foo.zip (2.5 KB)

avr_fred:
...
I can routinely fail to grasp the obvious ...

.S not .s

avr_fred:
...but I see that YOU missed the idiom.

Or, I am capable of understanding that what you wrote can be both.

Huh. Where did the initial messages go?
I guess you do understand that you have to program in the gnu assembler, which has a somewhat different syntax than the Atmel assembler, since your "foo" example has gnu-style directives in it... (Hmm. But NOT the _SFR_IO_ADDR() macros you'll need around IO register names, or the hack to avoid them.)

.S not .s

This is apparently important. I downloaded your foo.zip and got the same error you did (as is), but it builds correctly when I rename the asm file to foo.S. Looking at the log, there is only some of the necessary processing done on "foo.s" - it goes through the 'checking for libraries used' part of the pre-processing, but is never actually compiled/assembled.
This is probably a bug in the pre-processor where some of the steps are not case-sensitive, and some are. You'd have gotten better error messages without the bug, but you would have gotten a LOT, since the #include for io.h would not have worked. (.S means "assembler with C preprocessor." ".s" means "assembler without preprocesing.") (there was a slim chance that the IDE would have told the assembler to preprocess anyway, but it doesn't seem to have gotten that far.)

westfw:
Huh. Where did the initial messages go?

Split the thread. Two different problems.

(.S means "assembler with C preprocessor." ".s" means "assembler without preprocesing.")

Westfw, thank you for the concise, informative answers.

Where did you unearth that nugget of knowledge? I've done a bit of digging and found no documentation for this IDE "feature". I found issues #274 and #3079 with the IDE where the feature is requested but the trail quickly goes cold and then finally #3227 but that's it.

Is there any documentation for using this other than what you mentioned? Really, knowing that it's GNU syntax and understanding that the case of the file extension matters (while being used in case insensitive OS's), I suppose there is enough to use the "feature" although I understand the compatibility could break with any future IDE release, given it's relative obscurity.

FWIW, the code origin was lifted directly from an example in this thread:

avr_fred:
Westfw, thank you for the concise, informative answers.

Where did you unearth that nugget of knowledge?

FTMOC (From The Manual Of Course)

Duoh, slaps forehead. Thank you! I was thinking it would have been documented in the IDE. With the lack of a roadmap of the what the IDE does with your files, it's difficult impossible to know where the IDE ends and the gnu tools begin.

As another example, I've seen all manner of explainations about when to use brackets or quotes in header file includes. Paths of header files seem not well understood as well. As is almost always the case in open community tools, the software is always light years ahead of the documentation. Sigh.