• AVR Freaks

Hot!Is PAGESEL the same as movlp HIGH?

Page: 12 > Showing page 1 of 2
Author
upand_at_them
Super Member
  • Total Posts : 437
  • Reward points : 0
  • Joined: 2005/05/16 07:02:38
  • Location: Pennsylvania
  • Status: online
2020/04/25 04:32:03 (permalink)
0

Is PAGESEL the same as movlp HIGH?

Are these two the same?
 
pagesel MyFunction
call MyFunction

 
movlp HIGH MyFunction
call MyFunction

 
I notice that movlp throws a warning, but pagesel doesn't.
#1

33 Replies Related Threads

    crosland
    Super Member
    • Total Posts : 1939
    • Reward points : 0
    • Joined: 2005/05/10 10:55:05
    • Location: Warks, UK
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 05:50:38 (permalink)
    0
    Do you think it might help to say what the warning was?
    #2
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 06:34:11 (permalink)
    0
    Which PIC? (In particular, PIC16F or PIC18F)
    Which mode is the assembler in? (Absolute, or relocatable)
    As crosland asked, WHAT is the error reported?
     
    You would save a lot of time getting answers if you supplied this basic information.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 06:42:52 (permalink)
    5 (1)
    It has to be an enhanced mid range PIC device to have an MOVLP instruction. ;)
     
    upand_at_them
    Are these two the same?
     
    pagesel MyFunction
    call MyFunction

     
    movlp HIGH MyFunction
    call MyFunction

     
    I notice that movlp throws a warning, but pagesel doesn't.


    I think both will load the PCLATH register with the same value. With that being said, the latter version throws an "out of range" warning because the HIGH operator returns 8 bits but MOVLP accepts an operand of only 7 bits (0 to 127); i.e. there are only 7 implemented bits in PCLATH.
     
    Edit: Notice PAGESEL generates code fitted for the selected PIC device; e.g. some PIC devices use only 1 or 2 bits for paging, so it will generate only BSF/BCF instead of MOVLP.
     
    Edit2: As others said, it is generally best to mention the PIC device, copy 'n paste the warning/error message verbatim, etc.
     
    post edited by 1and0 - 2020/04/25 07:00:47
    #4
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 07:01:08 (permalink)
    0
    1and0
    It has to be an enhanced mid range PIC device to have an MOVLP instruction. ;)

    Good point!
     
    Edit: Notice PAGESEL generates code fitted for the selected PIC device; e.g. some PIC devices use only 1 or 2 bits for paging, so it will generate only BSF/BCF instead of MOVLP.

    No device that has a MOVLP instruction would bother, as that is always a single instruction, and doesn't corrupt W or affect any flags.

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #5
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 07:08:30 (permalink)
    5 (1)
    ric
    No device that has a MOVLP instruction would bother, as that is always a single instruction, and doesn't corrupt W or affect any flags.

    Agree. My point is PAGESEL is "universal" -- it can generate one, two, and even zero instruction, depending on the PIC device.
    #6
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 07:13:06 (permalink)
    0
    Agree.
    I assume "movlp HIGH MyFunction" is handled correctly by the linker in relocatable mode.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #7
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 07:36:20 (permalink)
    0
    ric
    I assume "movlp HIGH MyFunction" is handled correctly by the linker in relocatable mode.

    Yes, it can handle expression in the format of "[upper | high | low] relocatable_symbol + literal_offset".
    post edited by 1and0 - 2020/04/25 07:37:32
    #8
    upand_at_them
    Super Member
    • Total Posts : 437
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 07:49:04 (permalink)
    0
    I'm not sure if it's absolute or relocateable.  I haven't done much PIC assembly before.  I'm compiling for 16F1825 with MPASM.  More of a general question, I guess.  So pagesel is preferred?
     
    Here is my code.  I put the string stuff near the end of program memory.  It does work, but I wanted to write it so that when I expand the program beyond the small one here I won't be scratching my head for why it doesn't work.
     

    list p=16f1825, r=dec

    #include <p16F1825.inc>

    errorlevel -306 ; no page boundary warnings
    errorlevel -302 ; no bank 0 warnings
    errorlevel -202 ; no 'argument out of range' warnings

    __config 0x8007, 0x09c4
    __config 0x8008, 0x1eff

    stringnum EQU 0x0070
    stringindex EQU 0x0071
     
     
     
     
     
     
     
    org 0
    pagesel main
    goto main
    addwf PCL, f
     
     
     
     
     
     
     

    init
      movlb 2
      clrf LATA
      clrf LATC

      movlb 1
      clrf TRISA
      clrf TRISC
      movlw 104
      movwf OSCCON
     
     
     
     
     
     
     
      movlb 3
      clrf ANSELA
      clrf ANSELC

      clrf TXSTA
      clrf RCSTA
      bsf BAUDCON, 3
      bsf TXSTA, 2
      movlw 103
      movwf SPBRGL
      clrf SPBRGH
     
     
     
     
     
     
     
      movlb 1
      movlw b'01111100'
      movwf ADCON0
      movlw b'10010000'
      movwf ADCON1

      movlb 3
      bsf TXSTA, 5
      bsf RCSTA, 7
      bsf RCSTA, 4

      movlb 2
      bsf FVRCON, 0
      return

    main
      pagesel init
      call init
      pagesel uart_crlf
      call uart_crlf
      pagesel uart_crlf
      call uart_crlf
      movlw 0
      movwf stringnum
      pagesel uart_string
      call uart_string


    main_loop
    ; todo: take reading

    ; todo: display value

    ; todo: delay 1s

      pagesel main_loop
      goto main_loop


      org 0x1E00
    uart_crlf
      movlw 13
      pagesel uart_char
      call uart_char
      movlw 10
      pagesel uart_char
      call uart_char
      return

    uart_char
      movlb 0
      btfss PIR1, 4
      goto $-1
      movlb 3
      movwf TXREG
      return
     
     
     
     
     
     
     
    uart_string
      movf stringnum, w
      call getstringaddress
      movwf stringindex
    uart_string1
      movf stringindex, w
      call getstringchar
      addlw 0
      btfsc STATUS, Z
      goto uart_string2
      call uart_char
      incf stringindex, F
      goto uart_string1
    uart_string2
     
     
     
      return

    getstringaddress
      brw
      retlw string0-string0
      retlw string1-string0

    getstringchar
      brw
      string0: dt "This is string 0", 0Dh, 0Ah, 00h
      string1: dt "String 1", 0Dh, 0Ah, 00h

      end

    post edited by upand_at_them - 2020/04/25 08:01:05
    #9
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 08:08:19 (permalink)
    0
    upand_at_them
    I'm not sure if it's absolute or relocateable.  I haven't done much PIC assembly before.

    Your code is absolute, but MPLAB X defaults to relocatable mode.
     

    I'm compiling for 16F1825 with MPASM.  More of a general question, I guess.  So pagesel is preferred?

    Yes, but I prefer LCALL as it is less typing. ;)
     
     

    Here is my code.  I put the string stuff near the end of program memory.  It does work, but I wanted to write it so that when I expand the program beyond the small one here I won't be scratching my head for why it doesn't work.

    I like putting my lookup tables at top of program memory too.
     


    __config 0x8007, 0x09c4
    __config 0x8008, 0x1eff


    Use symbols defined in the .INC file.
     


    stringnum EQU 0x0070
    stringindex EQU 0x0071


    Use CBLOCK/ENDC to declare variables in absolute mode. Use the various UDATA and RES to reserve variables in relocatable mode.
     

    [/code]
    org 0
    pagesel main
    goto main
    addwf PCL, f
    [/code]

    The ORG directive is for absolute mode, and the CODE directive is for relocatable mode. That ADDWF is unreachable code. ;)
     


      movlb


    Use the BANKSEL directive instead. It is less error-pone and guarantee to work for relocatable mode; i.e. you do not know which data memory bank the linker will allocate the variable to.
     
    #10
    upand_at_them
    Super Member
    • Total Posts : 437
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 08:18:11 (permalink)
    0
    Thanks for all the advice!  The "ADDWF" at the top of the program was copied from a program I had that was written in a high-level language and the compiler produced the ASM, which I [mostly] copied.
    #11
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 08:36:57 (permalink)
    5 (1)
    upand_at_them
    Thanks for all the advice! 

    You're welcome.
     
    upand_at_them

      pagesel init
      call init
      pagesel uart_crlf
      call uart_crlf
      pagesel uart_crlf
      call uart_crlf


    See here -- use of LCALL will make this more readable.  There is no need to repeat PAGESEL (and waste code space) when PCLATH has not changed.
     
    upand_at_them

      org 0x1E00
    uart_crlf
      movlw 13
      pagesel uart_char
      call uart_char
      movlw 10
      pagesel uart_char
      call uart_char
      return


    getstringchar
      brw
      string0: dt "This is string 0", 0Dh, 0Ah, 00h
      string1: dt "String 1", 0Dh, 0Ah, 00h


    Use '\n' and '\r' instead of hard-coded 10/0Ah and 13/0Dh, respectively, for readability.
     
    Edit: Use '\0' instead of 00h for the null character.
     
    Edit2: That is, it can be written like this
    string0: dt "This is string 0\r\n\0"

    and yes, the null character has to be explicit.
     
    post edited by 1and0 - 2020/04/25 08:51:12
    #12
    upand_at_them
    Super Member
    • Total Posts : 437
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 08:56:57 (permalink)
    0
    1and0
    upand_at_them
    pagesel init
    call init
    pagesel uart_crlf
    call uart_crlf
    pagesel uart_crlf
    call uart_crlf


    See here -- use of LCALL will make this more readable.  There is no need to repeat PAGESEL (and waste code space) when PCLATH has not changed.

     
    I did that because I thought it was possible that "uart_crlf" could change PCLATH.  The way I wrote "uart_crlf" doesn't, but if I add CALL's or GOTO's in the future it could.  Right?  I was going with "just in case".
    #13
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 09:12:46 (permalink)
    0
    upand_at_them
    I did that because I thought it was possible that "uart_crlf" could change PCLATH.  The way I wrote "uart_crlf" doesn't, but if I add CALL's or GOTO's in the future it could.  Right?  I was going with "just in case".

    The safest way is to litter your code with PAGESEL, but keep in mind that takes code space and cycle time. ;)  Anyway, you just have to make sure the correct PCLATH is set prior to all CALLs and GOTOs.
     
    #14
    upand_at_them
    Super Member
    • Total Posts : 437
    • Reward points : 0
    • Joined: 2005/05/16 07:02:38
    • Location: Pennsylvania
    • Status: online
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 09:51:40 (permalink)
    0
    1and0The safest way is to litter your code with PAGESEL, but keep in mind that takes code space and cycle time. ;)

     
    This is why I got into assembly just now.  I have a program that uses an SD card with FAT, a 128x64 OLED display using software I2C, UART, and some other stuff.  I'm not done with it and I've already reached 4K in code.  I figured I should try assembly so that I could fit all of the features that I want.
    #15
    NorthGuy
    Super Member
    • Total Posts : 6085
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 10:45:31 (permalink)
    0
    There are several ways of managing PCLATH. Microchip recommends something of that sort:
     
    ; if calling function in the same page page
    call Function
     
    ; if calling function in some distant page
    pagesel Function
    call Function
    pagesel Home

     
    My take is different. I want my code to flow through page boundaries without problems, so there's no  home page - it may change all the time. So, I don't try to maintain PCLATH, and always set it  before use:
     
    pagesel Function
    call Function

     
    Now my code can flow freely and I don't care where the function is. I also get rid of the notion of home page completely.
     
    That's the general rule. Although I can break that rule and do as I see fit.
    #16
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 11:07:05 (permalink)
    5 (1)
    I also don't use the notion of a home page. But I do allocate "related" subroutines in the same page to reduce page switching; the same goes for variables in the same bank to reduce bank switching.
     
    #17
    NorthGuy
    Super Member
    • Total Posts : 6085
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: online
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 11:38:13 (permalink)
    0
    1and0
    I also don't use the notion of a home page. But I do allocate "related" subroutines in the same page to reduce page switching;



    Yes. If you have a cluster of routines which are not related to outside, you can easily locate them all on the same page - pages are rather big. Then you don't need any pagesels at all.
     
    Or you can have virtual pages. If you use several pages, you can locate routines (actually not routines themselves, but rather jump instructions to routines) at known addresses within each page, then you just flip PCLATH, and the functionality of the PIC totally changes. Sort of several virtual PICs in one. And this also affects the "goto" from the interrupt vector, so each virtual PIC gets its own interrupt handler.
     
    #18
    1and0
    Access is Denied
    • Total Posts : 10780
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 12:44:44 (permalink)
    2 (1)
    When there's a subroutine located in another page that is called often, I'll use a springboard to launch to the actual subroutine; e.g,
    ;
    ; Page A
    ;
    PageA_Routine
            ; ...
            return

    ;
    ; Page B
    ;
    PageB_Routine
            lgoto   PageA_Routine
            ;...
           
            call    PageB_Routine  ; call PageA_Routine from inside PageB     
            ;...
            call    PageB_Routine
            ;...
            call    PageB_Routine
    post edited by 1and0 - 2020/04/25 12:48:39
    #19
    ric
    Super Member
    • Total Posts : 27022
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: offline
    Re: Is PAGESEL the same as movlp HIGH? 2020/04/25 15:48:18 (permalink)
    0
    Small instruction saver. Change the last CALL to a GOTO and drop the RETURN
    uart_crlf
      movlw 13
      pagesel uart_char
      call uart_char
      movlw 10
      pagesel uart_char
      call uart_char
      return

    To save another instruction, make sure "uart_char" follows this function in memory (which in your code, it does),
    and just fall into the uart_char code, losing the PAGESEL and the GOTO.
     
    For the string handling, use one of the FSR#/INDF# pairs as a string pointer.
    This has several immediate benefits.
    • The string doesn't have to be in the same page as the output function, it can be anywhere in memory.
    • The hardware manages incrementing the 16 bit pointer for you.
    • Fetching each character is a single instruction.
    • The zero flag is set appropriately straight after fetching each character.
     
     
     
    post edited by ric - 2020/04/25 15:49:26

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #20
    Page: 12 > Showing page 1 of 2
    Jump to:
    © 2020 APG vNext Commercial Version 4.5