Sign in

username:

password:



Not a member?

Search 68hc12



Search tips

Subscribe to 68hc12



68hc12 by Keywords

68HC1 | 812A4 | 9S12DP256 | Bootloader | CodeWarrior | D60A | Debugger | DP256 | ECT | EEPROM | EVB | Flash | HC1 | HCS12 | I2C | IAR | ICC1 | Interrupts | LCD | M68KIT912DP256 | MC9S12DP256 | MC9S12DP256B | Metrowerks | Motor | MSCAN | Multilink | PLL | Quadrature | SDI | SPI | Transceiver | XFC

Ads

Discussion Groups

See Also

DSPFPGAElectronics

Discussion Groups | 68HC12 | confused by assembly produced by CW

Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).

confused by assembly produced by CW - Frank - Mar 29 11:08:04 2009

I have a C function that depending on how it's written will be compiled into assembly that does two different things. Below are the functions and the assembly produced. I'm using CodeWarrior 5.9. Can anyone tell me why it produces such different code (TransmitStart being the one that is doing what I intend)?

static uint16 transmitCnt_;
static uint8 *transmitBuf_;

static void TransmitStart(void)
{
uint8* buf = transmitBuf_;
transmitCnt_ = 1;
BDR = buf[0];
}

0000 de00 [3] LDX transmitBuf_
0002 c601 [1] LDAB #1
0004 87 [1] CLRA
0005 5c00 [2] STD transmitCnt_
0007 e600 [3] LDAB 0,X
0009 7b0000 [3] STAB _DLCBDR
000c 3d [5] RTS

static void TransmitStart2(void)
{
transmitCnt_ = 1;
BDR = transmitBuf_[0];
}

0000 c601 [1] LDAB #1
0002 87 [1] CLRA
0003 5c00 [2] STD transmitCnt_
0005 e6fb0000 [6] LDAB [transmitBuf_,PCR]
0009 7b0000 [3] STAB _DLCBDR
000c 3d [5] RTS

------------------------------------



(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )


Re: confused by assembly produced by CW - Edward Karpicz - Mar 30 2:10:05 2009

"Frank" wrote:

>I have a C function that depending on how it's written will be compiled
>into assembly that does two different things. Below are the functions and
>the assembly produced. I'm using CodeWarrior 5.9. Can anyone tell me why it
>produces such different code (TransmitStart being the one that is doing
>what I intend)?

Codes are equivalent. Why they are not the same? Only CW engineers can tell
you why their compiler and optimiser didn't generate exactly the same code.
However in your first routine you are requesting a read from transmitBuf_
pointer, then write to transmitCnt_, then read from data pointed by
transmitBuf_. In your second routine you write to transmitCnt_ first, then
read data pointed by transmitBuf_. No wonder different code is generated.
Are you asking why did TransmitStart2 produce PC relative instruction? Maybe
compiler gives priority to code that overwrites less registers? More chances
for reusage of values loaded to registers? I don't know, specific
optimization strategy, specific solution.

Edward
>
> static uint16 transmitCnt_;
> static uint8 *transmitBuf_;
>
> static void TransmitStart(void)
> {
> uint8* buf = transmitBuf_;
> transmitCnt_ = 1;
> BDR = buf[0];
> }
>
> 0000 de00 [3] LDX transmitBuf_
> 0002 c601 [1] LDAB #1
> 0004 87 [1] CLRA
> 0005 5c00 [2] STD transmitCnt_
> 0007 e600 [3] LDAB 0,X
> 0009 7b0000 [3] STAB _DLCBDR
> 000c 3d [5] RTS
>
> static void TransmitStart2(void)
> {
> transmitCnt_ = 1;
> BDR = transmitBuf_[0];
> }
>
> 0000 c601 [1] LDAB #1
> 0002 87 [1] CLRA
> 0003 5c00 [2] STD transmitCnt_
> 0005 e6fb0000 [6] LDAB [transmitBuf_,PCR]
> 0009 7b0000 [3] STAB _DLCBDR
> 000c 3d [5] RTS
> ------------------------------------

______________________________
Stellaris® MCU Family: New Parts, New Package, New Price.


(You need to be a member of 68hc12 -- send a blank email to 68hc12-subscribe@yahoogroups.com )