+ Reply to Thread
Results 1 to 5 of 5

Thread: Asembler Question...

  1. #1
    Licensed User johngb's Avatar
    Join Date
    Oct 2003
    Location
    Surrey, UK
    Posts
    1,340

    Default Asembler Question...

    I want to be execute a Call (or GoSub) from my code where the label I want to call is held as a Code address in RAM. To try and explain further... I have an array holding the addresses of a number of routines. I want to call these routines so that when the routines complete they will return to the calling routine.

    I cannot see how I can do this so what am doing at present is jumping to the routine using the following code. Note Addr is the label of the routine I want to call.

    Code:
                    Movff Addr + 1, PCLATH          ; Set PCH via PCLATH
                    Movff Addr, WREG                ; Can't write direct to PCL with movff
                    Movwf PCL                       ; Writing to PCL will also load PCLath
    RtnLabel:
    The called routines at present finish with a GoTo back to Rtnlabel but I would prefer they just did a Return. Is it possible to manipulate the stack so that when the routine finishes with a Return the prgram returns to RtnLabel?

    Hi, its great to see you visiting our forum. Why not try Proton Compiler for FREE?

    Download the FREE version of Proton Compiler, Its called Amicus18 and its available from HERE

    Already using proton Compiler??? Get rid of these pesky messages... get LICENSED USER STATUS


    JohnB


  2. If you're a Licensed user of PROTON DEVELOPMENT SUITE, apply for Licensed User Status to remove these pesky messages
     and get access to additional forum areas, Beta test downloads and more!

  3. #2
    Super Moderator fanie's Avatar
    Join Date
    Oct 2005
    Location
    Crime riddled ZA
    Posts
    8,019


    Default Re: Asembler Question...

    Hi John,

    What's the difference between what you want to do and just calling subroutines in a sequence ?
    Fanie
    FAZE
    73 de ZS6FAZ
    http://fanie.cambs.net
    Stick to pic

  4. #3
    Licensed User johngb's Avatar
    Join Date
    Oct 2003
    Location
    Surrey, UK
    Posts
    1,340


    Default Re: Asembler Question...

    What's the difference between what you want to do and just calling subroutines in a sequence ?
    Everything, I am developing a real time operating system for PDS. This means that the user can write code in the form of tasks and the OS will run those tasks at appropriate times. To do this I keep a list of all the tasks (subroutines) in a table and then when the right conditions are met I run the appropriate task which means calling that task.

    Its a bit more complicated than that but that's the gist of it. I would rather the tasks return to the OS rather than jumping to a fixed label as I have implemented at present.
    JohnB

  5. #4
    Super Moderator wastrix's Avatar
    Join Date
    May 2008
    Location
    Sydney, Australia
    Posts
    2,555


    Default Re: Asembler Question...

    The called routines at present finish with a GoTo back to Rtnlabel but I would prefer they just did a Return. Is it possible to manipulate the stack so that when the routine finishes with a Return the prgram returns to RtnLabel?
    Something like this should work:
    Code:
    main:
        'etc.
        Asm-
        ;setup return address
        Push
        Movlw   ReturnLabel & 255
        Movwf   TOSL
        Movlw   (ReturnLabel >> 8) & 255
        Movwf   TOSH
        Movlw   (ReturnLabel >> 16) & 255   ;writing upper byte not necessary with < 64K program memory
        Movwf   TOSU
        Endasm-
        ;branch to subroutine
        GoTo subroutine
    ReturnLabel:
        'etc.
    GoTo main
    
    
    subroutine:
        'etc.
        Return
    It's a bit messy, I don't know if this is the best way to do this, but we must manipulate the top of stack. The push instruction is there basically to increment the stack pointer, the actual value placed on the stack by push is overwritten by the correct return address before jumping to the subroutine. The return instruction in the subroutine will pop our modified value off the TOS and branch back to the return label. The stack pointer at this point is decremented back to where it was before and ready for the next call.
    "If you have an important point to make, don't try to be subtle or clever. Use a pile driver."
    - Winston Churchill
    If you want to contact me, please email me, don't PM me.

  6. #5
    Licensed User johngb's Avatar
    Join Date
    Oct 2003
    Location
    Surrey, UK
    Posts
    1,340


    Default Re: Asembler Question...

    Thanks - that's what I needed
    JohnB

+ Reply to Thread

Members who have read this thread : 7

Actions :  (Set Date)

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts