• Please review our updated Terms and Rules here

Counting Clock Cycles on Apple IIgs - cc65 compiler

twillkickers

Experienced Member
Joined
Feb 22, 2017
Messages
152
Location
New Jersey, USA
Doing some tinkering with my IIGS and I'd like to be able to count clock cycles required for execution of a machine language program. I'm using the cc65 compiler to take some small C programs and run them on my IIGS. (essentially followed this tutorial for anyone who is also interested: https://macgui.com/kb/article/761)

I'd like to run some number crunching scripts and then see the execution time in clock cycles for the entire program. Is there a good way to count clock cycles and display the number on the Apple II/IIgs? What C commands or 6502 machine language instruction(s) would I use? I'm new to this type of thing and would love to learn more. Thanks for any help!
 
I don't know if it's possible to programmatically count clock cycles. You could take the compiled code, examine the resulting op codes for the section of code in question, then cross reference with the processor data sheet.
 
Thank you for the suggestion. I've decided to go with your method - I pulled up the data sheet for the 6502 found at https://www.princeton.edu/~mae412/HANDOUTS/Datasheets/6502.pdf (also attached below for redundancy)

However, I cannot figure out what these letters circled in red signify (OP, N, and #.) Does anyone know what these mean? I'm assuming it is a common convention that I am not familiar with as I am still new to the field. Does one of these signify clock cycles from start to finish of the instruction?
1671390505167.png
 

Attachments

  • 6502.pdf
    2.5 MB · Views: 2
OP is the opcode. N is the cycles, # is the number of bytes for the instruction.

Note the details at the bottom about how N is adjusted based on page boundaries and such.
 
Doing some tinkering with my IIGS and I'd like to be able to count clock cycles required for execution of a machine language program. I'm using the cc65 compiler to take some small C programs and run them on my IIGS. (essentially followed this tutorial for anyone who is also interested: https://macgui.com/kb/article/761)

I'd like to run some number crunching scripts and then see the execution time in clock cycles for the entire program. Is there a good way to count clock cycles and display the number on the Apple II/IIgs? What C commands or 6502 machine language instruction(s) would I use? I'm new to this type of thing and would love to learn more. Thanks for any help!
Probably you are looking for a "code profiler" which will watch the execution of a program and tell you more about the performance of different parts of the code you have written.

Assuming that what you are using is this CC65: https://github.com/ilmenit/CC65-Advanced-Optimizations then it looks like you can use the Altira emulator , compile your number crunching code under an emulated Atari and get exact measurements on the profiled code. However you might find the optimization tips and tricks on that page are enough, without having to compile under an emulator!
 
Back
Top