How does data get saved in the ram?

Go To Last Post
13 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i know that this is little endian, but a is 43.75 the hex value isn't 42 2f.
first avr-gcc program smiley bear with the noob if you may.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

first avr-gcc program

Why do you start off with float?  Floating point is usually reserved for when you have no other choice, want to execute calculations comparably slow (crawl), and use up your code space

 

If it uses IEEE754, this might help

https://www.h-schmidt.net/FloatConverter/IEEE754.html

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

Last Edited: Tue. Oct 15, 2019 - 10:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much for the fast response, i totally forgot about IEEE754. its a test program for school just to show how floating points are saved.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,  Welcome to AVR and embedded systems programming. 

 

Embedded systems programming (ESP) doesn't ever use the 'return' command like normal C programming on a PC.  In PC programming, doing return causes the program to end and "returns" to the PC command line.   ESP devices are always running the main program in a loop.  This final loop either does nothing {using a while(1) or loops back to either the beginning of main() or some test point in the code}.

 

This little test program declares a float and then changes its value 100 times.  But there is no way to see the result of its value change.   ESP devices often send the monitored value to the AVR's UART so that the user can see the result on the PC. 

 

Float values are stored in four bytes. I think that you want to look at how these four SRAM bytes change with each iteration of the FOR loop.  Arduino (which is a good place to start learning ESP) uses to the Serial library to send information from the AVR to the PC.  I suggest a working variation of this code:

 

#include Serial.h

 

float  myTestValue = 43.75;

uint16_t  myAddress = &myTestValue;

 

void setup() {

   Serial.begin(9600);

}

 

void loop() {

   for (uint8_t i = 0, i< 10, i++) {   //  small number of memory displays

       myTestValue += 0.01;

       for (uint8_t j = 0, j < 4; j++)  Serial.print(* (myAddress + j));   // show value in the four SRAM locations used for storing the float value

       Serial.print('\n');    // line feed on PC display

   }

 

(the code above is probably not exactly right, but shows the process for monitoring RAM output: corrections welcome)

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Simonetta wrote:
Embedded systems programming (ESP) doesn't ever (sic) use the 'return' command like normal C programming on a PC

Not true!

 

'return' is used exactly the same in embedded 'C' functions as elsewhere - the only exception is the special case of main().

 

And, in the special case of main(), it's not just about the specific 'return' statement - main() should generally not exit at all.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

If you do want to explore IEEE754 then I always find  https://www.h-schmidt.net/FloatConverter/IEEE754.html  to be very useful. As you'll see there your 43.75 will be stored in 4 bytes as 0x422f0000. So you were "half right" in identifying the 42 2F but the 00 and 00 are equally important in this. If it had been 422F0001 for example that would be 43.750004 in fact ;-)

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Now that's a function I have wished for on both the Windows and Linux calculators...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


barnacle wrote:
Now that's a function I have wished for on both the Windows and Linux calculators...

Your wish is granted:

SpeedCrunch http://speedcrunch.org/

SpeedCrunch is a high-precision scientific calculator featuring a fast, keyboard-driven user interface. It is free and open-source software, licensed under the GPL.

It's not much to look at, but it's my desktop calculator of choice in both Linux & Windows.

 

 

As you can see it keeps a history - oh I recognise some baud-rate calculations I did last week.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

QCalc (GPLv2) is similar though couldn't locate a floating point representation function.

Cling is a FLOSS C and C++ interpreter.

 

Expressions in C-Syntax | QTools: QCalc Programmer's Calculator

Cling Documentation | GOREPL

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

"How does data get saved in the ram?"

Beowulf_NL wrote:
but a is 43.75 the hex value isn't 42 2f. [where a is a float]
first avr-gcc program 

Now, OP did say "gcc".  Yet for the "newbie" it might be worth saying "the float is stored in whatever format the toolchain deems appropriate".  Yes, IEE874 is in all probability the dominant format we'd normally run into.  Yes, GCC libraries/intrinsics use that for representation of float.  Yes, GCC for AVR has 32-bit floats, and 32-bit doubles.

 

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I hafta admit that the subject line of this thread sorely tempts me to reply, "By kneeling in prayer and accepting AVR as thy lord and master", but I really shouldn't.  devil  S.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:
Yes, IEE874 is in all probability the dominant format we'd normally run into.
Is that some new version of IEEE754 ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0


clawson wrote:

Is that some new version of IEEE754 ?

754, 874 -- whatever it takes to be saved.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.