Reply by wilbur March 23, 20072007-03-23
Hi Harish,

Thanks for your inputs. That issue is now solved.
There were 2 reasons why the data was getting
corrupted. One was a coding error and the other
because I was not restoring the state of the circular
address register back to linear addressing. Thanks
anyway.

Regards,
Wilbur
--- Harish Kumar wrote:

> Wilbur,
>
> May be a late reply as I was on leave. Not looked in
> to what other folks had written. below are my
> thoughts
> about your problem.
>
> Compiler takes care of this in linear assembly.
> In case of interrupts with in those functions you
> need
> to take care of the registers, otherwise one need
> not
> bother about registers with in the scope of
> functions.
> By default the stack pointer is aligned. If your
> adressing is different, you just need to check the
> alignment. I think it is always word aligned.
>
> Corruption might be because of some misplaced logic
> in
> the code. Please review your code and reverify. I
> would like to have a look at the piece of code which
> is troubling you.
>
> Regards
> Harish
>
> --- wilbur wrote:
>
> > Hi All,
> >
> > A Correction to the data values getting
> corrupted...
> > The first byte of data is consistently getting
> > corrupted for the packed data.The second byte is
> > correct. I initially mentioned it as
> > > the upper two bytes of the LSB data and the
> lower
> > two bytes of my packed MSB data get corrupted.
> Sorry
> > bout tht if someone was thinkin bout this :)
> >
> > What sort of alignment needs to be done?
> >
> > Regards,
> > Wilbur
> >
> > --- wilbur wrote:
> >
> > > Hi All,
> > >
> > > What precautions does one need to take when
> > calling
> > > an
> > > assembly function within the scope of another
> > > assembly
> > > function in linear assembly. Does the compiler
> > take
> > > care of this? or do I have to store the values
> of
> > > the
> > > registers that I require?.
> > >
> > > Another question I have is...do I need to align
> > the
> > > stack pointer in anyway for C64xx when I enter
> and
> > > exit the assembly function? My data is getting
> > > corrupted in some way..specifically the upper
> two
> > > bytes of the LSB data and the lower two bytes of
> > my
> > > packed MSB data. To give you some more
> > > information..I
> > > call an assembly function from C. Inside this
> > > assembly
> > > function I call another assembly function which
> > does
> > > some scaling routine.Then I return to my program
> > in
> > > C.
> > > What I observe here is the next chunk of data
> i.e
> > > lets
> > > say the next 256 data values in my C program
> > itself
> > > has the alignment problem I described above!!
> Has
> > > anyone faced this issue? Any suggestions will be
> > > helpful. Thanks !
> > >
> > > Warm Regards,
> > > Wilbur
> > >
> > >
> > >
> > >
> >
> >
> >
> >
> ____________________________________________________________________________________
> > Bored stiff? Loosen up...
> > Download and play hundreds of games for free on
> > Yahoo! Games.
> > http://games.yahoo.com/games/front
> >
>
____________________________________________________________________________________
> Never miss an email again!
> Yahoo! Toolbar alerts you the instant new Mail
> arrives.
> http://tools.search.yahoo.com/toolbar/features/mail/
>

____________________________________________________________________________________
Sucker-punch spam with award-winning protection.
Try the free Yahoo! Mail Beta.
http://advision.webevents.yahoo.com/mailbeta/features_spam.html
Reply by Harish Kumar March 22, 20072007-03-22
Wilbur,

May be a late reply as I was on leave. Not looked in
to what other folks had written. below are my thoughts
about your problem.

Compiler takes care of this in linear assembly.
In case of interrupts with in those functions you need
to take care of the registers, otherwise one need not
bother about registers with in the scope of functions.
By default the stack pointer is aligned. If your
adressing is different, you just need to check the
alignment. I think it is always word aligned.

Corruption might be because of some misplaced logic in
the code. Please review your code and reverify. I
would like to have a look at the piece of code which
is troubling you.

Regards
Harish

--- wilbur wrote:

> Hi All,
>
> A Correction to the data values getting corrupted...
> The first byte of data is consistently getting
> corrupted for the packed data.The second byte is
> correct. I initially mentioned it as
> > the upper two bytes of the LSB data and the lower
> two bytes of my packed MSB data get corrupted. Sorry
> bout tht if someone was thinkin bout this :)
>
> What sort of alignment needs to be done?
>
> Regards,
> Wilbur
>
> --- wilbur wrote:
>
> > Hi All,
> >
> > What precautions does one need to take when
> calling
> > an
> > assembly function within the scope of another
> > assembly
> > function in linear assembly. Does the compiler
> take
> > care of this? or do I have to store the values of
> > the
> > registers that I require?.
> >
> > Another question I have is...do I need to align
> the
> > stack pointer in anyway for C64xx when I enter and
> > exit the assembly function? My data is getting
> > corrupted in some way..specifically the upper two
> > bytes of the LSB data and the lower two bytes of
> my
> > packed MSB data. To give you some more
> > information..I
> > call an assembly function from C. Inside this
> > assembly
> > function I call another assembly function which
> does
> > some scaling routine.Then I return to my program
> in
> > C.
> > What I observe here is the next chunk of data i.e
> > lets
> > say the next 256 data values in my C program
> itself
> > has the alignment problem I described above!! Has
> > anyone faced this issue? Any suggestions will be
> > helpful. Thanks !
> >
> > Warm Regards,
> > Wilbur
> >
> >
> >
> >
>
____________________________________________________________________________________
> Bored stiff? Loosen up...
> Download and play hundreds of games for free on
> Yahoo! Games.
> http://games.yahoo.com/games/front
>

____________________________________________________________________________________
Never miss an email again!
Yahoo! Toolbar alerts you the instant new Mail arrives.
http://tools.search.yahoo.com/toolbar/features/mail/
Reply by Andrew Nesterov March 11, 20072007-03-11
Hi Wilbur,

Most probably that the problem with incorrect alignement is
due to an incorrect address calculation or modification.

The rule of thumb for alignments is:

1 byte data addresses are aligned on 1 byte boundary
2 byte data addresses are aligned on 2 byte boundary
etc.

Stack pointer is always aligned on 8 byte boundary (see 8.1.2 note
and 8.5.1 of spru187n, two notes towards the end of the section).

I'd recommend to read spru187n chapter 8 Run-time environment,
sections
8.1.2 System stack
8.3. Register conventions
8.4. Function structure and calling conventions
8.5.1 Using assembly language modules

Please also note a funny cross-reference in sections 8.1.2 and 8.4.3
regarding the system stack :)

Hope this helps,

Andrew

> From: wilbur
> To: c...
> Sent: Wed, 7 Mar 2007 13:59:30 -0800 (PST)
> Subject: Re: [c6x] Calling Assembly within assembly
>
>> What precautions does one need to take when calling an
>> assembly function within the scope of another assembly
>> function in linear assembly. Does the compiler take
>> care of this? or do I have to store the values of the
>> registers that I require?.
>>
>> Another question I have is...do I need to align the
>> stack pointer in anyway for C64xx when I enter and
>> exit the assembly function? My data is getting
>> corrupted in some way..specifically the upper two
>> bytes of the LSB data and the lower two bytes of my
>> packed MSB data. To give you some more information..I
>> call an assembly function from C. Inside this assembly
>> function I call another assembly function which does
>> some scaling routine.Then I return to my program in C.
>> What I observe here is the next chunk of data i.e lets
>> say the next 256 data values in my C program itself
>> has the alignment problem I described above!! Has
>> anyone faced this issue? Any suggestions will be
>> helpful. Thanks !
>
Reply by wilbur March 11, 20072007-03-11
Hello Guys,
Thanks a lot for your inputs. Unfortunately or
fortunately the error was a coding error which was
overwriting those values. Also while using linear
assembly, I dont have to worry about the values of the
registers before calling the assembly function. I
guess the compiler takes care of this. Thanks again!

Regards,
Wilbur
--- Richard Williams wrote:

> 8 byte alignment, I don't know, I have seen plenty
> of C code from the Code
> composer that did not achieve the 8 byte alignment.
> In fact all they
> achieved was even address boundary.
>
> R. Williams
>
> ---------- Original Message -----------
> From: "Bhooshan Iyer"
> To: "Jeff Brower"
> Cc: Wilbur ,
> c...
> Sent: Thu, 8 Mar 2007 18:24:08 +0530
> Subject: Re: [c6x] Calling Assembly within assembly
>
> > Jeff--
> >
> > On 08 Mar 2007 04:21:10 -0800, Jeff Brower
> wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > > Wilbur-
> > >
> > > Richard), and keeping the stack pointer on
> 4-byte alignment.
> >
> > Isnt it 8 byte alignment for stack pointer that is
> reccommended by TI?
> >
> > -Bhooshan
> ------- End of Original Message -------

____________________________________________________________________________________
Bored stiff? Loosen up...
Download and play hundreds of games for free on Yahoo! Games.
http://games.yahoo.com/games/front
Reply by Richard Williams March 9, 20072007-03-09
8 byte alignment, I don't know, I have seen plenty of C code from the Code
composer that did not achieve the 8 byte alignment. In fact all they
achieved was even address boundary.

R. Williams

---------- Original Message -----------
From: "Bhooshan Iyer"
To: "Jeff Brower"
Cc: Wilbur , c...
Sent: Thu, 8 Mar 2007 18:24:08 +0530
Subject: Re: [c6x] Calling Assembly within assembly

> Jeff--
>
> On 08 Mar 2007 04:21:10 -0800, Jeff Brower wrote:
> >
> >
> >
> >
> >
> >
> > Wilbur-
> >
> > Richard), and keeping the stack pointer on 4-byte alignment.
>
> Isnt it 8 byte alignment for stack pointer that is reccommended by TI?
>
> -Bhooshan
------- End of Original Message -------
Reply by Bhooshan Iyer March 8, 20072007-03-08
On 3/9/07, Richard Williams wrote:
> 8 byte alignment, I don't know, I have seen plenty of C code from the Code
> composer that did not achieve the 8 byte alignment. In fact all they
> achieved was even address boundary.

For data I presume?

Iam talking specifically about the stack pointer. TI recommends that
it ALWAYS be aligned to 8byte boundary. I have a vague recollection of
why but wont go into it now.

--Bhooshan

>
> R. Williams
>
> ---------- Original Message -----------
> From: "Bhooshan Iyer"
> To: "Jeff Brower"
> Cc: Wilbur , c...
> Sent: Thu, 8 Mar 2007 18:24:08 +0530
> Subject: Re: [c6x] Calling Assembly within assembly
>
> > Jeff--
> >
> > On 08 Mar 2007 04:21:10 -0800, Jeff Brower wrote:
> > >
> > >
> > >
> > >
> > >
> > >
> > > Wilbur-
> > >
> > > Richard), and keeping the stack pointer on 4-byte alignment.
> >
> > Isnt it 8 byte alignment for stack pointer that is reccommended by TI?
> >
> > -Bhooshan
> ------- End of Original Message -------
--
-------------------------------
"I've missed more than 9000 shots in my career.
I've lost almost 300 games. 26 times I've been trusted to take the
game winning shot and missed.
I've failed over and over again in my life.
And that is why I succeed."
-- Michael Jordan
--------------------------------
Reply by Bhooshan Iyer March 8, 20072007-03-08
Jeff--

On 08 Mar 2007 04:21:10 -0800, Jeff Brower wrote:
> Wilbur-
>
> Richard), and keeping the stack pointer on 4-byte alignment.

Isnt it 8 byte alignment for stack pointer that is reccommended by TI?

-Bhooshan
Reply by Jeff Brower March 8, 20072007-03-08
Wilbur-

> What precautions does one need to take when calling an
> assembly function within the scope of another assembly
> function in linear assembly. Does the compiler take
> care of this? or do I have to store the values of the
> registers that I require?.
>
> Another question I have is...do I need to align the
> stack pointer in anyway for C64xx when I enter and
> exit the assembly function? My data is getting
> corrupted in some way..specifically the upper two
> bytes of the LSB data and the lower two bytes of my
> packed MSB data. To give you some more information..I
> call an assembly function from C. Inside this assembly
> function I call another assembly function which does
> some scaling routine.Then I return to my program in C.
> What I observe here is the next chunk of data i.e lets
> say the next 256 data values in my C program itself
> has the alignment problem I described above!! Has
> anyone faced this issue? Any suggestions will be
> helpful. Thanks !

Strongly advise to find a TI assembly code example that calls asm functions, then do
exactly as they do. It's important to follow overall compiler conventions, including
creating .bss space for local variables, using a stack frame (see other post by
Richard), and keeping the stack pointer on 4-byte alignment.

Also, make absolutely sure both asm functions are using only registers "permitted" by
the C compiler. This is well-explained in TI documentation.

Regarding your specific problem, does the first assembly program return to C
correctly? If so, and you call a second one that's just a "stub"; i.e. does nothing
but return, does it still work? If that works, can you call it 1000 times with no
issue? You can continue this type of step-by-step thinking as a 'debug strategy' and
you will soon find your problem(s).

-Jeff
Reply by Richard Williams March 8, 20072007-03-08
wilbur,

here is a thought
Have you checked to assure that something (just ahead of the corrupted bytes)
is perhaps getting written past the end of its' data area and thereby writing
on the first bytes of the array that is getting corrupted?

R. Williams

---------- Original Message -----------
From: wilbur
To: c...
Sent: Wed, 7 Mar 2007 13:59:30 -0800 (PST)
Subject: Re: [c6x] Calling Assembly within assembly

> Hi All,
>
> A Correction to the data values getting corrupted...
> The first byte of data is consistently getting
> corrupted for the packed data.The second byte is
> correct. I initially mentioned it as
> > the upper two bytes of the LSB data and the lower
> two bytes of my packed MSB data get corrupted. Sorry
> bout tht if someone was thinkin bout this :)
>
> What sort of alignment needs to be done?
>
> Regards,
> Wilbur
>
> --- wilbur wrote:
>
> > Hi All,
> >
> > What precautions does one need to take when calling
> > an
> > assembly function within the scope of another
> > assembly
> > function in linear assembly. Does the compiler take
> > care of this? or do I have to store the values of
> > the
> > registers that I require?.
> >
> > Another question I have is...do I need to align the
> > stack pointer in anyway for C64xx when I enter and
> > exit the assembly function? My data is getting
> > corrupted in some way..specifically the upper two
> > bytes of the LSB data and the lower two bytes of my
> > packed MSB data. To give you some more
> > information..I
> > call an assembly function from C. Inside this
> > assembly
> > function I call another assembly function which does
> > some scaling routine.Then I return to my program in
> > C.
> > What I observe here is the next chunk of data i.e
> > lets
> > say the next 256 data values in my C program itself
> > has the alignment problem I described above!! Has
> > anyone faced this issue? Any suggestions will be
> > helpful. Thanks !
> >
> > Warm Regards,
> > Wilbur
> >
> >
> >
>
Reply by Richard Williams March 7, 20072007-03-07
Here is a couple of key questions..

1) does the stack pointer have exactly the same value when it returns to the C
program as it did before the call to the assembly program?

2) are the Assembly programs defined with the Pascal interface or the C
interface? This makes a big difference on which program pushes parameters on
the stack. I.E before the call or upon entry to the assembly program.
The same program that pushed the parameters on the stack must be the same one
the pops them back off the stack.

It is a definite plus to use the 'stack frame' facility in your call/return
operations, so the stack pointer is not corrupted across calls/returns.

Yes, you have to handle the saving/restoring, in the assembly functions, of
any registers that are modified in the assembly function and then restore
those registers afterwards.

R. Williams

---------- Original Message -----------
From: wilbur
To: c...
Sent: Mon, 5 Mar 2007 11:22:36 -0800 (PST)
Subject: [c6x] Calling Assembly within assembly

> Hi All,
>
> What precautions does one need to take when calling an
> assembly function within the scope of another assembly
> function in linear assembly. Does the compiler take
> care of this? or do I have to store the values of the
> registers that I require?.
>
> Another question I have is...do I need to align the
> stack pointer in anyway for C64xx when I enter and
> exit the assembly function? My data is getting
> corrupted in some way..specifically the upper two
> bytes of the LSB data and the lower two bytes of my
> packed MSB data. To give you some more information..I
> call an assembly function from C. Inside this assembly
> function I call another assembly function which does
> some scaling routine.Then I return to my program in C.
> What I observe here is the next chunk of data i.e lets
> say the next 256 data values in my C program itself
> has the alignment problem I described above!! Has
> anyone faced this issue? Any suggestions will be
> helpful. Thanks !
>
> Warm Regards,
> Wilbur
------- End of Original Message -------