howto: HLI varible,x (inline assembly using varible,X offset to tables of varibles)

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

howto: HLI varible,x (inline assembly using varible,X offset to tables of varibles)

跳至解决方案
3,175 次查看
CarlFST60L
Senior Contributor II

Hi All,

 

Should be very easy, I searched around for ideas for half hour and have given up on this very simple problem. I cannot work out how to get inline assembly to compile the address of a varible for use with an ,X offset.

 

- I know this code is useless here, but its important for our application as its doing 128 bit NLF's.

 

uchar test[32]  = 0;

 

__asm{

   LDHX #$0005

   LDA test:1,x  //< PROBLEM, will not compile "test" as an address using @ or & or a pointer to test.

}

 

Note: Using Codewarrior 6.1 and a HCS08 processor.

 

The problem is clearly that test is not being replaced as an address, I have tried everything i can think of. Code works straight away in straight assembly.

Message Edited by CarlFST60L on 2009-07-08 04:00 AM
标签 (1)
0 项奖励
回复
1 解答
1,075 次查看
CompilerGuru
NXP Employee
NXP Employee

I shortly wrote the small test below and I did not notice anything special with rol.

I wonder if you have a macro called rol? I would check the preprocessor output.

Otherwise please provide a full text example, best if including the project as well.

 

Daniel

 

BTW: I recomment not to use the __near qualified but instead mark the section as __SHORT_SEG.

This way the allocation and the way the variable is accessed are both at one place, the pragma.

Otherwise it is up to the programmer to make sure the two match.

 

 

 

 

#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGEstatic unsigned char buf[2];#pragma DATA_SEG DEFAULTvoid main(void) {  buf[0] = 0x2;  buf[1] = 0x4;  for(;;) {    __asm LDHX #1;    __asm ROL @buf,X    __asm AIX #-1    __asm ROL @buf,X    }}

 

 

 

在原帖中查看解决方案

0 项奖励
回复
8 回复数
1,075 次查看
pgo
Senior Contributor V

Dear CarlFST60L,

 

Tried the following 3 cases for a 9S08SH8 target:

 

 uchar test1[32] = {
   0
};

......

 

   asm {
      ldhx  #@test1 
      lda   5000,x


      ldhx  #5
      lda   @test1,x


      ldhx  #5
      lda   @test1:2,x
  }

Produced

   14:    asm {
   15:        ldhx  #@test1
  0000 450000   [3]             LDHX  @test1
   16:        lda   5000,x
  0003 d61388   [4]             LDA   5000,X
   17:        ldhx  #5
  0006 450005   [3]             LDHX  #5
   18:        lda   @test1,x
  0009 d60000   [4]             LDA   @test1,X
   19:        ldhx  #5
  000c 450005   [3]             LDHX  #5
   20:        lda   @test1:2,x
  000f d60002   [4]             LDA   @test1:2,X
   21:       
   22:       
   23:    }

 

which looks OK. Simulation also looks correct.

 

Using CW for microcontrollers V6.2. & whatever patches are current (6.2.2 I think!)

 

Have I missed something?

 

bye

Message Edited by pgo on 2009-07-08 01:55 PM
0 项奖励
回复
1,075 次查看
CarlFST60L
Senior Contributor II

Thanks for your quick reply. 

 

The solution was that you must define the varibles used in the HLI as global. The reason I didnt realise this was the the error just says "C18107: Illegal Operands" which is what you also get when you put the incorrect syntax.

0 项奖励
回复
1,075 次查看
CarlFST60L
Senior Contributor II

Well, all went fine until I came across one thing that doesnt work

 

... 

static uchar _near MyVar = 0;

...

void main(void){

 __asm{

...  

     rol MyVar,x           //This line just doesnt work, take off the ,x and it works 100%!

...

    }

...

 

I also noticed that the global varibles need to be declared as _near for paged instructions for anyone that came across this that was having similar problems.

0 项奖励
回复
1,075 次查看
bigmac
Specialist III

Hello,

 


CarlFST60L wrote:

Well, all went fine until I came across one thing that doesnt work

 

... 

static uchar _near MyVar = 0;

...

void main(void){

 __asm{

...  

     rol MyVar,x           //This line just doesnt work, take off the ,x and it works 100%!

...

    }

...

 

I also noticed that the global varibles need to be declared as _near for paged instructions for anyone that came across this that was having similar problems.


I suspect that the instruction might work if the static variable were to be placed within page zero RAM, although I haven't tried it.  Since 16-bit offset is not valid for this instruction, there would even be difficulty in writing normal assembly code.  Certainly the stack cannot be used with indexed addressing, but might be for non-indexed operation.

 

Regards,

Mac

 

 

0 项奖励
回复
1,075 次查看
CarlFST60L
Senior Contributor II

Thanks for the reply Bigmac,

 

I probably should have gone into more detail in my above example. Along with using __near, the varibles must be defined in zero page as you say (which i have)

 

#pragma DATA_SEG MY_ZEROPAGE

static uchar __near MyVar = 0;

#pragma DATA_SEG DEFAULT

 

This is what I had to do to get various similar commands to rol op,x to work, its just this one command. I am pretty sure that there is something wrong with the back end.

 

Unfortunately I cannot just do a work around in this case, I need this command is its critical to the 128bit NLF we have.

0 项奖励
回复
1,075 次查看
bigmac
Specialist III

Hello,

 

If you can't get the HLI code to meet your indexing requirements, another possibility would be to write your speed critical routine in "pure assembly", within a .asm file, and add this file to your project.  Your C function could now setup any parameters required, and then JSR to the assembly sub-routine using HLI.

 

Regards,

Mac

0 项奖励
回复
1,076 次查看
CompilerGuru
NXP Employee
NXP Employee

I shortly wrote the small test below and I did not notice anything special with rol.

I wonder if you have a macro called rol? I would check the preprocessor output.

Otherwise please provide a full text example, best if including the project as well.

 

Daniel

 

BTW: I recomment not to use the __near qualified but instead mark the section as __SHORT_SEG.

This way the allocation and the way the variable is accessed are both at one place, the pragma.

Otherwise it is up to the programmer to make sure the two match.

 

 

 

 

#pragma DATA_SEG __SHORT_SEG MY_ZEROPAGEstatic unsigned char buf[2];#pragma DATA_SEG DEFAULTvoid main(void) {  buf[0] = 0x2;  buf[1] = 0x4;  for(;;) {    __asm LDHX #1;    __asm ROL @buf,X    __asm AIX #-1    __asm ROL @buf,X    }}

 

 

 

0 项奖励
回复
1,075 次查看
CarlFST60L
Senior Contributor II

Thanks Daniel,

 

Thanks for the idea using __SHORT_SEG to, much nicer.

 

As you can see in my example I did not have the @ infront of the varible. I guess I now understand what the compilier expects. I couldnt see any details of this in the help files, but it all makes sense now.

 

 

Carl.

0 项奖励
回复