Login

Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.

ARM Community: [Cortex-A8] beginner lost with simple floats - ARM Community

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

[Cortex-A8] beginner lost with simple floats Rate Topic: ***-- 1 Votes

#1 User is offline   AndresN 

  • Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 25-June 12

Posted 25 June 2012 - 04:28 PM

can anyone please explain to a beginner why a simple program (below) apparently corrupts the Locals (as seen in IDE, image below).
It doesn't seem to happen for integers, though.
Sure I'm doing something wrong, but what is it, and how to fix?
It's modified "startup_Cortex-A8", going emulator "startup-Cortex-A8-RTSM-example.launch" (otherwise all fresh installation)
int main(void)
{
  float A;
  float B;
  float C;
  float D;
  A = 1.2f;
  B = 2.3f;
  C = 3.4f;
  D = B + C;
  return 0;
}


Posted Image
0

#2 User is offline   scott 

  • Regular Contributor
  • PipPipPip
  • Group: Members.
  • Posts: 227
  • Joined: 05-October 06

Posted 26 June 2012 - 07:44 AM

What compiler and optimization level are you using?

The compiler is only required to make the sure the function behaves according to the standard -- this does not include debugging. Since your function returns 0, the variables A, B, C and D don't really affect anything and the compiler can eliminate them partially or completely if it wants. In fact, if you look in the Location column of the float case, you can see that B and C have both been put in the same register.

You can probably convince the compiler to keep the variables by taking their addresses and passing them to another function, e.g.
  printf("&A=%p, &B=%p, &C=%p, &D=%p\n", &A, &B, &C, &D);


1

#3 User is offline   AndresN 

  • Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 25-June 12

Posted 26 June 2012 - 08:11 AM

Thanks, Scott, you were so right!
Simply adding the printf made a difference.
And I can see they are in memory now (no more in registers)
Compiler and optimization level was armcc -O0 --cpu=Cortex-A8 -g -c -o"sorts.o" "../sorts.c"
Posted Image

View Postscott, on 26 June 2012 - 07:44 AM, said:

What compiler and optimization level are you using?

The compiler is only required to make the sure the function behaves according to the standard -- this does not include debugging. Since your function returns 0, the variables A, B, C and D don't really affect anything and the compiler can eliminate them partially or completely if it wants. In fact, if you look in the Location column of the float case, you can see that B and C have both been put in the same register.

You can probably convince the compiler to keep the variables by taking their addresses and passing them to another function, e.g.
  printf("&A=%p, &B=%p, &C=%p, &D=%p\n", &A, &B, &C, &D);



1

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic