6802 assembly help please.

Discussion in 'Embedded Systems and Microcontrollers' started by Danno., Aug 20, 2016.

  1. Danno.

    Thread Starter Member

    Apr 6, 2015
    39
    1
    Hi,
    Could somebody please help me understand what's going on in this subroutine, processor is a 6802.


    7198 ldx #$2000
    719B clr x0006
    719E tst $00, x
    71A0 bpl L71A5
    71A2 inc X0006
    71A5 inx
    71A6 cpx #$2005
    71A9 bne L719E
    71AB rts


    Is it some kind of timer circuit???

    Thanks in advance.
     
    Last edited: Aug 20, 2016
  2. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    I can, but there is an error in the code at line (address) 71A6.
    Perhaps you recorded the line incorrectly.

    Edit: incorrect code at address 71A6 was cpx #$2000
     
  3. Danno.

    Thread Starter Member

    Apr 6, 2015
    39
    1

    Sorry, now corrected, thanks.
     
  4. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    Is this homework?
     
  5. Danno.

    Thread Starter Member

    Apr 6, 2015
    39
    1
    No, it's a hobby. I have a machine which is 36 years old and I am playing about with whilst trying to work out assembly coding at the same time.

    Never to old to learn but to old for school now LOL.
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    Start by drawing a flow chart.

    The code begins by setting the x-register to $2000 and clearing memory location 6, used as a counter.
    The code scans memory locations $2000 to $2004 inclusive and counts the number of times it finds a negative value (signed 8-bit number) i.e. bit-7 is 1.

    This code serves no useful purpose as far as I can see. That is why I would expect this to be a piece of homework exercise.
     
  7. Danno.

    Thread Starter Member

    Apr 6, 2015
    39
    1
    Thanks Mr Chips, it all makes sense now and it does serve a purpose.

    The machine has 6 coin switches memory mapped to addresses 0x2000 - 0x2005, what this subroutine appears to do is scan the switches when the machine is switched on to check if any are stuck. Immediately on returning from this subroutine the code checks the status of memory location 0x0006 and either branches to continue with program or branches to another subroutine that causes an alarm.

    Originally I was just not getting that it was pointing to those memory locations, your explanation made everything fall into place, thanks.

    One quick question, the tst $00,x instruction means test index accumulator without adding anything to the address?

    Cheers
     
  8. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    Correct.

    Hence TST 1,X would test the address one away from the address pointed to in X.
    That is why X is called the index register.

    If you would like to learn more you might find this pdf useful. The 6805 is an offspring of the 6802 and hence shares some similarities in the architecture and instruction set.

    http://www.nxp.com/files/microcontrollers/doc/ref_manual/M68HC05TB.pdf
     
  9. Danno.

    Thread Starter Member

    Apr 6, 2015
    39
    1

    Thank you, I'll have a read of that.
     
  10. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,011
    3,785
    @MrChips
    What kind of programmer is used for these old chips?
     
    Last edited: Aug 21, 2016
  11. MrChips

    Moderator

    Oct 2, 2009
    12,437
    3,360
    Depends on the specific chip. Most chips of that era were simply CPUs; they had no internal memory.
    Hence the standard practice was to program a UV-EPROM.
    I used a programmer on a S100-Bus system running CP/M.:eek: Yikes! Turn around time to reprogram the UV-EPROM was 45 minutes. That's how long it took to erase the UV-EPROM. You made sure that there weren't too many mistakes in your code.

    There were no fancy IDE then. You used a text editor to write your ASM code followed by an assembler to produce hex code. Then you used the programmer program to flash the UV-EPROM.

    Next, you remove the UV-EPROM from the programmer and plug it into your proto board... apply power and then hope for the best.:)

    My first code for a micro was assembled by hand for an RCA 1802 and then programmed into the UV-EPROM. No editor or assembler involved.
     
  12. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,677
    2,725
    That's why I used to keep a bunch of EPROMs (and, later, windowed UV erasable MCU's) in the eraser and rotate them. Often I'd burn and test many chips per hour.

    Much fun.
     
  13. JWHassler

    Member

    Sep 25, 2013
    201
    33
    "Crash and burn"
     
Loading...