A new article about 6502

Let's talk about anything related to the 6502 microprocessor.
White Flame
Posts: 704
Joined: 24 Jul 2012

Re: A new article about 6502

Post by White Flame »

GARTHWILSON wrote:
and the (ZP,X) is tremendously valuable in dealing with a virtual stack where some of the cells on the stack are addresses and X is used as the virtual-stack pointer. I definitely use X more than Y. Even for hardware-stack addressing, there's the TSX and TXS, but no equivalent for Y.
And even if you're exclusively using Y indexing, that means you'll always be using X for a loop counter.
User avatar
BigDumbDinosaur
Posts: 9426
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: A new article about 6502

Post by BigDumbDinosaur »

GARTHWILSON wrote:
and the (ZP,X) is tremendously valuable in dealing with a virtual stack where some of the cells on the stack are addresses and X is used as the virtual-stack pointer.
Not to mention using (<dp>,X) for selecting UART channels to process. :D
x86?  We ain't got no x86.  We don't NEED no stinking x86!
JimBoyd
Posts: 931
Joined: 05 May 2017

Re: A new article about 6502

Post by JimBoyd »


brain wrote:
tiny is better. But, it's still an awfully loaded term. Minimal, or nominal, or half hearted I think would be better (and more nuanced). tiny and microscopic are boring words.

Incremental?
brain
Posts: 113
Joined: 05 May 2009

Re: A new article about 6502

Post by brain »

JimBoyd wrote:

brain wrote:
tiny is better. But, it's still an awfully loaded term. Minimal, or nominal, or half hearted I think would be better (and more nuanced). tiny and microscopic are boring words.

Incremental?
Also a good choice and somewhat more neutral.

Jim
User avatar
1024MAK
Posts: 155
Joined: 14 May 2015
Location: UK

Re: A new article about 6502

Post by 1024MAK »

I’ve not read the linked to article. But one thing that is more important than features alone, especially in the 1970s and 1980s, was getting the price right (as in low) with just enough features so that it sells.

This was when complex highly integrated circuits were expensive. Especially microprocessors and RAM chips.

And microprocessors designed for use in embedded systems (which was the original market for the NMOS 6502, and also for the Z80) did not need anything that would require any extra cost.

Despite not being designed for use in home computer systems let alone business systems, the 6502 and the Z80 ended up in business computers, educational computers and home computers as well as arcade machines. But also in their original market: embedded systems.

Why, because they were low cost solutions.

Now, looking back (in hindsight), it’s easy to say that there should have been improved versions made. But at the time, when the fabs were having trouble keeping up with production, that’s not really thought about.

Similarly, computer manufacturers are not going to spend too much time and money designing a new computer whilst they are selling their best selling models by the truck load. Hence low or no demand for anything better in terms of the microprocessor.

And then technology moves on and someone else is now working on 16 or 32 bit microprocessors (look up the dates for the 68000 and the 8086 and then look at when the first 16/32 bit computers were first sold). At the same time, most of the computers that these chips (6502, Z80) are being used in, are undergoing cost reduction measures by the manufacturers so that the older model of computers can stay price competitive. Not a good market for a new more expensive eight bit microprocessor... so even less call for a more expensive eight bit souped up microprocessor.

As it happens, because both the 6502 and the Z80 got CMOS versions, they both live on. Because they can be used in low power devices.

Of course, if a significantly faster and/or significantly more capable eight microprocessor that was backwards compatible had been made at low cost back in the mid 1980s, people may well have wanted it in their computer systems.

The bit about the Acorn BBC Micro (also known as the model B). Acorn did design and manufacturer an export version for sale in the U.S.A. As far as I know, they were not blocked or locked out as such. In their home market (the U.K.) these machines were already in the expensive segment of the home computer market. Lower cost Commodore 64 and Sinclair ZX Spectrum computers outsold the Acorn models by a considerable margin, and don’t forget there were many other home computer manufacturers at the time as well, some of which were also undercutting the cost of a BBC Model B machine.

The U.S.A. model included as standard, what were optional features (see here) on the models sold in the U.K., plus all the extra screening added to the cost of each machine. So my feeling is that they priced themselves out of the market. They were never going to really compete with the C64 for a home computer. And if you wanted a more business like computer, then a business would be more likely to either buy and use a CP/M machine or a IBM PC.

The only lock or block really, was the interference suppression requirements (screening and testing) that were required before it was legal to sell systems in the U.S.A.

This was also part of the reason that other U.K. home computer manufacturers had difficulty trying to enter the U.S.A. market.

Interestingly enough, Acorn did push 6502 system functionality more than most home computers in that it’s ‘main’ 6502 normally runs at 2MHz when accessing ROM or RAM. The optional second processor expansion runs even faster at 3MHz. Later on the (internal) second processor board for the Master 128 (the machine is then known as the ‘Master Turbo’) runs at 4MHz. And the Master series machines use a CMOS 65C12 and use the extra instructions to improve the OS code.

By the time of their last eight bit machine (the Master Compact), the OS and BASIC had been improved significantly, in part due to using the 65C12 (and also by general code improvements). See the section under “Performance” in this review (yes, it’s obviously biased). However by now, eight bit machine sales were falling, as most people wanted the new 16/32 bit machines...

Mark
Martin_H
Posts: 837
Joined: 08 Jan 2014

Re: A new article about 6502

Post by Martin_H »

GARTHWILSON wrote:
and the (ZP,X) is tremendously valuable in dealing with a virtual stack where some of the cells on the stack are addresses and X is used as the virtual-stack pointer. I definitely use X more than Y. Even for hardware-stack addressing, there's the TSX and TXS, but no equivalent for Y.
A +1 to (ZP,X) as well. Last year I wrote a toy compiler for a Scheme like language, and I used that for reference arguments.

Looking at one of my common macros modules. I use ",x" 68 times and ",y" 4 times. So I'm really partial to it. But I stole my 6502 assembler style from Forth, so no shock there.

Pairing X and Y together can be really powerful. Such as copying a data stack cell to a location via a pointer. There you use the Y rather than alter the pointers contents.

Code: Select all

; Nondestructively saves the word at TOS using indirect y addressing.
.macro peekIndY
	lda TOS_LSB,x
	sta (_1),y
	iny
	lda TOS_MSB,x
	sta (_1),y
.macend
User avatar
BigDumbDinosaur
Posts: 9426
Joined: 28 May 2009
Location: Midwestern USA (JB Pritzker’s dystopia)
Contact:

Re: A new article about 6502

Post by BigDumbDinosaur »

After reading the linked article in its entirely, and at the risk of offending the author, I must ask what was the point of writing it? The article is overflowing with opinion and starved for facts. In fact, there is so much factual inaccuracy present another entire article would have to be written to rebut the multitude of errors and outright false statements.
x86?  We ain't got no x86.  We don't NEED no stinking x86!
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: A new article about 6502

Post by BillG »

I have been playing with code generation on different processors.

This line of code

Code: Select all

    W0 := S1;
sign extends a byte into two.

For the 6502:

Code: Select all

                          00037 ;  1 L v S1
 0029 A0 00           [2] 00038          ldy    #0
 002B A6 16           [3] 00039          ldx    S1
 002D 10 01 (0030)  [2/3] 00040          bpl    2f
 002F 88              [2] 00041          dey
 0030                     00042 2:
 0030 98              [2] 00043          tya
                          00044 ;  0 := v W0 -> 1
 0031 86 0D           [3] 00045          stx    W0
 0033 85 0E           [3] 00046          sta    W0+1
For the 6800:

Code: Select all

                          00037 *  1 L v S1
 0029 4F              [2] 00038          clra
 002A D6 16           [3] 00039          ldab   S1
 002C 2A 01 (002F)    [4] 00040          bpl    2f
 002E 4A              [2] 00041          deca
 002F                     00042 2:
                          00043 *  0 := v W0 -> 1
 002F 97 0D           [4] 00044          staa   W0
 0031 D7 0E           [4] 00045          stab   W0+1
For the 8080:

Code: Select all

                          00037 ;  1 L v S0
 0100 3A 0015        [13] 00038         lda     S0
 0103 6F              [5] 00039         mov     L,A
 0104 17              [4] 00040         ral
 0105 9F              [4] 00041         sbb     A
 0106 67              [5] 00042         mov     H,A
                          00043 ;  0 := v W0 -> 1
 0107 22 000D        [16] 00044         shld    W0
For the 9900:

Code: Select all

                          00043 *  1 L v S1
 0052 D020 0037           00044         movb    @S1,R0
 0056 0880                00045         sra     R0,8
                          00046 *  0 := v W0 -> 1
 0058 C800 002E           00047         mov     R0,@W0
For the 68000:

Code: Select all

                                  00009 ;  1 L v S1
 00000400 1038 0421               00010         move.b  S1,D0
 00000404 4880                    00011         ext.w   D0
                                  00012 ;  0 := v W0 -> 1
 00000406 31C0 0418               00013         move.w  D0,W0
That almost feels like cheating.

It is interesting that the last four examples have each been ten bytes long.

Real cheating would be the 80386:

Code: Select all

    movsx   AX,[S1]
    mov     [W0],AX
For the AVR:

Code: Select all

                          00011 ;  1 L v S1
 000060 9160 0116     [2] 00012         lds     R22,S1
 000062 2F76          [1] 00013         mov     R23,R22
 000063 0F77          [1] 00014         lsl     R23
 000064 0B77          [1] 00015         sbc     R23,R23
                          00016 ;  0 := v W0 -> 1
 000065 9360 010D     [2] 00017         sts     W0,R22
 000067 9370 010E     [2] 00018         sts     W0+1,R23
And finally, for the 6809:

Code: Select all

                                  00037 *  1 L v S1
 0029 D6 16                   [4] 00038          ldb    S1
 002B 1D                      [2] 00039          sex
                                  00040 *  0 := v W0 -> 1
 002C DD 0D                   [5] 00041          std    W0
which brings up one of my favorite programming jokes:

The Motorola 6809, where SEX is sometimes followed by STD.

Thank you very much. Drive safely...
User avatar
barrym95838
Posts: 2056
Joined: 30 Jun 2013
Location: Sacramento, CA, USA

Re: A new article about 6502

Post by barrym95838 »

BillG wrote:
For the 6502:

Code: Select all

                          00037 ;  1 L v S1
 0029 A0 00           [2] 00038          ldy    #0
 002B A6 16           [3] 00039          ldx    S1
 002D 10 01 (0030)  [2/3] 00040          bpl    2f
 002F 88              [2] 00041          dey
 0030                     00042 2:
 0030 98              [2] 00043          tya
                          00044 ;  0 := v W0 -> 1
 0031 86 0D           [3] 00045          stx    W0
 0033 85 0E           [3] 00046          sta    W0+1
Same size, but one cycle faster for negative numbers:

Code: Select all

ext8to16:
    lda  #$7f
    cmp  S1
    sbc  #$7f
    ldx  S1
;
    stx  W0
    sta  W0+1
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: A new article about 6502

Post by BillG »

barrym95838 wrote:
Same size, but one cycle faster for negative numbers:

Code: Select all

ext8to16:
    lda  #$7f    ; 2 cycles
    cmp  S1      ; 3 cycles
    sbc  #$7f    ; 2 cycles
    ldx  S1      ; 3 cycles
;
    stx  W0
    sta  W0+1
YOU ARE WRONG!!!

The savings are 2 or 3 cycles! I think you did not count that tya below...

Thank you!
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: A new article about 6502

Post by BillG »

That technique saves one cycle on the 6800, but make the code larger.

Optimizing for size:

Code: Select all

                          00037 *  1 L v S1
 0029 4F              [2] 00038          clra
 002A D6 16           [3] 00039          ldab   S1
 002C 2A 01 (002F)    [4] 00040          bpl    2f
 002E 4A              [2] 00041          deca
 002F                     00042 2:
                          00043 *  0 := v W0 -> 1
 002F 97 0D           [4] 00044          staa   W0
 0031 D7 0E           [4] 00045          stab   W0+1
Optimizing for speed:

Code: Select all

                          00037 *  1 L v S1
 0029 D6 16           [3] 00038          ldab   S1
 002B 86 7F           [2] 00039          ldaa   #$7F      ; Thanks Mike B!
 002D 91 16           [3] 00040          cmpa   S1
 002F 82 7F           [2] 00041          sbca   #$7F
                          00042 *  0 := v W0 -> 1
 0031 97 0D           [4] 00043          staa   W0
 0033 D7 0E           [4] 00044          stab   W0+1
With that one post, you just earned a mention in two more of my compilers. Congratulations!
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: A new article about 6502

Post by BillG »

Saved another cycle and byte...

Code: Select all

                          00037 *  1 L v S1
 0029 D6 16           [3] 00038          ldab   S1
 002B 86 7F           [2] 00039          ldaa   #$7F      ; Thanks Mike B!
 002D 11              [2] 00040          cba
 002E 82 7F           [2] 00041          sbca   #$7F
                          00042 *  0 := v W0 -> 1
 0030 97 0D           [4] 00043          staa   W0
 0032 D7 0E           [4] 00044          stab   W0+1
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: A new article about 6502

Post by BigEd »

(BillG, I'm not sure if you intended these last few posts to be on this thread...)
BillG
Posts: 710
Joined: 12 Mar 2020
Location: North Tejas

Re: A new article about 6502

Post by BillG »

BigEd wrote:
(BillG, I'm not sure if you intended these last few posts to be on this thread...)
100% intended.

This thread is largely about comparing the 6502 to other processors; showing that the one detested by the OP is competitive is on topic.
User avatar
BigEd
Posts: 11464
Joined: 11 Dec 2008
Location: England
Contact:

Re: A new article about 6502

Post by BigEd »

Oh right. "Detested" would be a mischaracterisation, I'm sure.
Post Reply