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 support@ccsinfo.com

|= or ||

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



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

|= or ||
PostPosted: Sun Mar 02, 2003 3:52 pm     Reply with quote

It appears that |= does not work very well on bits. Double the code and half the speed. Have I just written this incorectly?

.................... go_open |= CMD_go_open;
060C: MOVLW 00
060E: MOVLB 2
0610: BTFSC x69.4
0612: MOVLW 01
0614: MOVWF x7A
0616: MOVLW 00
0618: BTFSC x69.6
061A: MOVLW 01
061C: IORWF x7A,W
061E: XORLW 00
0620: BTFSS FD8.2
0622: GOTO 062C
0626: BCF x69.4
0628: GOTO 062E
062C: BSF x69.4
.................... go_open = go_open || CMD_go_open;
062E: BTFSC x69.4
0630: GOTO 0640
0634: BTFSC x69.6
0636: GOTO 0640
063A: BCF x69.4
063C: GOTO 0642
0640: BSF x69.4
___________________________
This message was ported from CCS's old forum
Original Post ID: 12283
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

Re: |= or ||
PostPosted: Sun Mar 02, 2003 6:31 pm     Reply with quote

|| is logical OR. It should be
go_open = go_open | CMD_go_open

Regards,
Mark

:=It appears that |= does not work very well on bits. Double the code and half the speed. Have I just written this incorectly?
:=
:=.................... go_open |= CMD_go_open;
:=060C: MOVLW 00
:=060E: MOVLB 2
:=0610: BTFSC x69.4
:=0612: MOVLW 01
:=0614: MOVWF x7A
:=0616: MOVLW 00
:=0618: BTFSC x69.6
:=061A: MOVLW 01
:=061C: IORWF x7A,W
:=061E: XORLW 00
:=0620: BTFSS FD8.2
:=0622: GOTO 062C
:=0626: BCF x69.4
:=0628: GOTO 062E
:=062C: BSF x69.4
:=.................... go_open = go_open || CMD_go_open;
:=062E: BTFSC x69.4
:=0630: GOTO 0640
:=0634: BTFSC x69.6
:=0636: GOTO 0640
:=063A: BCF x69.4
:=063C: GOTO 0642
:=0640: BSF x69.4
___________________________
This message was ported from CCS's old forum
Original Post ID: 12293
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: |= or ||
PostPosted: Sun Mar 02, 2003 7:07 pm     Reply with quote

I should have mentioned that these are boolean variables. All three of these expressions seem to work. It seems to be a weakness in the way the compiler optimizes code for boolean variables. I expected a logical OR to be used because these are boolean variables. I guess the way I want to do this does not really conform to ANSI C.

.................... go_close = go_close || CMD_go_close;
07F8: BTFSC x6F.7
07FA: GOTO 080A
07FE: BTFSC x7B.1
0800: GOTO 080A
0804: BCF x6F.7
0806: GOTO 080C
080A: BSF x6F.7
.................... go_close = go_close | CMD_go_close;
080C: MOVLW 00
080E: BTFSC x6F.7
0810: MOVLW 01
0812: MOVWF x81
0814: MOVLW 00
0816: BTFSC x7B.1
0818: MOVLW 01
081A: IORWF x81,W
081C: XORLW 00
081E: BTFSS FD8.2
0820: GOTO 082A
0824: BCF x6F.7
0826: GOTO 082C
082A: BSF x6F.7
.................... go_close |= CMD_go_close;
082C: MOVLW 00
082E: BTFSC x6F.7
0830: MOVLW 01
0832: MOVWF x81
0834: MOVLW 00
0836: BTFSC x7B.1
0838: MOVLW 01
083A: IORWF x81,W
083C: XORLW 00
083E: BTFSS FD8.2
0840: GOTO 084A
0844: BCF x6F.7
0846: GOTO 084C
084A: BSF x6F.7
___________________________
This message was ported from CCS's old forum
Original Post ID: 12295
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: |= or ||
PostPosted: Mon Mar 03, 2003 12:13 pm     Reply with quote

:=I should have mentioned that these are boolean variables. All three of these expressions seem to work. It seems to be a weakness in the way the compiler optimizes code for boolean variables. I expected a logical OR to be used because these are boolean variables. I guess the way I want to do this does not really conform to ANSI C.
--------------------------------------------------------------
Instead of declaring the variables as "shorts" (1 bit),
declare them as chars. Then it only uses 2 ROM words
for each line of source code in your example.
___________________________
This message was ported from CCS's old forum
Original Post ID: 12309
Hans Wedemeyer
Guest







Re: |= or ||
PostPosted: Tue Mar 04, 2003 9:45 am     Reply with quote

:=Instead of declaring the variables as "shorts" (1 bit),
:=declare them as chars. Then it only uses 2 ROM words
:=for each line of source code in your example.

Tried that and got gobbs of code... could you please post your example.

___________________________
This message was ported from CCS's old forum
Original Post ID: 12333
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: |= or ||
PostPosted: Tue Mar 04, 2003 12:55 pm     Reply with quote

:=:=Instead of declaring the variables as "shorts" (1 bit),
:=:=declare them as chars. Then it only uses 2 ROM words
:=:=for each line of source code in your example.
:=
:=Tried that and got gobbs of code... could you please post your example.
:=
----------------------------------------------------
You're right. For the logical OR, it does produce a lot
of code. I had assumed that his original post had a typo
and that he intended to compare two bitwise operations:
<PRE>
go_open |= CMD_go_open;
and this:
go_open = go_open | CMD_go_open;
<BR>
and not this:
<BR>
go_open |= CMD_go_open;
and this:
go_open = go_open || CMD_go_open;
</PRE>

My test was done after correcting his "typo" :)

<PRE>

0000 00273 .................... go_open |= CMD_go_open;
0014 0822 00274 MOVF 22,W
0015 04A1 00275 IORWF 21,F
0000 00276 ....................
0000 00277 .................... go_open = go_open | CMD_go_open;
0016 0822 00278 MOVF 22,W
0017 04A1 00279 IORWF 21,F
0000 00280 ....................
0000 00281 ....................
0000 00282 ....................
0000 00283 .................... go_open = go_open || CMD_go_open;
0018 08A1 00284 MOVF 21,F
0019 1D03 00285 BTFSS 03.2
001A 2820 00286 GOTO 020
001B 08A2 00287 MOVF 22,F
001C 1D03 00288 BTFSS 03.2
001D 2820 00289 GOTO 020
001E 3000 00290 MOVLW 00
001F 2821 00291 GOTO 021
0020 3001 00292 MOVLW 01
0021 00A1 00293 MOVWF 21

</PRE>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12343
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