Searching \ for '[PIC] Passing Variables from HItech C to inline as' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=c
Search entire site for: 'Passing Variables from HItech C to inline as'.

Exact match. Not showing close matches.
PICList Thread
'[PIC] Passing Variables from HItech C to inline as'
2011\07\03@144132 by Tamas Rudnai

face picon face
I am just reposting it with the correct [PIC] tag...

---------- Forwarded message ----------
From: David Bley <spam_OUTdavbbleyTakeThisOuTspamyahoo.com>
Date: Sun, Jul 3, 2011 at 6:36 PM
Subject: [PIC[Passing Variables from HItech C to inline assembly
To: ".....piclistKILLspamspam@spam@mit.edu" <piclistspamKILLspammit.edu>


We have inherited a project running on a PIC16F505 at 4MHz.  The bulk of the
software is written in Hitech C with some inline assembler.  The original
code works (we have the original source and the original .hex and .cof
files.  We are unable to compile it with the latest version of Hitech C (no
optimization, free version) caused by passing a variable from a C routine
that calculates a number for a delay that is passed to an inline assembler
routine that performs the delay (approx 40 - 75us).  If I comment out the
inline assembly routine and replace it with a fixed delay routine using the
built in delay_us function, it compiles OK.  Any suggestions?  Sorry that I
am being so sketchy, but this is a proprietary product

2011\07\03@150056 by Jan-Erik Soderholm

face picon face


Tamas Rudnai wrote 2011-07-03 20:41:
> I am just reposting it with the correct [PIC] tag...
>
> ---------- Forwarded message ----------
> From: David Bley<.....davbbleyKILLspamspam.....yahoo.com>
> Date: Sun, Jul 3, 2011 at 6:36 PM
> Subject: [PIC[Passing Variables from HItech C to inline assembly
> To: "EraseMEpiclistspam_OUTspamTakeThisOuTmit.edu"<piclistspamspam_OUTmit.edu>
>
>
> We have inherited a project running on a PIC16F505 at 4MHz.  The bulk of the
> software is written in Hitech C with some inline assembler.  The original
> code works (we have the original source and the original .hex and .cof
> files.  We are unable to compile it with the latest version of Hitech C (no
> optimization, free version) caused by passing a variable from a C routine
> that calculates a number for a delay that is passed to an inline assembler
> routine that performs the delay (approx 40 - 75us).  If I comment out the
> inline assembly routine and replace it with a fixed delay routine using the
> built in delay_us function, it compiles OK.  Any suggestions?  Sorry that I
> am being so sketchy, but this is a proprietary product.
>

2011\07\03@211502 by Bob Blick

face
flavicon
face
> We have inherited a project running on a PIC16F505 at 4MHz.  The bulk of
> the
> software is written in Hitech C with some inline assembler.  The original
> code works (we have the original source and the original .hex and .cof
> files.  We are unable to compile it with the latest version of Hitech C
> (no
> optimization, free version) caused by passing a variable from a C routine
> that calculates a number for a delay that is passed to an inline
> assembler
> routine that performs the delay (approx 40 - 75us).  If I comment out the
> inline assembly routine and replace it with a fixed delay routine using
> the
> built in delay_us function, it compiles OK.  Any suggestions?  Sorry that
> I
> am being so sketchy, but this is a proprietary product.

You could post sections and we probably wouldn't know anything too
proprietary. Especially if you changed names to be generic.

Needless to say, there are a couple of ways of doing inline asm in
HiTech. In my old version you access C variables by prepending an
underscore to them, so a variable in C named Fred would be _Fred in asm.
And you can have one line of assembly all by itself like this:

asm("incfsz _inc1_2,w");

which is accessing the variable inc1_2

or you can do entire blocks of asm. What method does the code use? What
does the current HiTech users manual say about inline assembly (I can't
check because my version is old).

Best regards,

Bob

-- http://www.fastmail.fm - Access your email from home and the web

2011\07\04@062115 by cdb

flavicon
face
part 1 2798 bytes content-type:text/plain; charset="us-ascii" (decoded quoted-printable)

According to the Hitech manual for v9.80 as Bob says for inline assembler the following is correct.

Excerpt from page 92 of the manual.

unsigned int var;
void main(void)
{
var = 1;
#asm // like this...
BCF 0,3
BANKSEL(_var)
RLF (_var)&07fh
RLF (_var+1)&07fh
#endasm

However if the function is written in assembler and called from a C statement, things get a little more complicated.

From page 89.

The following are guidelines that must be adhered to when writing a routine in a
C-callable assembly routine.
? Select, or define, a suitable psect for the executable assembly code
? Select a name (label) for the routine using a leading underscore character
? Ensure that the routine?s label is globally accessible from other modules
? Select an appropriate equivalent C prototype for the routine on which argument
passing can be modelled
? Ensure any symbol used to hold arguments to the routine is globally accessible
? Optionally, use a signature value to enable type checking when the function is
called
? Write the routine ensuring arguments are read from the correct location, the return
value is loaded to the correct storage location before returning, if appropriate
? Ensure any local variables required by the routine have space reserved by the
appropriate directive
? Use bank selection instructions and mask addresses of symbols
? If the assembly routine calls other C functions or assembly routines, ensure the
compiler is aware of this using the appropriate directives.

Page 91 has, (aspic.h is a Hitech header file for assembly functions).

#include <aspic.h>

GLOBAL _add,?_add ; make _add globally accessible
SIGNAT _add,8298 ; tell the linker how it should be called
FNSIZE _add,0,4 ; this required 4 bytes of params; no autos
; everything following will be placed into the mytext psect
psect mytext,local,class=CODE,delta=2
; our routine to add to ints and return the result
_add:
; params are loaded by the calling function;
; we access them here using the special symbol
BANKSEL (?_add) ; select the bank of this object
MOVF BANKMASK(?_add+2),w ; take the LSB of the second param
ADDWF BANKMASK(?_add),f ; add to the LSB of the first param
BTFSC STATUS,0 ; check for carry
INCF BANKMASK(?_add+1),f ; handle carry
MOVF BANKMASK(?_add+3),w ; take the MSB of the second param
ADDWF BANKMASK(?_add+1),f ; add to the MSB of the first param
; the result is already in the required location so we can
; just return immediately
RETURN


Colin
--
cdb, @spam@colinKILLspamspambtech-online.co.uk on 4/07/2011
Web presence: http://www.btech-online.co.uk   Hosted by:  http://www.justhost.com.au
 This email is to be considered private if addressed to a named  individual or HR department, and public if addressed to a blog,  forum or news article.
 


part 2 181 bytes content-type:text/plain; name="ATT00001.txt"
(decoded base64)

--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
mailman.mit.edu/mailman/listinfo/piclist

2011\07\04@083049 by Gerhard Fiedler

picon face
cdb wrote:

> According to the Hitech manual for v9.80 as Bob says for inline assembler
> the following is correct. [...]
>
> However if the function is written in assembler and called from a C
> statement, things get a little more complicated. [...]

I always found it much easier to write a function definition in C and
fill it with inline assembly. No need to care about linker details etc.
(Unless, of course, you have a large body of assembly routines you need
to integrate, which I never had.)

Gerhar

2011\07\04@091448 by Isaac Marino Bavaresco

flavicon
face
Em 4/7/2011 09:30, Gerhard Fiedler escreveu:
> cdb wrote:
>
>> According to the Hitech manual for v9.80 as Bob says for inline assembler
>> the following is correct. [...]
>>
>> However if the function is written in assembler and called from a C
>> statement, things get a little more complicated. [...]
> I always found it much easier to write a function definition in C and
> fill it with inline assembly. No need to care about linker details etc.
> (Unless, of course, you have a large body of assembly routines you need
> to integrate, which I never had.)
>
> Gerhard


I usually write the function in C (alone in a source file), then compile
it to assembly (using the "-S" command-line switch).
I then discard (or save elsewhere) the C source file and add the
resulting ".s" file to the project and tweak the generated assembly code
to my needs.


Isaac

2011\07\04@093027 by Michael Rigby-Jones

flavicon
face


> -----Original Message-----
> From: KILLspampiclist-bouncesKILLspamspammit.edu [RemoveMEpiclist-bouncesTakeThisOuTspammit.edu] On
Behalf
{Quote hidden}

etc.
> (Unless, of course, you have a large body of assembly routines you
need
> to integrate, which I never had.)

It becomes awkward with PICC, since the symbols assigned to function
arguments and local variables will change if you change the number or
type of function arguments, or add/remove local variables (or change
their order).

This was probably one of the more disappointing aspects of PICC that I
found; it is far easier to use inline assembler with other vendors
compilers.

However, this is based on using what is now quite an old version; I have
not tried the latest versions of the compiler.

Regards

Mike

=======================================================================
This e-mail is intended for the person it is addressed to only. The
information contained in it may be confidential and/or protected by
law. If you are not the intended recipient of this message, you must
not make any use of this information, or copy or show it to any
person. Please contact us immediately to tell us that you have
received this e-mail, and return the original to us. Any use,
forwarding, printing or copying of this message is strictly prohibited.
No part of this message can be considered a request for goods or
services.
=======================================================================

2011\07\05@013925 by Gál Zsolt

flavicon
face
I am using SDCC. So it is little different from HiTech-C. Variables
using in inline assemby should be global variables there. You can try
it in your source code if it is not too complicated

More... (looser matching)
- Last day of these posts
- In 2011 , 2012 only
- Today
- New search...