65xx Opcode statistics, an example

Basic and Machine Language

Moderator: Moderators

tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

Mike wrote:
tlr wrote:...and for fcbpaint...

Code: Select all

nop: 232
:shock: :?:

Does this include the dynamic code of the display routine? And thus the NOPs are for timing purposes?
Those are part of the display code in the editor screen. The viewer code is runtime generated and not part of this.
I think it would be very interesting to expand our statistics with addressing mode.
That's debatable. You'd either have to compare an even longer list of 151 different (documented) opcodes. Or arrange them in a table with '#IMM', 'ZP', 'ZP,X', ..., '(ZP),Y', etc. as table header, with sums for each row and column. In the latter case, most of the table entries would be empty, since the instructions do not cover all combinations. And the statistics as such also gets less reliable, since the numbers get smaller - conversely the programs would need to be bigger to draw good conclusions.

OTOH, I'd rather have put, for example, LDA, LDX, LDY into one group. If it were not for the fact that A, X and Y *do not have* equal properties. As it is, the statistics sum up a distinct operation on a register or memory location, regardless in which way the operand was obtained.
I think that the most interesting solution would be just to add an additional statistic table that does not consider the instruction mnemonic only the addressing mode.
User avatar
Mike
Herr VC
Posts: 4846
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

O.K., that'd comprise:

Code: Select all

ABS
ABS,X
ABS,Y
ZP
ZP,X
ZP,Y
(ZP,X) - would be very interesting to see real-life examples!
(ZP),Y
(ABS) - used only in indirect JMP instruction
#IMM
Implied/Accumulator/Stack - do we need to separate these?
Relative - used only with branch instructions
If BIT is used solely for instruction masking, I'd suggest to make the case 'Implied' and, again, account for the address mode of the masked instruction as well.
Kananga
Vic 20 Afficionado
Posts: 317
Joined: Mon Mar 08, 2010 2:11 pm

Post by Kananga »

So where is the script that collects the statistics?
I'll run it on my sources right away!

But I haven't installed cygwin or gnu-win32 on my PC yet and I don't like to perform this kind of task without a proper shell & environment.
Buy the new Bug-Wizard, the first 100 bugs are free!
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

Here's my attempt:

datapop...

Code: Select all

Addressing modes:
#<imm>: 177
<abs>: 167
impl: 167
<abs>,x: 102
<rel>: 99
<zp>: 89
<zp>,x: 82
<abs>,y: 71
(<zp>),y: 9
(<ind>): 1
(<zp>,x): 0
...fcbpaint...

Code: Select all

Addressing modes:
impl: 991
<abs>: 945
#<imm>: 745
<zp>: 378
<rel>: 318
<abs>,x: 239
(<zp>),y: 156
<abs>,y: 69
<zp>,x: 21
(<zp>,x): 0
(<ind>): 0
It was kind of tedious to write the instruction tables so I might have made some mistakes in it.
User avatar
Mike
Herr VC
Posts: 4846
Joined: Wed Dec 01, 2004 1:57 pm
Location: Munich, Germany
Occupation: electrical engineer

Post by Mike »

tlr, your stats are missing ZP,Y - even if only LDX and STX support it.

Also just finished my stats on the EDITOR library of MINIPAINT, sorted:

Code: Select all

#IMM    442
IMPL.   417
ABS     341
ZP      227
REL.    191
ABS,X   106
ABS,Y   87
(ZP),Y  57
ZP,X    0
ZP,Y    0
(ZP,X)  0
(ABS)   0
And here's the program I ran on the output of TEDMON (C16/+4 variant). I couldn't simply use INPUT# to read in the lines, as that barfed upon the commas of the indexed addressing modes:

Code: Select all

10 IFPEEK(1)+256*PEEK(2)<>828THENPOKE56,PEEK(56)-1:CLR:POKE1,60:POKE2,3
11 FORT=828TO916:READA:POKET,A:NEXT
12 Z$="I'M 17 CHARS LONG":Z$=Z$+Z$+Z$+Z$+Z$:Z$=Z$+Z$+Z$
13 :
14 DATA 32,247,215,165,21,208,35,166,20,32,27,225,160,0,132,254
15 DATA 32,15,225,201,13,240,11,164,254,145,55,200,132,254,192
16 DATA 255,208,238,32,204,255,164,254,76,162,211,76,72,210
17 DATA 32,253,206,32,139,208,133,20,132,21,160,0,177,20,72,200
18 DATA 177,20,72,200,177,20,133,21,104,133,20,104,133,254,160,0
19 DATA 196,254,240,7,177,55,145,20,200,208,245,96
20 :
21 DIMAM(11):P$="                            "
22 OPEN2,8,2,"EDITOR.TXT,S,R"
23 R$=LEFT$(Z$,USR(2)):SYS873,R$
24 R$=LEFT$(R$+P$,28):IFR$=P$THEN37
25 IFMID$(R$,22,2)="($"ANDMID$(R$,26,3)=",X)"THENAM(6)=AM(6)+1:GOTO37
26 IFMID$(R$,22,2)="($"ANDMID$(R$,26,3)="),Y"THENAM(7)=AM(7)+1:GOTO37
27 IFMID$(R$,22,2)="($"ANDMID$(R$,28,1)=")"THENAM(8)=AM(8)+1:GOTO37
28 IFMID$(R$,27,2)=",X"THENAM(1)=AM(1)+1:GOTO37
29 IFMID$(R$,27,2)=",Y"THENAM(2)=AM(2)+1:GOTO37
30 IFMID$(R$,25,2)=",X"THENAM(4)=AM(4)+1:GOTO37
31 IFMID$(R$,25,2)=",Y"THENAM(5)=AM(5)+1:GOTO37
32 IFMID$(R$,22,1)="#"THENAM(9)=AM(9)+1:GOTO37
33 IFMID$(R$,22,1)="$"ANDMID$(R$,25,2)<>"  "ANDMID$(R$,15,2)="  "THENAM(11)=AM(11)+1
34 IFMID$(R$,22,1)="$"ANDMID$(R$,25,2)<>"  "ANDMID$(R$,15,2)<>"  "THENAM(0)=AM(0)+1
35 IFMID$(R$,22,1)="$"ANDMID$(R$,25,2)="  "THENAM(3)=AM(3)+1
36 IFMID$(R$,22,7)="       "THENAM(10)=AM(10)+1
37 IFST=0THEN23
38 CLOSE2
39 S=0:FORT=0TO11:S=S+AM(T):NEXT
40 PRINTS
41 OPEN2,8,2,"RESULT.TXT,S,W"
42 PRINT#2,"ABS    "+STR$(AM(0))
43 PRINT#2,"ABS,X  "+STR$(AM(1))
44 PRINT#2,"ABS,Y  "+STR$(AM(2))
45 PRINT#2,"ZP     "+STR$(AM(3))
46 PRINT#2,"ZP,X   "+STR$(AM(4))
47 PRINT#2,"ZP,Y   "+STR$(AM(5))
48 PRINT#2,"(ZP,X) "+STR$(AM(6))
49 PRINT#2,"(ZP),Y "+STR$(AM(7))
50 PRINT#2,"(ABS)  "+STR$(AM(8))
51 PRINT#2,"#IMM   "+STR$(AM(9))
52 PRINT#2,"IMPL.  "+STR$(AM(10))
53 PRINT#2,"REL.   "+STR$(AM(11))
54 CLOSE2
wimoos
Vic 20 Afficionado
Posts: 350
Joined: Tue Apr 14, 2009 8:15 am
Website: http://wimbasic.webs.com
Location: Netherlands
Occupation: farmer

Post by wimoos »

In WimBasic (zp,x) is used twice, both with x=0, in the code for RENUM.
It is used in conjunction with (zp),y when the new linenumber is longer or shorter than the old one and the programtext has to be shifted.
VICE; selfwritten 65asmgen; tasm; maintainer of WimBasic
tlr
Vic 20 Nerd
Posts: 567
Joined: Mon Oct 04, 2004 10:53 am

Post by tlr »

Mike wrote:tlr, your stats are missing ZP,Y - even if only LDX and STX support it.
Ok, fixed that now. Those would have appeared in the list if they were anything else than 0.
Post Reply