Jump to content
Sign in to follow this  

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:

  movlw 5;
  addwf _reg, W;
  xorlw  0x12;


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;


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


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)



Share this post

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

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.

Sign in to follow this  

  • Create New...