« Return to Thread: confused by assembly produced by CW

confused by assembly produced by CW

by Frank-185 :: Rate this Message:

Reply to Author | View in Thread

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


 « Return to Thread: confused by assembly produced by CW