[Starting User] Problem with the inline assembly

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[Starting User] Problem with the inline assembly

5,165 Views
Barth
Contributor I
Hi Everybody,

My probleme is very simple to explain. I hope it will not be harder to solve.
I'm develloping a very little function that needs to go very fast. Knowing that, I decide to write it directly in assembly code. My problem is that whenever I try to use global variables in this function (inside the asm brackets), the compiler sends the following error:

"Error: C18700 Unknown Opcode Operand Combination."

Here is part of my code :

unsigned char ucSampleIdx;

void IsrDecode (void){

__asm{
dbnz ucSampleIdx, FRAMING_ERROR
FRAMING_ERROR:
rti
}
}

Thanks in advance for your help
Labels (1)
Tags (1)
0 Kudos
7 Replies

748 Views
CrasyCat
Specialist III

Hello

I have a couple of question before I can answer here. It looks like the compiler consider your inline assembler instruction as invalid.

Which processor are you targeting (HC08, HC12, Coldfire, EPPC, ...)?
How is FRAMING_ERROR defined?
How is ucSampleIdx defined (or declared)?

CrasyCat

0 Kudos

748 Views
Barth
Contributor I
Thanks for your fast answer !

I am currently using a HCS08 microcontroler

The ucSampleIdx variable is defined before my first function (out of any brackets) as follows:

unsigned char ucSampleIdx

The FRAMING_ERROR label is only defined by the compiler/assembler and is designed just one instruction later.

Thx again
0 Kudos

748 Views
rocco
Senior Contributor II
Hi, Barth:

It may or may not be the problem, but there you have a space between "ucSampleIdx," and "FRAMING_ERROR" in your assembly instruction (at least in your original post). That would be an illegal syntax for a dbnz instruction.
0 Kudos

748 Views
Barth
Contributor I
Thank you !!

It seems like it is an adressing mode problem.
I am trying to use EXT adressing mode when it is not accepted.

That way I already solved a part of my problem, paying more attention to the documentation.

But now I wish to use another instruction (namely branch if bit is clear, brclr), it gives me the same kind of error:

Unknown Opcode Operand Combination: Opc.: BRCLR/Dst.: SP8/Src.: Bit0

for a function defined like that.

void function(void){

unsigned char ucStatusTmp = ucStatus;

__asm{
brclr 0,ucStatusTmp,WAIT_SYNCHRO_CLK
WAIT_SYNCHRO_CLK:RTI
}
}

Message Edited by Barth on 2006-08-18 01:00 AM

0 Kudos

748 Views
rocco
Senior Contributor II
Hi, Barth, this one is easier.

The variable "ucStatusTmp" is defined local to the function, so it should therefore be allocated on the stack. The only addressing mode available to the BRCLR instruction is direct (page-zero) addressing, so there is no way to address a variable on the stack (even if the stack is in page-zero).
0 Kudos

748 Views
Barth
Contributor I
Thanks to both of you I solved it all.
I still don't know how to allocate memory in HCS08 assembly... So that it could be recognized by the C compiler.

But anyway It is already a great thing that I get my application working.

Thank you
0 Kudos

748 Views
CompilerGuru
NXP Employee
NXP Employee
>I still don't know how to allocate memory in HCS08 assembly...
>So that it could be recognized by the C compiler.

Actually the point is that for the HC08 you have to differentiate between variables (memory) allocated in the zero page, and variables allocated outside of it.
In the SMALL memory model (which I guess you are using) variables are extended (say non zero page allocated) by default. So if you want to allocate some into the zero page so that a DBNZ can use it (and not just a LDA), then use the following syntax:

#pragma DATA_SEG SHORT ZERO_PAGE
// assuming you prm file maps ZERO_PAGE
// to a memory area <= 0xFF
unsigned char zero_page_var;
#pragma DATA_SEG DEFAULT
unsigned char default_allocated_var;

You can now use with inline assembly instructions requiring direct (say zero page) addressing mode.

Daniel
0 Kudos