A Bit of Vectrex History
From RoadsideThoughts ...
Home >> A Bit of Vectrex History >> Programmer NotesIndex...

Some Programming Considerations

Below are a few programming notes that might help when reading through these pages:

  • The address of the instruction that is being executed is located in the program counter (also called the 'PC' register). The contents of the program counter are incremented, byte-by-byte, as instructions are read. Keep in mind that instructions can consist of one or more bytes, depending on function and addressing modes.
  • When a subroutine is invoked with either a 'JSR' or 'BSR' call, the address of the next instruction is pushed onto the stack and then the address of the first byte of the subroutine is entered into the program counter ‑ execution continues within the subroutine. When the subroutine is done, you will find that an 'RTS' instruction will be used to exit the subroutine. The 'RTS' instruction will pop 2 bytes from the stack and load those bytes into the program counter. Execution will continue with the instruction after the calling 'JSR' or 'BSR'.

    The 6809 has an unusual feature: Multiple general purpose registers can be pushed onto the stack with just a single instruction ‑ with other processors, there is usually a PUSH instruction for each register to be pushed. The 6809 also permits multiple registers to be popped (or pulled) with a single instruction. The most interesting feature of these instructions is that it permits the program counter ('PC') to be pushed and popped like any other register.

    For example:

    SUBR       PUSH       A  
      PUSH   B  
      PUSH   X  
        .    
        .    
        .    
      PULL   X  
      PULL   B  
      PULL   A  
      RTS    


    can be
    written as
    SUBR       PSHS       A,B,X  
        .    
        .    
        .    
      PULS   A,B,X  
      RTS    


    or a little more
    efficently
    SUBR       PSHS       A,B,X  
        .    
        .    
        .    
      PULS   A,B,X,PC  

    As you look through the code, you'll see a mix where either an 'RTS' or a 'PULS' instruction has been used to exit a subroutine. Generally speaking, what drives the choice is whether any registers where pushed onto the stack when the subroutine was entered.

    Just one more thought on this subject: You'll notice in the above example that the pull order is the reverse of the push order ‑ the stack is a last-in/first-out structure. When using the 6809 'PSHS' and 'PULS' instructions, the push/pull order is inherent to the instruction. Just make sure that your pushes and pulls match before pulling the program counter.
  • Instructions can take a varying amount of time (or cycles) to execute. Execution time can be short and of fixed duration like when loading a register and unpredictably long when performing a multiply. Normally, the amount of time to execute a section of code doesn't matter too much (as long as it's not excessive). With the Vectrex, there are areas of code where the time of execution is crucial ‑ right down to the number of cycles that it takes. Truly, a couple of cycles too long or too short can have a noticeable impact on what appears on the screen.

    Some situations might require an exact cycle count. While always needing attention to detail, this type of code can be difficult to accomplish because conditional instructions (like 'BNE' or 'BCS') will require additional cycles if the condition is true versus the number of cycles if the test is false. Getting the right number of cycles can result in some peculiar looking code.





 

Copyright 2024
All Rights Reserved

Thank you for visiting our website.

In closing, please keep in mind that we can not guarantee the accuracy or timeliness of the information on this website, so use with care. We encourage you to double-check the information that is critical to you.

If you've found an error or have additional information that you would like to share, please don't hesitate to write: Click here to contact us.

This page was last modified/updated: 04 Feb 2024