CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using const tables from inline asm (#asm)

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asy777
Guest







Using const tables from inline asm (#asm)
PostPosted: Fri Jan 19, 2007 11:04 am     Reply with quote

Hi,
i've the following:

...
unsigned char const table[5]={1,2,5,2,3};
...

void main(void) {
...
...
#asm
some code...
movf some_reg,W
call &table[] <-- error
#endasm
...
...
}

The quiesiton is how can I use const tables from within #asm block?

Thanks.
Ttelmah
Guest







PostPosted: Fri Jan 19, 2007 11:18 am     Reply with quote

With a constant like this, with a lot of difficulty...
Declared like this, the 'table', is actually a complete program, which returns the selected item.
You don't say what chip?. If it is a 16 chip, then this is inherent in the hardware really. For a 18 chip, simply declare the table with a #ROM directive instead, at a fixed location, then in your assembler, a table read command can be used starting at this address.

Best Wishes
asy777
Guest







#asm
PostPosted: Fri Jan 19, 2007 11:25 am     Reply with quote

The chip is 16F690

this is asm listing for the table:
028 100A BCF 0xa, 0
029 108A BCF 0xa, 0x1
02A 110A BCF 0xa, 0x2
02B 0782 ADDWF 0x2, F
02C 340D RETLW 0xd
02D 3401 RETLW 0x1
02E 340D RETLW 0xd
02F 3409 RETLW 0x9
030 340D RETLW 0xd

Is there any other way to achieve this?
Is there a way to define label or something that will point to the begining of the table. I've tryed label_address() but didn't work.

Thanks.
asy777
Guest







#asm
PostPosted: Fri Jan 19, 2007 11:36 am     Reply with quote

I've tryed this:

#asm
code...
...
...
#endasm
ADCON=table[ScanIndex];
#asm
...code
...
#endasm

which produced the following:

...
015 300F MOVLW 0xf (other code)
016 05AD ANDWF 0x2d, F (other code)
017 0AA6 INCF 0x26, F (other code)
018 300F MOVLW 0xf (other code)
019 05A6 ANDWF 0x26, F (other code)

01A 0826 MOVF 0x26, W <-- this is ScanIndex var
01B 202A CALL 0x2a <-- the table
01C 00A1 MOVWF 0x21 <-- what is this? some local that i haven't define
01D 0821 MOVF 0x21, W <--
01E 009F MOVWF 0x1f <-- this is ok (ADCON0=...)

01F 2821 GOTO 0x21 ... other code ...

why the compiler generate such a nonsence? The optimization level is up to MAX. This is a ISR routine and is time critical. How can I work around this.

Thanks.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group