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.

Multi-level Looping with Function Calls

Hi I am using a function (foo) call inside a main loop in assembly for C5515. The function (foo) itself has another loop. See the assembly code below. ;------------------------------------------ ; Loop 0 ;------------------------------------------ MOV #8, BRC0 . . . RPTBLOCAL _end_loop_0-1 . . CALL _foo . . _end_loop_0 ;------------------------------------------ ; end Loop 0 ;------------------------------------------ ;------------------------------------------------------ ; function foo ;------------------------------------------------------ _foo MOV #6, mmap(BRC1) ;------------------------------------------ ; Loop 1 ;------------------------------------------ RPTB _loop_1-1 . . . _loop_1 RET When the second function is called, the RSA0 and REA0 are overwritten by the start and end address of loop 1. So the code does not execute as intended. I appreciate if someone can direct me to get this done correctly. P.S. I tried branching (B) instead of (CALL) as well. Thanks, Shaminda
  • Sorry for the messy code. Please see the attached txt file.
  • Shaminda,

    You call the funciton inside the outer loop and the inner loop is in the function call. I don't think this is going to work. I have an idea to solve this problem but let me run a test first before getting back to you.  I will give you answer within this week.

    Best Regards,

    Peter Chung

     

  • Shaminda,

    If you really want to use a block repeat inside the subroutine, you should consider that loop as a outer loop, not inner loop. I made an example and verified it (see below). However, my question is why do you want to do this? You can add the subroutine insdie the blockrepeat without using "call". You may have a size problem? 

    Anyway, here is example that I have verified.

    ;function subroutine

    _foo

     PSH mmap(BRC0)
     PSH mmap(RSA0L)
     PSH mmap(RSA0H)
     PSH mmap(REA0L)
     PSH mmap(REA0H) 
         MOV #6, mmap(BRC0)
         RPTBLOCAL _end_loop_1-1
      nop
      nop
      MOV #1, AC0
      MOV #1, AC1
    _end_loop_1 
        POP mmap(REA0H)
     POP mmap(REA0L)
     POP mmap(RSA0H)
     POP mmap(RSA0L)
     POP mmap(BRC0)
     RET

    ;main loop

     MOV #8, BRC0
     nop
     nop
     RPTB _end_loop_0-1

     MOV #0, AC0
     MOV #0, AC1

      CALL _foo
      nop
      nop
      MOV #1, AC0
      MOV #1, AC1
       
    _end_loop_0

     

    Best Regards,

    Peter Chung

     

  • Thanks for the solution Peter.

    In our code, the subroutine is used in two  Viterbi decoders (1/2 and 1/3) for path and metric updates.  Subroutine itself is quite large, so we do not want to repeat it inside both 1/2 and 1/3 decoders as we are dealing with tight memory requirements.

    Best regards,

    Shaminda