This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Problem with mixing assembler and C

Hello,

I use DSK6711 and I want to branch to the value of variable entry but I branch to the label address.

This is my assembler code:

.global _Skok_entry_point
.ref _entry

_Skok_entry_point:

mvkl .S2 _entry, B0
mvkh .S2 _entry, B0
B .S2 B0
nop 5

and a piece of C code:

extern unsigned int entry=0;
extern void Skok_entry_point(void);

...

entry=2147483648;

Skok_entry_point();

...

now I want to branch to the address 2147483648(0x80000000) not to address label _entry. Does anybody know how to solve this problem?

Thanks,

  • I don't think you need the assembly, try this...

    void (*entry)(void) = ( void (*)(void) )2147483648;

    entry( );

    The first line defines a pointer to a function you wish to call and then assigns the value to it after casting the value to a pointer to a function of the proper type.  Then all you need to do is call the function using the pointer to the function just like any other function call.

    If you want to pass the value to the function then you will need to redifine the pointer declaration like this

    void (*entry)(unsigned long) = ( void (*)(unsigned long) )2147483648;

    entry( 0x80000000 );

    If you don't want to make the assignment at declaration time, you can always defer it to later like this

    entry = ( void (*)(void) )2147483648;

    or

    entry = ( void (*)(unsigned long) )2147483648;

    If you would like to make your code a little easier to read, use a typedef like this

    typedef void (*func_t)(void);

    func_t entry;

    entry = (func_t) 2147483648;

    entry();

    a similar apporach can be used for the function which takes a parameter.

    At least that's what your code and your comments look like you are attempting to accomplish.  If not, clarify a bit more and I'll try again.

    Regards,

    Jim Noxon

  • Hello,

    It works very good. Thank you very much Jim Noxon.

    Regards,