Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Assembly code in C? (http://www.chiefdelphi.com/forums/showthread.php?t=39032)

red_alert_13 21-07-2005 10:50

Assembly code in C?
 
I have a quick question: is it possible to use assembly code in C?

My experience was that in C++ (oh, how I miss C++), you could have code like this:

Code:

_asm
{
    /* Assembly code goes here */
}

I was wondering if the same thing would be possible with the compiler supplied by FIRST?

Thanks in advance!

Dave Flowerday 21-07-2005 11:54

Re: Assembly code in C?
 
Quote:

Originally Posted by red_alert_13
I was wondering if the same thing would be possible with the compiler supplied by FIRST?

This is called 'inline assembly' and is a nonstandard feature of most compilers, and they all seem to implement it in a slightly different way. Luckily, though, you don't have to look any further than the default code to find an example.

From ifi_startup.c:
Code:

void _startup (void)
{
  _asm
    /* Initialize the stack pointer */
    lfsr 1, _stack lfsr 2, _stack clrf TBLPTRU, 0 /* 1st silicon doesn't do this on POR */
    bcf  FPFLAGS,RND,0 /* Initialize rounding flag for floating point libs */

    /* initialize the flash memory access configuration. this is harmless */
    /* for non-flash devices, so we do it on all parts. */
    bsf 0xa6, 7, 0
    bcf 0xa6, 6, 0
  _endasm

loop:

    Clear_Memory();
  _do_cinit ();
  /* Call the user's main routine */
  main ();

  goto loop;
}                              /* end _startup() */

There's several other examples in that file as well.

red_alert_13 21-07-2005 13:23

Re: Assembly code in C?
 
Thanks for your response! That clears up a lot of questions.

red_alert_13 21-07-2005 15:01

Re: Assembly code in C?
 
Just in case anyone else might find assembly code useful, I found a link containing a list of commands - I'll have to test it but from the source code I've seen these are the commands used to program low level functions for the robot controller.

http://www.picbasic.co.uk/forum/showthread.php?t=222


All times are GMT -5. The time now is 04:42.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi