• AVR Freaks

AnsweredInline assembler usage PIC32MZ

Author
Edocecrous
Second Job Wizard
  • Total Posts : 32
  • Reward points : 0
  • Joined: 2017/07/13 13:25:16
  • Location: Somewhere in Europe
  • Status: offline
2018/03/19 06:07:39 (permalink)
0

Inline assembler usage PIC32MZ

 
Hi, where can i get details on the inline assembly? Asked MPLABX to disassemble the code, and it wouldn't take back the exact same asm code that it showed me.
 
For this:
asm volatile("mfc0 %0, $9" : "=r"(periodbck));
I found: "mfcz dest-gpr, source" Stores the contents of the coprocessor register specified by the source in the general register specified by dest-gpr.
That's ok, so CP0 Register 9 contents go to %0. But it doesn't seem to work without the : "=r"(variable) part, which seems to add an instruction to move out the contents from %0 to 'variable'. 
 
I'm an x86 assembly programmer for xxx yers and getting a headache from this...
 
 
#1
Jim Nickerson
User 452
  • Total Posts : 6755
  • Reward points : 0
  • Joined: 2003/11/07 12:35:10
  • Location: San Diego, CA
  • Status: online
Re: Inline assembler usage PIC32MZ 2018/03/19 07:49:52 (permalink)
0
In the xc32 compiler users guide I find the Predefined MACROS section 17.4 quite useful
Also section 17.2 mixing assembly language and c variables.
 
#2
simong123
Lab Member No. 003
  • Total Posts : 1391
  • Reward points : 0
  • Joined: 2012/02/07 18:21:03
  • Location: Future Gadget Lab (UK Branch)
  • Status: offline
Re: Inline assembler usage PIC32MZ 2018/03/19 08:07:25 (permalink) ☼ Best Answerby Edocecrous 2018/03/19 10:35:42
5 (3)
The format of GCC inline assembly is convoluted. You need to look at the GCC docs at gnu.org for full documentation.
 
As for the example you give, the %0 is just a placeholder. The "=r"(periodbck) tells the compiler to write the value %0 to the register periodbck. If periodbck is delcared as a register variable, it will do just that. If not it has to write it out to memory, so you get the extra SW (or SH or SB) instruction. Remember MIPS is a load-store architecture, you cannot store a result direct to memory like on an x86, it has to go via a register.
You could just write for example
asm volatile("mfc0 $a0,$9")
to write direct to a register, however the compiler won't know you've done that, so you may clobber something in use (which is the reason for the "=r" format).
 
 
For a full opcode description download MD00086-2B-MIPS32BIS-AFP-06.02.pdf from the imgtec website.
#3
Jump to:
© 2020 APG vNext Commercial Version 4.5