cancel
Showing results for 
Search instead for 
Did you mean: 

I have a question about the COSMIC C complier

hongluo
Associate II
Posted on December 27, 2004 at 02:10

I have a question about the COSMIC C complier

5 REPLIES 5
hongluo
Associate II
Posted on December 23, 2004 at 23:26

Hi!everybody!

I have a question about the COSMIC C complier.

When I use PA7^=1 and PA7=PA7^1,the disassembly is different.

The meaning that I think the two is the same.

But I don't understand why different ??

The following is my code ...and thanks.

Quote:

main.c:42 PA7^=1;

0x8083 0x0F0004 BTJF 0x00,#7,0x808a BTJF 0x00,#7,0x808a

0x8086 0x1E00 BSET 0x00,#7 BSET 0x00,#7

0x8088 0x2002 JRT 0x808c JRT 0x808c

0x808a 0x1F00 BRES 0x00,#7 BRES 0x00,#7

main.c:41 PA7=PA7^1;

0x8083 0x4F CLR A CLR A

0x8084 0x0F0000 BTJF 0x00,#7,0x8087 BTJF 0x00,#7,0x8087

0x8087 0x49 RLC A RLC A

0x8088 0xA801 XOR A,#0x01 XOR A,#0x01

0x808a 0x2602 JRNE 0x808e JRNE 0x808e

0x808c 0x2004 JRT 0x8092 JRT 0x8092

0x808e 0x1E00 BSET 0x00,#7 BSET 0x00,#7

0x8090 0x2002 JRT 0x8094 JRT 0x8094

0x8092 0x1F00 BRES 0x00,#7 BRES 0x00,#7

:-W

luca239955_st
Associate III
Posted on December 24, 2004 at 06:42

Hi,

how do you define PA7 and what version are you using?

The answer to your question is probably

When assigning an expression to a _Bool variable,

the compiler compares the expression against zero and assigns the

boolean result to the boolean variable.

See page 53 of the user manual for more details.

If, as I guess, you are trying to toggle a pin of PortA, your best option (smaller code) is to address the whole port at once, as shown in the exaple below:

[code]

_Bool

mailto:PA7@PADR:7

;

; 38 PADR^=1; (6 bytes only)

000e b600 ld a,_PADR

0010 a801 xor a,#1

0012 b700 ld _PADR,a

; 40 PA7^=1;

0014 0e0004 btjt _PA7,L6

0017 1e00 bset _PA7

0019 2002 jra L01

001b L6:

001b 1f00 bres _PA7

001d L01:

; 42 PA7=~PA7;

001d 0e0004 btjt _PA7,L21

0020 1e00 bset _PA7

0022 2002 jra L41

0024 L21:

0024 1f00 bres _PA7

0026 L41:

; 44 PADR=PADR^1;

0026 b600 ld a,_PADR

0028 a801 xor a,#1

002a b700 ld _PADR,a

; 46 PA7=PA7^1; (wrong, don't do it)

002c 4f clr a

btst _PA7

0030 49 rlc a

0031 a801 xor a,#1

0033 2704 jreq L61

0035 1e00 bset _PA7

0037 2002 jra L02

0039 L61:

0039 1f00 bres _PA7

003b L02:

[/code]

Regards,

Luca (Cosmic)

hongluo
Associate II
Posted on December 27, 2004 at 02:08

hongluo
Associate II
Posted on December 27, 2004 at 02:09

Hi everybody,

I can't post the question in the forum.

So I write my question in the attachments.

And thanks again. :)

[ This message was edited by: hongluo on 30-12-2004 03:49 ]

________________

Attachments :

Question.txt : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I0F3&d=%2Fa%2F0X0000000bVv%2FAxXij1IHK7fzpf.7xoYq_Igr42Sunl4aZ2oiLdu_c_0&asPdf=false
hongluo
Associate II
Posted on December 27, 2004 at 02:10