Two statements from assembly - trying to convert the code in PBasic Pro


Closed Thread
Results 1 to 14 of 14

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Del Rio, TX, USA
    Posts
    343


    Did you find this post helpful? Yes | No

    Default Re: Two statements from assembly - trying to convert the code in PBasic Pro

    In PBP, the label "ISR" will be annotated in assembly as "_ISR" as a literal (i.e. constant). It represents the address of the first instruction following the label in PBP. The address is a 21 bit address. The bottom 8 bits (low byte, bits 0-7) are directly readable/writeable. The high byte (bits 8-15) and upper byte (bits 16-20) can only be read/written through the registers PCLATH and PCLATU respectively

    So... You will likely see something like this as well:

    movlw ((INTHAND) >> 16)
    movwf PCLATU

    movlw INTHAND
    movwf PCL


    When PCL is written to, the contents of PCLATH and PCLATU are written to the Program Counter along with the value to the PCL. This will cause the instruction found at that address to be the next instruction executed.

    One other thing. Since INTHAND is a constant, ((INTHAND) >> 16) and ((INTHAND) >> 8) will be evaluated when the program is compiled. So, the actual assembly will only see an 8 bit value.
    Last edited by SteveB; - 14th June 2012 at 18:14. Reason: typos, clarification

  2. #2
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Two statements from assembly - trying to convert the code in PBasic Pro

    Thanks for all the replies. Though I somewhat understood what you have said above.
    I just to finally confirm what you have advised still applies as the following is the whole context saving code for PIC 16F676:
    Code:
    define      INTHAND     _ISR
    
    ' The main program starts here
    goto main
    
    ISR:
    asm
            movwf   wsave           ; Save WREG
            swapf   STATUS, W
            clrf    STATUS           ; Point to bank 0
            movwf   ssave           ; Save STATUS
            movf    FSR,w
            movwf    fsave          ; save FSR
            movf    PCLATH, W       ; Save PCLATH
            movwf   psave
    ; No problems in understanding up to here
    
            ; get ready to jump within the ISR page
            movlw   ((INTHAND) >> 8) ; Set PCLATH for jump
            movwf   PCLATH
    There is no PCL related statement in the context saving. Correct me if I am wrong, does INTHAND has address 4 stored in it?

  3. #3
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Two statements from assembly - trying to convert the code in PBasic Pro

    The PBP instruction you're looking for might be "goto INTHAND", but, I wonder if there's really any need to jump to another program area for interrupt handler code?

  4. #4
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Two statements from assembly - trying to convert the code in PBasic Pro

    Hello Mike, Yes you do need to go to another location of memory when interrupts get involved.
    I read the datasheet of the 16f676 and it does say the whole memory is only one page, so I don't know why PCLATH needs touching, I also checked the ISR routine example in the datasheet and it does not mentions anything about the PCLATH. Only saves WREG & STATUS.

  5. #5
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Two statements from assembly - trying to convert the code in PBasic Pro

    Hi Megahertz,

    Was the original assembly language program written for a 16F676? Also, what is the source for the original assembly language program, please?

    Cheerful regards, Mike

  6. #6
    Join Date
    Nov 2009
    Location
    London
    Posts
    251


    Did you find this post helpful? Yes | No

    Default Re: Two statements from assembly - trying to convert the code in PBasic Pro

    This was written for 16F676 only originally. The source I don't know but I got it from my friend at UNI, we both are trying to understand the context saving part of it.

Members who have read this thread : 0

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