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
    Nov 2009
    Location
    London
    Posts
    251

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

    Can someone please advise what the following two statements mean (or doing) in the code? I have the code in assembly which I am converting to basic pro, but I don't have a clue what these statements are doing. They are extracted from the ISR routine.
    Code:
            
    movlw   ((INTHAND) >> 8)
    movwf   PCLATH

  2. #2
    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

    movlw ((INTHAND) >> 8) => Shift the constant (literal) 8 bits right (equivalent to dividing by 256) then put the value in WREG

    movwf PCLATH => Move the value in WREG into PCLATH.

    So, these two statement combined are putting INTHAND/256 into the the middle byte of the program counter.

  3. #3
    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

    Steve, but
    1)INTHAND is not a variable, in fact it is mentioned in the statement
    Code:
    define      INTHAND     _ISR
    2)What is the basic purpose of loading value in PCLATH

    cheers

  4. #4
    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

    Quote Originally Posted by Megahertz View Post
    Steve, but
    1)INTHAND is not a variable, in fact it is mentioned in the statement
    Code:
    define      INTHAND     _ISR
    Yes, you are right. But I didn't say it was a variable.


    2)What is the basic purpose of loading value in PCLATH
    The PCLATH is used (along with PCLATU) to make changes to the Program Counter, which is akin to directing the the program to a new location in the code: a "Computed GOTO."

  5. #5
    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

    I am confused, you said
    Shift the constant (literal) 8 bits right (equivalent to dividing by 256) then put the value in WREG
    Where is the constant here?

  6. #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,604


    Did you find this post helpful? Yes | No

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

    I really suck at assembly programming but I'm going to say (write) what I think, then hopefully someone will correct me if I'm wrong.

    The constant in this case is called INTHAND which is defined to contain the adress, in program memory, where the routine _ISR is located. What happens is that PCLATH (the high byte of the program counter) gets loaded with the 8 high bits of the adress of _ISR. I suspect there's also code to take the low 8 bits and put them in PCLATU. All in all, that would cause the program to jump to _ISR.

    After reading SteveB's other posts that's my understanding of it but again I might very well be wrong.

    /Henrik.

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