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.

Question about register usage in C called assembly code for C6000

Hi,

I write an assembly code function which is called by a C program for C6000 DSP. Although I have read the C call convention on spru187t.pdf, it is still not clear to me. For simplicity, I have two input parameters and one output parameter in function calling. This will use A4, B4 for input while A4 for output. What registers should I save in assembly code?

I notice that A0 to A9 are reserved by parent function while others reserved for child. I do not know what action in the assembly code to deal differently with those two group registers. Could you explain it to me?

Thanks,

  • Rather than write hand-coded assembly, you should consider implementing this function in linear assembly.  This is a level of programming abstraction that is between C and assembly.  Please see the chapter titled Using the Assembly Optimizer in the C6000 C manual.  Among other benefits, you can use the directives .cproc and .endproc around your assembly function, and that will take care of all these register convention details for you.  

    For now, I presume you still want to implement in hand coded assembly.

    Robert W said:
    What registers should I save in assembly code?

    Please show me the C prototype for this assembly function.  Then I can show you which registers will have the input parameters and which register to use to return the result.

    Robert W said:
    I notice that A0 to A9 are reserved by parent function while others reserved for child.

    Any register noted as preserved by parent can be modified in your assembly function without having to worry that you are messing up something in the calling function.  Try to avoid using any register noted as preserved by child.  If you do change one of those registers, you need to add code at the beginning and end of the function to save and restore it.

    Thanks and regards,

    -George

  • Thank you George!

    The main C code is like this:

    int main()
    {
    short ii=256;
    int dec_out[256/32];
    int trace_bk[256*2];
    int i;

    // initialize decoded data array
    for (i=0; i<256/32; i++)
    {
    dec_out[i]=0;
    }

    // call assembly decode algorithm
    vtbasmfunc(data_in, dec_out, trace_bk, ii, metrics);
    // print out decode data in hex, reversed bit format,
    for (i=0; i<256/32; i++)
    {
    printf("data_out[%d]=%X\n", i, dec_out[i]);
    }

    return 1;

    }

    In asm code, almost all registers are used. According to your reply, I have to save A10--A15, B10--B15

    STW B3, *B15--[2]
    STW B0, *B15--[2]
    STW B14, *B15--[2]
    STW B4, *B15--[2]

    STW A10, *B15--[2]
    STW A11, *B15--[2]
    STW A12, *B15--[2]
    STW A13, *B15--[2]
    STW A14, *B15--[2]
    STW A15, *B15--[2]
    STW B10, *B15--[2]
    STW B11, *B15--[2]
    STW B12, *B15--[2]
    STW B13, *B15--[2]
    STW B14, *B15--[2]
    STW B15, *B15--[2]          ; ????

    MV A4, in_data_ptr                                    ; short data pointer
    MV A6, trans_sta_ptr 
    MV B6, input_cnt
    SUB input_cnt,1, input_cnt                     ; account for BDEC

    .............

    LDW B15, *++B15[2]          ; ???????? How to save B15 itself?
    LDW B14, *++B15[2]
    LDW B13, *++B15[2]
    LDW B12, *++B15[2]
    LDW B11, *++B15[2]
    LDW B10, *++B15[2]
    LDW A15, *++B15[2]
    LDW A14, *++B15[2]
    LDW A13, *++B15[2]
    LDW A12, *++B15[2]
    LDW A11, *++B15[2]
    LDW A10, *++B15[2]

    LDW B4, *++B15[2]
    LDW B14, *++B15[2]
    LDW B0, *++B15[2]
    LDW B3, *++B15[2]

    On spru187t.pdf, it says that B15 is preserved by Child. I don't know how to do it in assembly code because B15 itself is stack pointer. Is there other method to save it?

    [quote]Please show me the C prototype for this assembly function.   [/quote

    I don't know the above code snippet is your required. Thanks.

  • Robert W said:
    On spru187t.pdf, it says that B15 is preserved by Child. I don't know how to do it in assembly code because B15 itself is stack pointer. Is there other method to save it?

    The SP (B15) is implicitly preserved by the convention that everything pushed on the stack is popped off before returning.

    Robert W said:
    vtbasmfunc(data_in, dec_out, trace_bk, ii, metrics);

    I think this is the assembly function you are calling from C.  It appears to not return any result, and none of the arguments are of type long, long long, or double.  Presuming that is all correct, here is how the arguments are passed:

    • A4 - data_in
    • B4 - dec_out
    • A6 - trace_bk
    • B6 - ii
    • A8 - metrics

    Thanks and regards,

    -George