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

Inserting a single instruction

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



Joined: 22 Dec 2010
Posts: 5

View user's profile Send private message

Inserting a single instruction
PostPosted: Wed Dec 22, 2010 6:00 am     Reply with quote

I'm trying to insert a single jump instruction at address 0x100. I don't want anything at 0x101. I tried:
Code:
#org 0x100
#asm
#inline
void jump_to_prog() {
   GOTO 0x300
}
#endasm

and it generates this according to the disassembly listing:
Code:

10:                #org 0x100, 0x101
11:                #inline
12:                void jump_to_prog() {
13:                   #asm
14:                   GOTO 0x300
   100    2B00     GOTO 0x300
15:                   #endasm
16:                }
   101    3400     RETLW 0


Can I prevent the RETLW instruction from being inserted?
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Wed Dec 22, 2010 9:12 am     Reply with quote

Problem is that the syntax doesn't make sense if you think about it!...

#inline, means 'place this directly in the code sequence, without a call', but the ORG, says 'put this at this location. The latter, implies that it is called, and therefore has to have a return....

If you just want your code to jump to location 0x300, then why not just use 'goto_address(0x300)', this will be coded directly 'inline' where used, and will take you straight to the required address. If you want a NOP after the jump, then just put a delay_cycles(1) there.

Best Wishes
zzattack



Joined: 22 Dec 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Dec 22, 2010 10:10 am     Reply with quote

I put the #inline there to prevent any function calls being done to this function. I don't actually want a function there, I just want this particular instruction on this exact address. Also, I want specifically nothing after this instruction, not a NOP. Flashing the compiled hex file should result in 0x101 not being touched. Can I do that?
Ttelmah



Joined: 11 Mar 2010
Posts: 19553

View user's profile Send private message

PostPosted: Wed Dec 22, 2010 10:58 am     Reply with quote

You can put a word at a location, by just using a #ROM.
So:

#ROM 0x100={0x2B00}

Will generate the instruction you want. However '0x101', _will_ be affected, since this is the second byte of the instruction. 0x102, won't. Remember PIC instructions on a PIC16, are 14bits wide. Both address 100, and 101, are part of the one instruction....

Best Wishes
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Wed Dec 22, 2010 11:04 am     Reply with quote

zzattack wrote:
I put the #inline there to prevent any function calls being done to this function. I don't actually want a function there, I just want this particular instruction on this exact address. Also, I want specifically nothing after this instruction, not a NOP. Flashing the compiled hex file should result in 0x101 not being touched. Can I do that?


Depends...

I'm going to assume you're using an 18F part?

With the 18F, the GOTO is a 2 WORD instruction.

Yes. that 32bits!

The second instruction starts with a F which is a NOP but carries 12bits of address from the previous instruction. So with the 18F's, you can't have a goto that doesn't have a following NOP. Otherwise the destination address wouldn't cover the whole 21bit address range of some 18F's. (-1 bit because each location is 2 words, so the goto is word-aligned.)

Because you didn't mention which CPU you're using... You'll want to look at the instruction summary in the datasheet for your CPU.
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
zzattack



Joined: 22 Dec 2010
Posts: 5

View user's profile Send private message

PostPosted: Wed Dec 22, 2010 11:43 am     Reply with quote

This solves my issue, thanks guys. By the way: I meant the 0x101th word on a PIC16.
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