Possible to compile Arduino/C++ library for use in AVR assembly?

I'm working on a project writing AVR assembly for an ATmega328P (an Arduino Uno) in Atmel/Microchip Studio with AVRASM2. One of the components I'm using is the MFRC522 RFID reader/writer, for which there exists an Arduino library. I want to continue writing my code in assembly, but in the interest of time, it would be very helpful if I could include the library and call its functions from my assembly code.

I'm assuming the ideal way to do this is to compile the library into an object file so it can be linked with my assembler code. The problem is I'm unsure how to handle the linking portion. One other option I've considered is compiling the library into an object file, disassembling it with avr-objdump then including that disassembled code with my original assembly to be re-assembled. I have a feeling this will not work though. Maybe it might with position-independent code, but I'm fuzzy on the compiling-linking-assembling process.

Is this feasible? Am I thinking about this the right way?

in the interest of time you probably want to write the whole thing in C++

is there a reason why you need to code in assembly?

1 Like

AVRASM does not support linking or external libraries, so the only way you can include "other" code is by converting it to ASM source somehow.

As you point out, that's likely to be significantly difficult to do to an Arduino library, especially since it's probably got its own sub-depenencies like I2C. You're probably better off using the C++ source code as a "model" for freshly written ASM code.

One possible issue that I remember from long ago (MCS51, Keil C/C++ compiler) was the use of registers in function calls; the main code was assembly and an added function was in C. I had to change the assembly generated from the C code to make use of different registers to match what was used in the main assembly code.