chipKIT® Development Platform

Inspired by Arduino™

Simplest way to use inline assembly

Created Wed, 14 Sep 2011 10:07:17 +0000 by drpap


drpap

Wed, 14 Sep 2011 10:07:17 +0000

I need to build a custom I/O library that uses bit-banging and would like to code a few inner loops in assembly (tried it in C and it works, but not fast enough).

What is the easiest way to code either a small subroutine in assembly or inline some assembly code within C code?


drpap

Thu, 22 Sep 2011 11:44:54 +0000

Bump - Any suggestions anyone? I know this is possible and have spend tons of hours searching for an answer/example, so any pointers would be appreciated.


WestfW

Fri, 23 Sep 2011 01:55:13 +0000

gcc has an inline assembler syntax that is relatively constant across the various architectures it supports. You'll have to figure out the MIPS M4K assembler, figure out how gcc has munged that, and look for some docs on specifics of the gcc inline assembler, and just do it... Looking at the "objdump -S" output is probably a good start.


jumpin_jack

Fri, 23 Sep 2011 02:05:07 +0000

There's some general info on GCC inline assembly here: http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s5

There's also some information on changing the chipKIT optimization level to -O3 -funroll-loops here: http://www.chipkit.org/forum/viewtopic.php?f=19&t=96


jumpin_jack

Fri, 23 Sep 2011 02:08:19 +0000

You might also want to check the bottom of the p32xxxx.h file for some examples of PIC32 inline assembly.


drpap

Sun, 25 Sep 2011 05:44:01 +0000

Thanks to all. This actually helped quite a bit. I am building a custom protocol between the Max and another micro controller and was planning on using assembly for speed.

After reading the material and digging into assembly for the PIC32 (MIPS instruction set) and writing the code in assembly, it turns out that the compiler can do a reasonably good job of efficiently generating code (provided that you access the registers directly with the LAT/SET/INV names as opposed to pinOutput). So I ended up using the inline assembly just to insert "nop" statements to tweak the timing.

Thanks again.