Using local variables in inline assembly for HiTech C PSoC

HiTech had a great compiler for PSoC's M8C processor, but, then they were bought by Microchip. Subsequently the HiTech forums were taken off line. At the request of PSoCDeveloper members PSoCDeveloper has created this forum to allow HiTech users to support each other.

Moderator: ericb

Using local variables in inline assembly for HiTech C PSoC

Postby baxsie » Tue Jun 02, 2009 3:55 pm

This is something I learned, then forgot, then found again, so I thought I would put it here so it can be found.

To use a "local" in inline assembly, use func_name@local_name:

asm("mov A,[func_name@local_name]");

Here is an example of using HiTech C Inline Assembly for the PSoC showing local variables used in inline assembly:
Code: Select all
unsigned short get_crc(unsigned char count,unsigned char *ptr)
  {
  unsigned short
    crc;   //Calculated CRC
  unsigned char
    i;     //Loop count, bits in byte
  unsigned char
    data;  //Current byte being shifted

  crc=0xFFFF; // Preset to all 1's, prevent loss of leading zeros

  do
    {
    data = *ptr++;
    i=8;
    do
      {
      if(((unsigned char)crc ^ data)&0x01)
        {
        //crc = crc >> 1 ^ POLY;
        asm("and   f, 0xFB");              //CLC
        asm("rrc   [get_crc@crc]");        //MSB
        asm("rrc   [get_crc@crc+1]");      //LSB
        asm("xor   [get_crc@crc],0x84");   //MSB
        asm("xor   [get_crc@crc+1],0x08"); //LSB
        }
      else
        crc >>= 1;
   
      data >>= 1;
      }while(--i);
    }while(--count);
  return (~crc);
  }
I'm not getting older. I'm getting bitter.
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Re: Using local variables in inline assembly for HiTech C PSoC

Postby chaitanyab » Fri May 14, 2010 2:53 am

Thanks Baxie this was important.

Where do u find such info? 8)
Help in PSOC Designer gives C-Programer's reference guide but it is from Image Craft.
Hi-Tech is no longer supported :!:
Is there any Hi-Tech C-Programer's Guide :?:

I am having one problem.

In ISR of PSOC we have ljmp to a C function.
//ljmp _Hall_ISR

Here the ljmp is in assembly or .ASM file.I need to do interrupt resolution here.Means Check which GPIO has caused the interrupt.So I need to store the status in one Assembly variable.
How to do this?
How to declare a Assembly variable in C Code's ISR so that the Compiler will understand :?: .
chaitanyab
Cheese Cube
Cheese Cube
 
Posts: 56
Joined: Mon Jan 04, 2010 4:17 am
Website: http://www.waveletgroup.com
Yahoo Messenger: chaitanya.bhalwankar@yahoo.com
Location: Pune India

Re: Using local variables in inline assembly for HiTech C PSoC

Postby IceCube » Wed May 26, 2010 5:30 am

Hi chaitanyab,

There's a HI-TECH manual in the folder "...Program Files\HI-TECH Software\HCPSOC\PRO\9.61\docs\manual.pdf"

If you want to use a variable within asm, you can declare it within C and access it within asm using an underscore, example
Code: Select all
unsigned char   shiftreg = 64;
#asm
asr [_shiftreg]
#endasm

Regards,
Rolf
User avatar
IceCube
The Big Cheese
The Big Cheese
 
Posts: 198
Joined: Thu Apr 20, 2006 11:47 pm
Website: http://www.nooteboom.biz
Location: Helmond, The Netherlands

Re: Using local variables in inline assembly for HiTech C PSoC

Postby chaitanyab » Wed May 26, 2010 11:50 pm

Oh Thank You ICE CUBE :D
Thank You Very Much :lol:
chaitanyab
Cheese Cube
Cheese Cube
 
Posts: 56
Joined: Mon Jan 04, 2010 4:17 am
Website: http://www.waveletgroup.com
Yahoo Messenger: chaitanya.bhalwankar@yahoo.com
Location: Pune India

Re: Using local variables in inline assembly for HiTech C PSoC

Postby IceCube » Thu May 27, 2010 12:02 am

you're welcome :)
User avatar
IceCube
The Big Cheese
The Big Cheese
 
Posts: 198
Joined: Thu Apr 20, 2006 11:47 pm
Website: http://www.nooteboom.biz
Location: Helmond, The Netherlands


Return to “%s” HiTech C User-to-User Support

Who is online

Users browsing this forum: No registered users and 1 guest