Hello BP,
Can you try with local declaration with "volatile char val1, val2" and try
(&val1 + 5)
Please update me on the results.
Hello Jim,
"I was referring to the local variable."
THe question BP put was whether he can replace below assembly with C code
" __asm ldhx 5,sp; // Return address on stack
__asm sthx PC_location; "
Nothing else . The question of converting the local to static didn't arise itself.To the BP's question I replied that assembly was necessary, to which you gave some answer which was no where near the answer expected.Seeing your answer why should I go mad or disturbed ?emotional ??!!??? No way!!!
"it is possible to get the address of the PC, if you do have a local, non static variable"
You never said the answer when it was really required and when someone gives them, claiming with confidence doesn't sound nice.I agree I am not right most of the time and so are you.
"A local variable is just scoping by the compiler. All variables are in RAM, it's just if you want to see it later.
If the variable is not static, and is on the stack, you really have no way to determine is address after the fact.
local variable, not static = on stack.
local variable, static = not on stack
"
Yes . You are right. All variables are physically on RAM, but segment wise locals on STACK segment while static and global on DATA segment(variables alive till the power is off).
But the benifits of going for stack space is that once you come out of that function those variables are removed (dereferenced) and the same memory can be used for other local variables.BUT in global/static(RAM) variables the memory is simply allocated permanently even if you use it just for a single time.So its better to go for locals and global/static used only when it is really required aka resuability concept.
To stop compiler optimization on a variable "volatile" keyword could be used.You are very much right.
" Sorry if I seemed to have annoyed you. You need to not take this so emotionally. It just some ideas to think about. I don't come here to get 5 star ratings, so rate me by how you feel, rather that what I say. You can't always be right, and if I am not the rate me 1. But at least take the time to try and understand what I say,."
You didn't annoy me.About trying to understand what you say, I assure you from today especially for your postings I try to do that sincerely
.But you should try to understand what others are asking rather than giving some wayward answers!!!
Really I was surprised to see 5 rating for myself.Just like you even I don't come here for 5 rating
Your friend,
Denn.