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.

Need Sample Delay Program in Assembly language for TMS320C6745

Other Parts Discussed in Thread: TMS320C6745

Hi,

   am using tms320c6745 kit, now i started writing the assembly coding for this processor in code composer studio. am doing led interfacing assembly code. toggling the led i have done through some instruction and i have checked the code by single step executing, led was blinking correctly. to run continuously i need 1 milli second delay program in assembly coding. i tried . but it not returning from the delay program.

Main Program:

Start    MVKL    0x0FFF0000,A2    
            MVKH    0x0FFF0000,A2
            STW        A2,*A1
            CALL    DELAY
            
            MVKL    0x00000000,A2    
            MVKH    0x00000000,A2
            STW        A2,*A1
            CALL    DELAY

Delay Program:

DELAY        MVKL    0x00007FFF,A3
                    MVKH    0x00007FFF,A3

Loop           SUB        A3,1,A3
                    NOP        3
                    B        Loop   

    My question is , once the code entered in delay it's not returning to main program . ( in 8051 we have RET instruction ) is their any other special instruction to return to main function. ?

Many Thanks,

Thiyagarajan.S

  • Thiyagarajan,

    My recommendations, in order of preference with 1 being the top preference:

    1. Write it in C, not assembly. Get it working in C. Then stop; your program is working and finished.

    2. Write it in C and set the compiler flag to keep the assembly file, then use the assembly file and call it your own.

    3. Write it in C, keep the assembly file, edit it to make it better in whatever way you would like, learning how the compiler writes assembly as you go. When you make your changes and they do not work, you can back up to what the compiler wrote to learn what your mistake was.

    4. To write in assembly from scratch, you need to study the CPU & Instruction Set Reference Guide in great detail, all the sections including the detailed explanations for the individual instructions and the details on the instruction architecture and pipeline operation. You will want to go through the C6000 Optimization Workshop material that is available on the Wiki and study the Student Guide plus do the labs that are supplied.

    Most of my learning of C6000 assembly is from reading what the compiler has written. Assume there are reasons for everything it does, although there are a few things you may be able to do when you can apply your own knowledge of constraints.

    CCS is what you would normally use to debug a program like your. Single-step into the failing subroutine and find out what it is doing that causes it to fail. Note the difference between the Source Single-step and the Assembly Single-step.

    Regards,
    RandyP

  • Hi Randy,

             I have done c program for led . it has working well. as per your advice i set an option to generate asm file. it generated. but its difficult to understand some syntax. Instead i studied instruction set and wrote the code for Led program in assembly language. i done a single stepping using assembly step into. perfectly its entering delay loop but its not returning from delay loop as long it staying their. this the problem i facing . here i attached my asm file for your  reference.

    1856.ASM_LED_C6745.asm

    Kindly am requesting you to check my project source file. tell about any correction .

    Thanks,

    Thiyagarajan.S

  • Interfering in discussion:

    Clue 1: see the not very user-friendly assembler implementation of CALL pseudo instruction in debugger (clue 1.1: see also far call trampolines)

    Clue 2: study CALLP instruction in C67x+ instruction set, forget CALL / RET traditional instructions pair scheme

    Clue 3: follow B3 register in C compiler-generated assembly code

  • Jakez,

    Thank you for joining the discussion.

    Thiyagarajan,

    Your post confirms my point that you should not be writing this simple algorithm in assembly. You must figure out how to understand the syntax that the compiler uses, at least for the C6000 opcodes (not for all the debug info starting with "dw...").

    And you had an assembly program from the C compiler that was working, then you made changes, and now it does not work. You have two ways to solve this problem (other than not programming in assembly, which is still my recommendation):

    1. Start over from the C compiler's assembly output and make your changes one-at-a-time. Test it after each change, then you will know which change made it fail. That will give you something to study to figure out what went wrong.

    2. With a simple function such as your delay function, you should be able to single-step into that function and continue single-stepping to find out what goes wrong. To be able to program in assembly, you must develop that skill in order to succeed. Again, my recommendation is to avoid that very difficult situation by keeping your C program that works and spend your time on the next part of your application.

    If your goal is to learn C6000 assembly programming, then you should start by learning the syntax and methods used by the C compiler's assembly output. It is nearly impossible to learn to do something like this by writing the program from the beginning and then not understanding why it does not work.

    Go back to the oldest training material you can find on the Wiki or on TI.com. Search for "C6000 assembly training" or "C6000 workshop" (no quotes) or other combinations to find archived training classes. TI used to teach assembly programming, but we found that 1) our customers preferred to write in C using the excellent optimizer in our compiler and that 2) assembly is too difficult to write and teach and use in the C6000 architecture - C works very well, assembly is not the best path to success in most cases.

    Regards,
    RandyP

  • Hi,

    Thanks to jakez and randyp.

    ya i studied about the CALLP instruction ( in CPU and Instruction set guide, it wont have example for CALLP Instruction) and i used . but it showing some error . how i over come this .? please help. i attached the program which i used CALLP instruction and i attached the error message also.

    Program: 8357.ASM_LED_C6745.asm

    Vector : 2867.vectors.asm

    Error Message:

    Error in console window:
    
    
    'Building file: ../ASM_LED_C6745.asm'
    'Invoking: Compiler'
    "C:/Program Files/Texas Instruments/ccsv4/tools/compiler/c6000/bin/cl6x" -mv6700 -g --include_path="C:/Program Files/Texas Instruments/ccsv4/tools/compiler/c6000/include" --diag_warning=225 --preproc_with_compile --preproc_dependency="ASM_LED_C6745.pp"  "../ASM_LED_C6745.asm"
    "../ASM_LED_C6745.asm", ERROR!   at line 19: [E0800] Instruction invalid for
                                                         C6700
    				CALLP	Delay,B3
    
    "../ASM_LED_C6745.asm", ERROR!   at line 25: [E0800] Instruction invalid for
                                                         C6700
    				CALLP	Delay,A3
    
    "../ASM_LED_C6745.asm", ERROR!   at line 31: [E0800] Instruction invalid for
                                                         C6700
    				CALLP	Delay,A3
    
    "../ASM_LED_C6745.asm", ERROR!   at line 37: [E0800] Instruction invalid for
                                                         C6700
    				CALLP	Delay,A3
    
    4 Assembly Errors, No Assembly Warnings
    
    Errors in Source - Assembler Aborted
    
    >> Compilation failure
    C:\Program Files\Texas Instruments\ccsv4\utils\gmake\gmake: *** [ASM_LED_C6745.obj] Error 1
    'Building file: ../vectors.asm'
    'Invoking: Compiler'
    "C:/Program Files/Texas Instruments/ccsv4/tools/compiler/c6000/bin/cl6x" -mv6700 -g --include_path="C:/Program Files/Texas Instruments/ccsv4/tools/compiler/c6000/include" --diag_warning=225 --preproc_with_compile --preproc_dependency="vectors.pp"  "../vectors.asm"
    'Finished building: ../vectors.asm'
    ' '
    C:\Program Files\Texas Instruments\ccsv4\utils\gmake\gmake: Target `all' not remade because of errors.
    Build complete for project ASM_LED_C6745

    CCS Error :

    Thanks,

    Thiyagarajan.S

  • Clue 4: CALLP is a C64+/C67+ instruction - see -mv option in compiler

  • Hi Jakez,

              yes you was correct. i changed as 6400+ then it took CALLP Instruction. again the same problem. Kindly go through my assembly code and tell why it is not returning from delay program. i done single stepping properly it reaching but once it entered . it not returning to main function.

    Asm Program: 4466.ASM_LED_C6745.asm

    Please Jakez help me in this.

    Thanks,

    Thiyagarajan.S

  • Clue 5: it's a good idea to terminate a function with a branch to caller. As RandyP said, take a look on C compiler-generated code (as I said, follow B3 register)

    Clue 6: Put an eye on your A3 register content (re-read CALLP description)

  • Hi Jakez,

                  slightly i modified the asm code. now it was working fine and my problem was solved. To return from delay routine  i used branch instruction. here  i attached my code. please go through it  and reply me because i want to know whether it is correct method to write or any other method is their to return from delay routine.

    New asm program: 2804.LED.ASM

    Thanks,

    Thiyagarajan.S

  • Clue 7: Should choose between Branch and CALLP - go back and re-read CALLP

    Clue 8: (optimization) CALLP includes 5 cycles delay

    Don't look below yet

    Problem possible solution 1 (C6x):

                MVKL    togx,B3
                MVKH    togx,B3
                B       Delay
                NOP     5
                
    togx:       MVKL    ...

                ...

    Delay:      MVKL    0x00FFFFFF,B0
                MVKH    0x00FFFFFF,B0
    Loop3:      SUB      B0,1,B0
          [ B0] B        Loop3
                NOP      5
                B        B3
                NOP      5

    Problem possible equivalent solution 2 (C64+/C67+):

                CALLP    Delay,B3
                MVKL     ...

               ...

    Delay:      MVKL     0x00FFFFFF,B0
                MVKH     0x00FFFFFF,B0
    Loop3:      SUB      B0,1,B0
          [ B0] BNOP     Loop3,5
                BNOP     B3,5

  • HI JAKEZ,

          now am ok. it's working fine. one more doubt is how to use sin function in assembly coding ?

    Thanks,

    Thiyagarajan.S

  • Clue 9: DSPs have no built-in trigonometrics (use TI C libs or C/asm lib FastRTS)

    Clue 10: (much) more C6x principles learning and asm practice can be necessary

  • Hi Jakez,

         am new to assembly. Kindly am requesting you to provide any example or sample project using sin function in assembly coding ?

    Thanks,

    Thiyagarajan.S

  • Sorry, no more clue.

    Some ending advice:

    Hand-coded C6x asm is mainly reserved for specific cases (for ex. speed critical DSP functions like FFTs, filters,...), when achieved performance is expected to be superior to that of C-compiler generated code, or (rarely) when a high-level language can't do the job (context switching in multi-threaded OS,...). As RandyP said, the C compiler is good but it can be defeated in some cases by the human compiler (which in turn can requires several days of compilation / optimization time and much more cafein).

    Most code in C6x (as in most processors today except tiniest ones) is written in high-level language like C.

    The knowledge of C environment and C/asm interface can be found in C compiler manual (spru187).

    Hand-coded asm programming examples can be found in TI libs source (FastRTS,...). See also TI manuals (spru198), and perhaps linear assembly for C6x (simpler).

    The C6x architecture and assembly is quite a big piece for a beginner, NOT the best choice without good knowledge of C, another DSP or a 32-bit processor assembly.