6809 Assembly Language Part 3

So I’ve realized that my biggest stumbling block getting started with this stuff is that I have a difficult time writing “pseudo-code”. Pseudo-Code is code that is not really in any particular language format but contains your logical decision making and program flow in a native language like format.

That being said, coming up with a meaningful shorthand is beneficial for the future you looking at the meticulous notes you made in your notebook while you were crafting your code. We all do this, right? Right? OK, I get it… time is valuable… writing notes is annoying… But your future self will thank you for keeping some notes.

So what am I getting to? Well, lets start with this.

  

         ORG $4000
START:
         PSHS A,B
         LDA #'H
         LDB #'I
         LDX #$400
         STD ,X
         PULS A,B
         PULS PC
         END

So, how did we get here… how about looking at my notes..

Screen memory begins at $400.  Program should be out of the way... so maybe $4000
We will BASH registers A&B so save them
Then use registers A & B for the 2 letters in the word "HI"
Load the X register with the location of 32 column screen start in RAM
Store the contents of the D register (registers A and B combined) into X, displaying both chars to the screen
do cleanup
exit to basic

But what if things get more complex? Choosing standards for shorthand in my notes could help. How about the easy stuff like operators.

eq Equal to
ne Not equal to
gt Check if the left operand is greater than the right operand
lt Checks if the left operand is less than the right operand
ge Check if the left operand is greater then or equal to right operand
le Check if the left operand is less than or equal to the right operand
and Equal to
or Not equal to
not Equal to

Labels: Naming labels so they are meaningful is a good idea. Granted, for simple local loops, you can even use the native shorthand described in the LWASM manual regarding `@` and `<` and `>`. For labels that leave the local scope, however, a meaningful label should be chosen.

Additionally, coming up with constructs similar to BASIC can be helpful, such as IF THEN and WHILE.

=====[Pseudo code]========================================
START:
WHILE A GT #0
 Decrement A
 ENDWHILE
==========================================================
Translates to: 
=====[Actual code]========================================
START:
       CMPA  #0
       BLE LEAVE
       DECA
       BRA START
LEAVE:  
       EQU *



Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.