6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 6:57 pm

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: jmp (abs,x)
PostPosted: Sat Apr 06, 2019 10:03 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
I recently had another "don't know what you don't know" moments - in that I thought I was generally OK with the 65C02 instruction set, however for some weird reason, jmp (abs,x) escaped me and I only noticed it when brushing up on the '816 instruction set...

I recently posted a command-dispatcher that looked like:

Code:
        lda     cmdI                    ; Get command index
        asl     a                       ; Double to index into jump table
        tay
        lda     commandList,y
        sta     wooly+1
        iny
        lda     commandList,y
        sta     wooly+2
        jsr     wooly                   ; JSR to the command and hope for an RTS
        jmp     rubyOsCmd

; The wooly jumper

wooly:  jmp     $FFFF                   ; Modified


The immediate optimisation (not that's it's really needed is to remove the iny and replace the subsequent lsa with lda commandList+1,y, however the jmp (abs,x) mechanism is far more compact, less cycles and less code, so why not, and I've now replaced all that with:

Code:
        lda     cmdI                    ; Get command index
        asl     a                       ; Double to index into jump table
        tax
        jmp     (commandList,x)


Anyway, there you are, in-case it helps anyone else, or jogs their little grey cells...

Cheers,

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
 Post subject: Re: jmp (abs,x)
PostPosted: Sat Apr 06, 2019 10:08 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
Differences between NMOS 6502 and CMOS 65c02

_________________
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  
 Post subject: Re: jmp (abs,x)
PostPosted: Tue May 28, 2019 7:56 pm 
Offline

Joined: Wed Feb 12, 2014 1:39 am
Posts: 173
Location: Sweden
Ahh thanks for letting us know, I made a similar thing by abusing RTS with the command table pointing to the Addresses - 1 which I patted myself on the back for lol. replacing it with a jmp now :)
Code:
            LDA T_COMMAND_TAB,X
            TXA
            ASL A
            TAX
            LDA T_COMMAND_ADDR+1,X
            PHA
            LDA T_COMMAND_ADDR,X
            PHA
            LDX #$01
            RTS

......

T_COMMAND_ADDR:
 .WORD DISPLAYRAM-1
 .WORD BRKTEST-1
 .WORD JUMP-1
 .WORD SREC-1
 .WORD MEMTEST-1
 .WORD READMEM-1
 .WORD SLEEP-1
 .WORD WRITEMEM-1
 .WORD FILL-1
 .WORD HELP-1


Top
 Profile  
Reply with quote  
 Post subject: Re: jmp (abs,x)
PostPosted: Tue May 28, 2019 9:33 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
I've also been using that CMOS instruction/address mode for many years now... example from my current monitor code:

Code:
;
CMON            JSR     RDCHAR          ;Wait for keystroke (converts to upper-case)
                LDX     #MONTAB-MONCMD-1 ;Get command list count
CMD_LP          CMP     MONCMD,X        ;Compare to command list
                BNE     CMD_DEC         ;Check for next command and loop
                PHA                     ;Save keystroke
                TXA                     ;Xfer Command index to A reg
                ASL     A               ;Multiply keystroke value by 2 (command offset)
                TAX                     ;Xfer Command offsett address to table MONTAB
                PLA                     ;Restore keystroke (some commands send to terminal)
                JSR     DOCMD           ;Call Monitor command processor as a subroutine
                BRA     WARM_MON        ;Command processed, branch and wait for next command
DOCMD           JMP     (MONTAB,X)      ;Execute CMD from Table
;
CMD_DEC         DEX                     ;Decrement index count
                BPL     CMD_LP          ;If more to check, loop back
                JSR     BEEP            ;Beep for error, not valid command character
                BRA     CMON            ;Branch back and re-enter Monitor
;


In the past few years, I've continued rewriting parts of my code to leverage many of the newer instructions and addressing modes. At this point, I don't think I could go back to writing code for the NMOS only CPU :mrgreen:

_________________
Regards, KM
https://github.com/floobydust


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 30 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: