.

JMP $FCE2
satpro

.

Post by satpro »

.
Last edited by satpro on Mon Dec 01, 2014 4:19 am, edited 2 times in total.


dudz
Member
Member
Posts: 140
Joined: Tue Jun 17, 2014 5:40 am
Contact:

Re: How to Add Local Variables to Your Functions

Post by dudz »

Which stack-clearing method the caller uses depends on how many params were pushed. You can probably see how this is the faster method.
ugh, except it isnt - in your example anyway (actually counting the cycles is always a good idea).

stackframes arent exactly something "the big boys" invented either, its a common thing to do ever since.
satpro

.

Post by satpro »

.
Last edited by satpro on Mon Dec 01, 2014 4:20 am, edited 1 time in total.
dudz
Member
Member
Posts: 140
Joined: Tue Jun 17, 2014 5:40 am
Contact:

Re: How to Add Local Variables to Your Functions

Post by dudz »

aha. so the one who writes those clearly wrong things isnt the clown here. point taken.
satpro

.

Post by satpro »

.
Last edited by satpro on Mon Dec 01, 2014 4:20 am, edited 1 time in total.
dudz
Member
Member
Posts: 140
Joined: Tue Jun 17, 2014 5:40 am
Contact:

Re: How to Add Local Variables to Your Functions

Post by dudz »

Feel free to jump in with facts
the second method of adjusting the stack frame in your example is not faster as you said, it is 2 cycles slower.
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: How to Add Local Variables to Your Functions

Post by Shaun_B »

dudz wrote:
Feel free to jump in with facts
the second method of adjusting the stack frame in your example is not faster as you said, it is 2 cycles slower.
Am I correct in thinking that 1 cycle = 1ns? Or is it 1ms?

Is there any way to optimise it to recover those 2 cycles? Or would the code require a radical re-working?

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
MarcWalters
Member
Member
Posts: 55
Joined: Wed Jun 11, 2014 2:33 pm
Location: Lake Macquarie, NSW, Australia
Contact:

Re: How to Add Local Variables to Your Functions

Post by MarcWalters »

Shaun, one CPU cycle occurs for each CPU clock tick. It is independent of the speed of the CPU clock. A cycle at 20Mhz occurs twenty times the speed of a CPU cycle at 1Mhz. However, the clock speed is derived from the frequency of the domestic AC power used by the computer, which varies significantly between some regions of the world - most significantly between North America (60Hz) and Europe (50Hz). A stock or accelerated C64 in the USA will complete 1/5 more CPU cycles in a given amount of time than its counterpart C64 in Europe.

A 50Hz-region C64 at 1Mhz will process just under a million cycles per second.

For detailed information relevant to the C64, read this page:
http://unusedino.de/ec64/technical/misc ... -ntsc.html

As for recovering two cycles, your question is void because it seems both Dudz and Satpro were mistaken.

From a careful read of the discussion, it's apparent Dudz assumed Saptpro was referring to the Caller method's alternative for stack recovery. The first example used repeated "inx", while the alternative used "adc" and transferred data between X and A. He was quite correct that the alternative would take two cycles longer.

However, Satpro was referring to the "Caller Handles The Stack" method as being faster than the "Callee" method. But this statement was ambiguous because it immediately proceeded the stack recover alternative, hence Dudz' misinterpretation.

Had Satpro been curious enough to wonder what Dudz had seen in his article that invoked such a short and simple reply, then he would not have fired off his own misconceived response. It is quite apparent on closer inspection that Dudz' statement was justified, given the misinterpretation, and did not need further explanation - because a casual glance by any ML programmer would be enough to see that the alternative was indeed two cycles longer.

Fortunately, this is a discussion forum involving adults who enjoy programming. Criticism, even when misdirected, is useful and should be embraced, as it can often be used as an opportunity to explore new and better ways to do things.
dudz
Member
Member
Posts: 140
Joined: Tue Jun 17, 2014 5:40 am
Contact:

Re: How to Add Local Variables to Your Functions

Post by dudz »

Is there any way to optimise it to recover those 2 cycles? Or would the code require a radical re-working?
in the above example there is simply a note missing that the second example is faster IF the stack needs adjustment by 5 or more bytes - in that case repeated INX are slower. for 4 bytes its the same, for 3 or less the INX stuff is faster. (and shorter!) if you make a macro for this, it could just choose between the two methods depending on the number of adjusted bytes.
User avatar
Shaun_B
Member
Member
Posts: 179
Joined: Tue May 06, 2014 12:12 pm
Location: UK
Contact:

Re: How to Add Local Variables to Your Functions

Post by Shaun_B »

dudz wrote:in the above example there is simply a note missing that the second example is faster IF the stack needs adjustment by 5 or more bytes - in that case repeated INX are slower. for 4 bytes its the same, for 3 or less the INX stuff is faster. (and shorter!) if you make a macro for this, it could just choose between the two methods depending on the number of adjusted bytes.
Okay, so why didn't you just say that in the first place?

Regards,

Shaun.
BASIC Programming - making the mistakes so that you don't have to.
Circles and Squares.
Nothing I post here will stand up in a court of law.
Post Reply Previous topicNext topic

Who is online

Users browsing this forum: No registered users and 6 guests