I converted 2 consecutive Ints to a Real using a Copy instruction. So now I need to reverse this process. Convert a Real into 2 consecutive Int's. Is this possible and if so how?
You may need to swap word or byte data using the SWPB instruction since you're coming from a REAL. I've made it work before but don't have the logic in front of me presently to tell you how.
Going from 32 bits to 2 ints you loose 1 bit on the way because two ints has two bits total for sign. You can do it with unsigned int I guess. And also, why real and not dint? A real can be much larger than a dint even though they are both 32 bits.
Are you using signed or unsigned ints? What's the max of your real? Is the real always coming from a combination of two ints (it will always divide into two ints with no decimals)?
if you go from two uint (0-65535) to a real and then back, if the int's are on the larger side of the scale you'll loose information because of how a real works. See these two excellent posts on the subject:
If you go from signed integers to a dint (using 0-32767 as the range, ignoring negative numbers) and then back it will work and give the same numbers on both sides no matter what you put into it. Two uints (16bits x2) won't fit in a dint (31bits + sign).
I assume you are using 2 INTs to transfer the REAL to another processor ?
If so, COP will work for both conversions, since COP does absolutely nothing to the bit patterns, it will re-create the REAL
One picture shows REAL to INTs to REAL, the other shows INTs to REAL to INTs. In either case you should ignore the actual values of the "middle" tag, as you can see the bit patterns of the 2 INTs when copied into a REAL do not produce a valid REAL number, so you get the error -1.#QNAN, which means "not a number", but the end-to-end data is correct.