[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]

But what if a program didn't want to wait until X or Y had reached (or not reached) zero? Well there are comparison instructions, CPX and CPY, which allow the machine language programmer to test the index registers with specific values, or even the contents of memory locations. If you wanted to see if the X register contained $40, you would use the instruction:

   CPX #$40         - compare X with the "value" $40.
   BEQ              - branch to somewhere else in the
   (some other        program, if this condition is "true."
    part of the
    program)

The compare, and branch instructions play a major part in any machine language program.

The operand specified in a branch instruction when using 64MON is the address of the part of the program that the branch goes to when the proper conditions are met. However, the operand is only an offset, which gets you from where the program currently is to the address specified. This offset is just one byte, and therefore the range that a branch instruction can branch to is limited. It can branch from 128 bytes back- ward, to 127 bytes forward.

NOTE: This is a total range of 255 bytes which is, of course, the maximum range of values one byte can contain.

64MON will tell you if you "branch out of range" by refusing to "assemble" that particular instruction. But don't worry about that now because it's unlikely that you will have such branches for quite a while. The branch is a "quick" instruction by machine language standards because of the "offset" principle as opposed to an absolute address. 64MON allows you to type in an absolute address, and it calculates the correct offset. This is just one of the "comforts" of using an assembler.

NOTE: It is NOT possible to cover every single branch instruction. For further information, refer to the Bibliography section in Appendix F.


[Prev] [Next] [Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated July 10, 2002.