Jump to content

Photo

Does anyone know how many machine cycles each 6502 operation takes?

6502 machine cycles

4 replies to this topic

#1 Pantomchap OFFLINE  

Pantomchap

    Space Invader

  • 16 posts

Posted Thu May 18, 2017 11:41 AM

must know.

 

I also would like to know if other parts of the 2600 will use more time if I interact with them.

 

Thanks!



#2 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 11,301 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Thu May 18, 2017 12:13 PM

NMOS 6502 Opcodes
 
as an example, look at LDA and you'll find:
 

LDA (LoaD Accumulator)
 
Affects Flags: S Z
 
MODE           SYNTAX       HEX LEN TIM
Immediate     LDA #$44      $A9  2   2
Zero Page     LDA $44       $A5  2   3
Zero Page,X   LDA $44,X     $B5  2   4
Absolute      LDA $4400     $AD  3   4
Absolute,X    LDA $4400,X   $BD  3   4+
Absolute,Y    LDA $4400,Y   $B9  3   4+
Indirect,X    LDA ($44,X)   $A1  2   6
Indirect,Y    LDA ($44),Y   $B1  2   5+
 
+ add 1 cycle if page boundary crossed
 
the TIM column is the cycles so LDA #0 takes 2 cycles while LDA $0 takes 3.

The only thing that'll take more time is if you write to WSYNC (Wait for SYNC) such as STA WSYNC. That's used to halt the CPU until the end of the scanline so you can synchronize your code with the electron beam.

#3 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 11,301 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Thu May 18, 2017 12:16 PM

Stella's built in debugger is also handy while you're learning the cycles. The numbers in the blue oval are the cycle counts for each instruction:
Screen Shot 2017-05-18 at 1.14.52 PM.png

#4 Pantomchap OFFLINE  

Pantomchap

    Space Invader

  • Topic Starter
  • 16 posts

Posted Thu May 18, 2017 3:32 PM

NMOS 6502 Opcodes
 
as an example, look at LDA and you'll find:
 
 

LDA (LoaD Accumulator)
 
Affects Flags: S Z
 
MODE           SYNTAX       HEX LEN TIM
Immediate     LDA #$44      $A9  2   2
Zero Page     LDA $44       $A5  2   3
Zero Page,X   LDA $44,X     $B5  2   4
Absolute      LDA $4400     $AD  3   4
Absolute,X    LDA $4400,X   $BD  3   4+
Absolute,Y    LDA $4400,Y   $B9  3   4+
Indirect,X    LDA ($44,X)   $A1  2   6
Indirect,Y    LDA ($44),Y   $B1  2   5+
 
+ add 1 cycle if page boundary crossed
 
the TIM column is the cycles so LDA #0 takes 2 cycles while LDA $0 takes 3.

The only thing that'll take more time is if you write to WSYNC (Wait for SYNC) such as STA WSYNC. That's used to halt the CPU until the end of the scanline so you can synchronize your code with the electron beam.

 

 

 

Thank you so much! This resource will be extremely helpful to me.


Edited by Pantomchap, Thu May 18, 2017 3:32 PM.


#5 SpiceWare OFFLINE  

SpiceWare

    Quadrunner

  • 11,301 posts
  • Medieval Mayhem
  • Location:Planet Houston

Posted Thu May 18, 2017 4:03 PM

Thank you so much! This resource will be extremely helpful to me.


No problem. I've also written a tutorial that you may find useful. It covers writing a 2K game from scratch.







Also tagged with one or more of these keywords: 6502, machine cycles

0 user(s) are browsing this forum

0 members, 0 guests, 0 anonymous users