Assembly Variables to C

Hi I am trying to catch exceptions that are causing me to crash. In the Startup.s assembly module, I have tags for: do_undefined_instruction: do_prefetch_abort: do_data_abort:

I am trying to set a variable that I can access later in main.c I have tried the following

[In Startup.c] .global source [during reset]

do_reset: ..... .equ myVar,5

However, I just get rubbish. I am thinking this is because Ram etc. i initialised in the later part of startup.s (?). However, I will need t set the variable before this happens. Any assistance would be greatly appriciated.

Reply to
nialldaly
Loading thread data ...

It's been a while since I tried to share data between asm and C. It's not difficult and your compiler/assembler manuals should tell you how to do it. Please look for that information.

By convention and during compiling/linking, a C file will publicize a global variable to all object modules by prepending an underbar character (decorating) before the C declared variable. Then you import the decorated variable name in your asm file. The flip side is true for declaring the variable in asm. Basically, C likes to see an underbar before each global variable at link time.

For example

in C:

int gVar = 1; // declared in global (module) scope

in asm:

.import _gVar // or whatever the means your compiler imports labels

An extremely helpful exercise is to take a C file that imports a C variable declared in another file, compile it while the asm output is turned on. Look at what is generated. It's the perfect model for what you want and the compiler did all the work for you.

JJS

Reply to
John Speth

ot

.

al

ted

e

al

e

the

Nice idea and a clean explanation :):)

Another point would be to have info regarding the stack, PC and also other processor registor info by having our own routines. That will help you in crash analysis .

Karthik.

Reply to
karthikbalaguru

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.