compiler issue

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

compiler issue

Jump to solution
2,259 Views
frogman_sr
Contributor II
I am using the memcpy function with identical parameters in two different locations. However, looking at the assembly code, there is a difference bewteen the two. Here is the output from the list file:
 
This one works correctly
 470:    memcpy((uchar *)&flash_data,(uchar *)&Flash_Data_1,sizeof(flash_data));
 0002 95       [2]             TSX  
 0003 89       [2]             PSHX 
 0004 8b       [2]             PSHH 
 0005 450000   [3]             LDHX  @Flash_Data_1
 0008 89       [2]             PSHX 
 0009 8b       [2]             PSHH 
 000a ae07     [2]             LDX   #7
 000c 8c       [1]             CLRH 
 000d cd0000   [6]             JSR   memcpy
 0010 a704     [2]             AIS   #4
 
this one causes the mp to reboot
 477:      memcpy((uchar *)&flash_data,(uchar *)&Flash_Data_1,sizeof(flash_data));
 002b 95       [2]             TSX  
 002c 89       [2]             PSHX 
 002d 8b       [2]             PSHH 
 002e 450000   [3]             LDHX  @Flash_Data_1
 0031 89       [2]             PSHX 
 0032 8b       [2]             PSHH 
 0033 ae07     [2]             LDX   #7
 0035 cd0000   [6]             JSR   memcpy
 0038 a704     [2]             AIS   #4
 
The only difference is the CLRH followign the LDX #7 command. The memcpy function uses the HX register to store the length value of the data you are copying. Because the H register is not being cleared, my length value is garbage.
 
Is this a known bug? Are there any workarounds?
 
I am using CodeWarrior IDE version 5.7.0 Build 1932 for target MC9S08GT32. Thanks for any help you can give.
 
frogman_sr
Labels (1)
Tags (1)
0 Kudos
1 Solution
440 Views
frogman_sr
Contributor II

Both snippets were compiled at the same time within the same function, a couple of lines apart. Originally there were to different source addresses, but for comparison, I made them both the same. -CS08 was included in the compiler options.

I did forget to include stdio.h. But adding it appears not to have worked.

After looking over my pragma statements to place my source variables into specific memory locations, I appear to have left the SHORT modifier when I copied over my zeropage definition. After removing SHORT, everything is compiling fine.

Thanks for your help.

View solution in original post

0 Kudos
2 Replies
440 Views
CompilerGuru
NXP Employee
NXP Employee
Can you provide a compilable code snippet to show the wrong code pattern? Together with the options actually used.

Something which could explain it is that for the HC08 (as opposed to a HCS08), the last 16 bit argument is passed in A/X and not in H/X.
So did you compile the second snippet without -CS08?

Also make sure memcpy is NOT implicitely (or incorrectly) defined. Make sure you did include stdio.h before calling it.

Daniel
441 Views
frogman_sr
Contributor II

Both snippets were compiled at the same time within the same function, a couple of lines apart. Originally there were to different source addresses, but for comparison, I made them both the same. -CS08 was included in the compiler options.

I did forget to include stdio.h. But adding it appears not to have worked.

After looking over my pragma statements to place my source variables into specific memory locations, I appear to have left the SHORT modifier when I copied over my zeropage definition. After removing SHORT, everything is compiling fine.

Thanks for your help.

0 Kudos