Hi, Just trying to write an assembler function for the DSP56858, based on their example code on the SDK. Now, the prototype for it is something like long int myfunction(long int a, short int b, short int c) (all signed) and i was wondering with codewarrior, what registers does it actually put those values passed in. Also need to know what register it uses to pass data back out when I do the "rts". I know with the short int's b & c, they get put into x0, y1, but not sure with the long's.. If anyone knows, or can help me, can't seem to find anything in the reference manuals, or in any information from codewarrior. Cheers |
|
Slight dilemma
CodeWarrior "Targeting 56800E" manul covers calling
conventions. This is what it says: Calling Conventions and Stack Frames Passing Values to Functions The compiler uses registers A,B, R1, R2, R3, R4, Y0, and Y1 to pass parameter values to functions. Upon a function call, the compiler scans the parameter list from left to right, using registers for these values: The first two 16-bit integer values Y0 and Y1. The first two 32-bit integer or float values A and B. The first four pointer parameter values R2, R3, R4, and R1 (in that order). The third and fourth 16-bit integer values A and B (provided that the compiler does not use these registers for 32-bit parameter values). The third 16-bit integer value B (provided that the compiler does not use this register for a 32-bit parameter value). The compiler passes the remaining parameter values on the stack. The system increments the stack by the total amount of space required for memory parameters. This incrementing must be an even number of words, as the stack pointer (SP) must be continuously long-aligned. The system moves parameter values to the stack from left to right, beginning with the stack location closest to the SP. Because a long parameter must begin at an even address, the compiler introduces one-word gaps before long parameter values, as appropriate. Returning Values From Functions The compiler returns function results in registers A, R0, R2, and Y0: 16-bit integer values Y0. 32-bit integer or float values A. All pointer values R2. Structure results R0 contains a pointer to a temporary space allocated by the caller. (The pointer is a hidden parameter value.) Additionally, the compiler: Reserves R5 for the stack frame pointer when a function makes a dynamic allocation. (This is the original stack pointer before allocations.) Otherwise, the compiler saves R5 across function calls. Saves registers C10 and D10 across function calls. Does not save registers C2 and D2 across function calls. --- In , "shockdesignau" <rajesh.singh@s...> wrote: > Hi, > > Just trying to write an assembler function for the DSP56858, based > on their example code on the SDK. > > Now, the prototype for it is something like > > long int myfunction(long int a, short int b, short int c) (all > signed) > and i was wondering with codewarrior, what registers does it > actually put those values passed in. Also need to know what register > it uses to pass data back out when I do the "rts". > > I know with the short int's b & c, they get put into x0, y1, but not > sure with the long's.. > > If anyone knows, or can help me, can't seem to find anything in the > reference manuals, or in any information from codewarrior. > > Cheers |
|
Thanks for that, still seem to be having a problem..
Ok.. in my header I have
extern long myfunc(long a, short b, short c);
then in my assembly file
SECTION rtlib GLOBAL Fmyfunc
ORG P: Fmyfunc: clr A rts
ENDSEC END
That should logically return a zero everytime, but instead I’m getting some random number which is the number 5198, since a long is a 32bit number, so clearing A and returning it should be giving me back zero.
Is there something I’m missing?
Rajesh Singh
From:
help56800 [mailto:h...@yahoo.com]
CodeWarrior
"Targeting 56800E" manul covers calling
conventions. |
The answer will most likely be very obvious when looking at the actual
generated assember code. I'd rely on the real thing over the "rules
from the manual" any day of the week. That is not to say that those rules are
not followed or are inaccurate.
Howard
|
Message
Yeah I actually looked at the generated asm code from a C version of
the function i'm writing, somehow they passed it back to C (as in the
register), which didnt work when I tried it in pure
assembler.
So not sure whats going on, i tried every register to pass something
back, and no avail. Will keep trying anything else I can think
of...
If anyone else has any other ideas? :)
Rajesh Singh
|
FYI:
when using Codewarrior 6.1 and a target cpu of 568357, the "rules from
the manual" work as advertised.
in a "C" file I put the following code:
extern long myFunc(long a, int b, int c);
... long temp32;
... temp32 = myFunc(1000,10,20);
In another "C" file I put the following:
asm long myFunc(long a, int b, int c) {
//return (a + (L_mult(b,c));
mpy y1,y0,b ADD b,a rts After execution the value of 1400 was in the temp32
variable.
Dissassembly of the call yielded:
*** EXECUTABLE CODE (.text) ***
Address ObjectCode
Label Opcode
Operands
Comment
0x00000000
Fmain:
0x00000000 0xE40003E8 move.l #1000,A 0x00000002 0xE58A move.w #10,Y0 0x00000003 0xE794 move.w #20,Y1 0x00000004 0xE2540000 jsr 0x000000 ; FmyFunc 0x00000006 0xD07D0000 move.l A10,X:0x000000 ; Ftemp32 ... ...
*** RELOCATIONS (.rela.text) *** no
type
offset addend
symbol
1
R_56800E_CODE19 0x00000008
0x00000000 FmyFunc
2 R_56800E_LONG16 0x0000000B 0x00000000 Ftemp32 ... hope this helps!!!
Jerry.
________________________________________________________________________ This email has been scanned for all viruses by the MessageLabs SkyScan service. For more information visit http://www.messagelabs.com ________________________________________________________________________ |
|
Jerry,
Thanks for that, seems to work a lot better as inline assembly in a “C” file, then when I was doing it as an external assembly file, with a “C” defined header. Actually compiles and runs now.
Rajesh Singh From:
Johnson, Jerry [mailto:j...@giddings.com]
FYI: when using Codewarrior 6.1 and a target cpu of 568357, the "rules from the manual" work as advertised.
in a "C" file I put the following code:
extern long myFunc(long
a, int b, int c); long temp32;
temp32 myFunc(1000,10,20);
In another "C" file I put the following:
asm long myFunc(long a, int b, int c) {
//return (a
+ (L_mult(b,c)); After execution the value of 1400 was in the temp32 variable.
Dissassembly of the call yielded:
*** EXECUTABLE CODE (.text) ***
Address ObjectCode Label Opcode Operands Comment
0x00000000
Fmain: ...
no type offset addend symbol
1
R_56800E_CODE19 0x00000008
0x00000000
FmyFunc
hope this helps!!!
Jerry.
|