Note that there are some explanatory texts on larger screens.

plurals
  1. POC Macro utilizing immediate values in embedded arm asm - armcc
    primarykey
    data
    text
    <p>The closest threads to my question are these <a href="https://stackoverflow.com/questions/1135822/escaping-a-symbol-in-a-define-macro">Escaping a # symbol in a #define macro?</a> and <a href="https://stackoverflow.com/questions/1386597/how-to-print-a-pound-hash-via-c-preprocessor">How to print a pound / hash via C preprocessor?</a>, but they don't exactly answer my question. More explicitly, the second doesn't seem to work with the armcc compiler; it just prints hash4 and not the symbol defined by hash. Chris Lutz was especially disparaging of trying use a macro for this functionality in the second post, so maybe this is the incorrect method all together. I would like more thoughts than just one persons, though.</p> <p>The problem is the following: I'm trying to write a macro that defines an embedded asm C function utilizing a macro. I've essentially implemented it except for one issue... expressing an immediate value. Immediate values' syntax requires (I believe) a pound symbol which is also the "stringify" symbol for the preprocessor. So, is it possible to escape a # symbol in a C macro? </p> <p>The primary purpose behind this is to wrap an isr with a pico kernels thread context management procedures and that new procedure's function pointer will eventually be passed to the vectored interrupt controller.</p> <p>Here's the code:</p> <pre><code>#define ISR_THREAD_MGMT(ISR_FUNC,FUNC_NAME) \ __asm void FUNC_NAME ( void ); \ __asm void FUNC_NAME (void ) \ { \ STMDB sp!, {r0-r3}; \ MRS r0, SPSR; \ SUB lr, lr, #4; \ &lt;----- Heres the problem STMDB sp!, {r0, r10, r12, lr}; \ bl _thread_vectored_context_save; \ bl ISR_FUNC; \ b _thread_context_restore; \ } </code></pre> <p>I hope I've explained everything in sufficient detail. If not, please don't hesitate to ask for any more details.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. COMy first instinct was "don't use a macro for this", but clearly you've already seen someone else say that, so I'm not sure what you expect us to say - you are trying to use a macro pre-processor to do things it was never designed to do. If you were using at&t syntax, if would magically work because $ [indication of constant] is not a preprocessor "special character". One solution would of course be to actually write out FUNC_NAME and ISR_FUNC in individual functions - or not use the C compiler for assembler code...
      singulars
    2. COOverall, I was wanting a larger consensus than one person's thoughts. So, you are saying specifying embedded assembly instructions as a macro is outside its intended use? Weren't macros originally written to inline function calls? Furthermore, a text preprocessor that doesn't let you write all symbols? Seems strange to me...
      singulars
    3. COThe C preprocessor is intended for C - it's part of its name. When C was designed, inline assembler was not part of the scope - the compiler would produce assembler, and then assemble through the system assembler - if you wanted to add assembler code yourself, you wrote a `something.s` file - which is still a valid option. Most assemblers do have a macro functionality to let you produce the same code over and over with variations.
      singulars
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload