6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Sep 22, 2024 4:57 am

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Aug 31, 2015 6:14 pm 
Offline
User avatar

Joined: Sun Sep 08, 2013 10:24 am
Posts: 740
Location: A missile silo somewhere under southern England
I've put together a small help sheet for my own use which will hopefully get me used to avoiding putting in unnecessary WDC 65C02 assembly commands with regard to branches based on flags. For example:

Code:
LDX #20
.loop
(do stuff)
DEX
CPX #0
BNE loop
RTS


Could become:

Code:
LDX #20
.loop
(do stuff)
DEX
BNE loop
RTS


I'm posting this here in case it's of use to anyone else.
BTW it should print out on to a single A4 sheet for easy reference.

Oh, and if anyone spots anything that I've missed or gotten wrong please post it and I'll amend the info sheet.

Attachment:
65C02 help sheet.pdf [250.47 KiB]
Downloaded 91 times


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 31, 2015 8:52 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
Be sure to also check out the 6502 primer's page 20, "Tips For Programming the 65(c)02 (sometimes affecting hardware design optimization)."

And as usual, I can't pass up the opportunity to recommend the excellent programming manual, "Programming the 65816 including the 6502, 65C02, and 65802" by David Eyes and Ron Liechty. This is a .pdf file of a rather large book that is well laid out and is much better than the description there lets on. Note: There were many problems with the earlier .pdf version that were not in the original paper manual; but in late March 2015, WDC scanned and OCR'ed the paper manual and posted the new, repaired .pdf.

In my 6502 assembly structure macros, the macros for a FOR...NEXT loop like your above watch for that kind of thing, to optimize. So
Code:
        FOR_X  20, DOWN_TO, 0
            <do stuff>
            <do stuff>
        NEXT_X

would assemble
Code:
        LDX  #20
loop:   <do stuff>
        <do stuff>
        DEX
        BNE  LOOP

without the CPX #0; but CPX would be added if you had for example FOR_X 20, DOWN_TO, 4. (It is slightly modified from BASIC's FOR...NEXT to more closely match what we do in assembly. The destination number is not run, because the incrementing or decrementing happens right before the test and conditional branch.) There are many conditions you can set up, and the macros will watch for them and optimize, just as you would do by hand, except that now the source code becomes more readable, so you get fewer bugs, quicker development, and better maintainability.

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC


Who is online

Users browsing this forum: jds and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: