Sending string to serial bug, 6809 assembly, beginner

127 views Asked by At

I have built a simple single board computer, and am trying to learn 6809 assembly language. I have got a few simple things running, Echo over via a 6850 ACIA for example. I am trying to print a string and am stuck.

The string is in ROM and terminated with null zero. I load the X register to point to start of the string. Later I load character pointed to by X to A register, and X is incremented. Then test for null zero before outputing the character to the ACIA. I have connected a simple logic analyser to the data bus, and know that nothing is output to the ACIA because it sees a zero instead of the first character, and thinks the string has finished. I can't see a bug in the code, and it could be hardware related, but need an experienced eye to look it over in case I'm making a beginners error.

Here is the assembly:


*******************************EQUATES****************************************
    ***ACIA register definitions****
ACIA_control EQU $A000 ;write only
ACIA_status EQU $A000 ;read only
ACIA_data EQU $A001 ;read/write

********************************STRING CONSTANT******************************
    ORG $C000 ; ROM starts here

    ***store string to send out on serial***
    *Pseudo op FCN stores characters in sequential bytes,
    *and automatically adds null zero.
   

start_of_string
    FCN "The quick brown fox jumps over the lazy dog"

**********************************SETUP****************************************
setup

    ***reset_ACIA***
    LDA #%00000011
    STA ACIA_control

    ***set_ACIA_mode***
    ;clock/64 gives 19,200 baud with 4.9152   MHz xtal
    ;8 bits, 1 stop bit, no parity
    ;/RTS inactive (set high), TX interupt disabled, RX interupt disabled
    LDA #%01010110
    STA ACIA_control

*********************************SEND LOOP**************************************
reset_index_register
        LDX start_of_string

        ***Is ACIA ready to TX***
wait    LDA #%00000010
        ANDA ACIA_status
        BEQ wait

        ***send character***
        LDA ,X+
        BEQ end_of_string; string finished at null zero
        STA ACIA_data
        BRA wait ;next character

        ***LOOP BACK***
end_of_string
        BRA reset_index_register

*********************************VECTORS****************************************

    ***RESET***
    ORG $FFFE
    FDB setup ;Jump to programme entry
1

There are 1 answers

0
DaveyCrockett On

It definitely is a beginners error.

The error is in the line

LDX start_of_string

This is extended mode addressing so the X register is loaded with the the two characters at the start of the string. This is used as a pointer so it is now pointing to "there be dragons!"

The correct code is: LDX #start_of_string This is immediate mode. X is now loaded with the address of start of string.

Things were not made easier by an error in Lance Leventhal's book "6809 assembly language programming". He gives the opcode for LDX immediate as BE, and the opcode for LDX extended also as BE. This is of course, impossible. LDX immediate opcode is really 8E, so you can see how the typo came about.