Jump to content
Sign in to follow this  
djulien

Accept "w" As L-Value Or R-Value

Recommended Posts

It would be very helpful if BoostC would accept "W" as an l-value or as part of an expression. This would cut down on the amount of asm statements needed considerably.

 

For example, if I need to evaluate an expression and pass it via W to a function, currently I need to write code like:

  asm
  {
  movlw 5;
  addwf _reg, W;
  xorlw  0x12;
}
func();

 

This is very ugly and non-portable. It would be a lot nicer and more portable to write the above as:

W = (reg + 5) ^ 0x12;
func();

 

As well as being more portable, this would also improve the readability of the code significantly.

 

Since there are no changes to the syntax rules, this feature would require only minor changes to the code generator. Basically, treat "W" (or maybe "WREG" or some other keyword) like a normal register or variable in the first pass of the compiler, and then simply omit instructions like

movf _W, W

and

movwf _W

in the code generator.

 

(There are a few other complications such as making sure "W = W ^ 0x10" reduces to "xorlw 0x10" instead of "movf _W, W; xorwf _W, F", but those are also fairly easy to handle in the code generator)

 

don

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×