Menu

#1 Accessing peripheral registers using Register addressing

1.0
closed
2014-05-26
2014-05-26
Jonam
No

Your article on Port Access in the Programmer's Reference is incorrect in that you do not need to use Extended addressing to control the ports on the eZ8. You can use simple register addressing using the LD instruction as long as you set up the Register Pointer using the SRP command to point to the start of the block of 16 registers of the peripheral you want to control.

If you have more than one register to change this becomes code and cycle efficient effectively halving the time taken to set up registers. For example:

    SRP   0DFH    ; Set register pointer to address 0FDxH (2 execution cycles, 2 fetch, 2 bytes of memory)
    LD    R8,#10H ; Set register 0FD8H to 10H (2 execution cycles, 2 fetch, 2 bytes of memory)
    LD    R9,#EFH ; Set register 0FD9H to EFH (2 execution cycles, 2 fetch, 2 bytes of memory)

Total of 6 execution cycles in 6 bytes to program two registers. If you exclude the SRP instruction, it is 4 cycles in 4 bytes. This compares to the LDX equivalent as:

    LDX    0FD8H,#10H    ; 2 execution cycles, 4 fetch and 4 bytes of memory
    LDX    0FD9H,#EFH    ; 2 execution cycles, 4 fetch and 4 bytes of memory

This takes a total of 8 cycles because of the longer fetch cycles and also increases the memory required.

Discussion

  • Koen van Vliet

    Koen van Vliet - 2014-05-26

    Hello Jonam,

    Thank you for pointing out this optimization trick. Can I use your example in the article?

    Kind regards

     
  • Jonam

    Jonam - 2014-05-26

    Koen,

    Of course you may use this example - happy to help. I am re-learning this processor after many years and there seems to be little information apart from Zilog's forums (which are generally very quiet anyway) so I was glad I found your tutorial pages.

    Regards

     
  • Koen van Vliet

    Koen van Vliet - 2014-05-26

    Hello Jonam,

    There are indeed very little tutorials out there. That is why I created this website and the tutorial pages. I am glad you found them useful.

    I modified the reference page here: http://ez8tut.sourceforge.net/?p=reference/port%20access.php#opt
    Thank you for contributing and good luck programming the eZ8 microcontroller.
    If you find more optimization tricks please share them.

    Kind regards

    Kind regards

     
  • Koen van Vliet

    Koen van Vliet - 2014-05-26
    • labels: --> Peripheral Register Addressing
    • status: open --> closed
    • assigned_to: Koen van Vliet
     

Log in to post a comment.