0

I am in process of migrating some legacy code to vxWorks 7.0. The vxWorks 6.9 code has the following few lines of assembly in an ISR. I am seeking an understanding of the below code line-by-line if possible. I am totally inexperienced with PPC assembly and GNU's in-line syntax

__asm__(
    "mfdec 3 \n\t"       ; I think this may be R3 = DEC timer val
    "my_loop:"           ; simple label
    "add. 3, %0, 3 \n\t" ; ?? Add %0+R3=> R3 with Rc=1. What is %0?  The ISR is void isr(void) type.
    "ble my_loop \n\t"   ; branch if <= to my_loop
    "mtdec 3 \n\t"       ; move R3 content into DEC
    :                    ; from here down I have no idea
    : "r" (val)
    : "3","cc"
);
  1. What is %0?
  2. What do the ':'s mean after the asm template string?
  3. What are the other lines (without comments), ie : through "3","cc" doing exactly?
halfer
  • 19,824
  • 17
  • 99
  • 186
peinal
  • 121
  • 4
  • 3
    1) `%0` is the first argument, which is `val`, whatever that is. 2) outputs, inputs, clobbers 3) `"r" (val)` means put `val` into a register, `3` and `cc` tell the compiler your asm block modifies those things. – Jester Feb 01 '21 at 19:59
  • Jester, thanks for the fast reply. I do not understand what 'first argument' is because the ISR handler of type void isr_handler(void). so 1st colon means 'no outputs', : "r" (val) means register R3 is an input? and the last : means R3 is clobbered? where can I find references for all of these things? Thanks so much!! – peinal Feb 01 '21 at 20:03
  • 3
    The gcc docs for inline asm are [here](https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html). When jester says "the first argument," he doesn't mean the first argument to the function (isr_handler), he means the first argument being passed to the inline asm. – David Wohlferd Feb 01 '21 at 20:52
  • Thanks David and Jester. You saved me many hours... – peinal Feb 02 '21 at 15:00

0 Answers0