Slashdot Mirror


6502 Machine Language for Beginners

savetz writes "If you've always wanted to learn 6502 assembly language, now's your chance. The full text of the classic, best-selling 1983 book Machine Language for Beginners is now on the Web. It includes examples and program code for Atari 8-bit, Apple ][, PET/CBM, VIC-20, and Commodore 64 computers."

106 comments

  1. I own this book by jvmatthe · · Score: 2, Interesting

    I have the copy of this that I bought back when it came out. Or, rather, my dad bought it for me. I remember showing it to him and having him ask "What? Are you going to start talking to the refrigerator with this?"

    Good old dad. Never has understood what "machine language" really means, and still doesn't care.

    It's a good book, if you want ot know 6502. Give it a try and then start coding for the Atari 2600 or Commodore 64.

    1. Re:I own this book by Elwood+P+Dowd · · Score: 1

      "What? Are you going to start talking to the refrigerator with this?"

      Good old dad. Never has understood what "machine language" really means, and still doesn't care.


      Of course, depending on the design of the refrigerator, couldn't he be correct? Sure, you'd need a serial interface, but...

      --

      There are no trails. There are no trees out here.
  2. Interesting fact... by Polo · · Score: 1

    The 6502 doesn't have an ADD instruction.

    1. Re:Interesting fact... by WolfWithoutAClause · · Score: 2, Informative

      Yes, it does; it's called ADC if I remember correctly.

      --

      -WolfWithoutAClause

      "Gravity is only a theory, not a fact!"
    2. Re:Interesting fact... by Anonymous Coward · · Score: 0

      ADC="Add with carry". Adds the arguments and the carry bit and sets the carry flag according to the result. The 6502 does not have multiplication or division instructions (other than bitshifts).

    3. Re:Interesting fact... by PD · · Score: 2, Funny

      But the Amiga had an HCF instruction. Halt and Catch Fire.

    4. Re:Interesting fact... by mivok · · Score: 2, Interesting

      But wouldnt that be add with carry, and not a straight add? Just being pedantic here mind you, because you do get the carry pretty much for free when making an alu, and stick a multiplexor on the carry line and you have the add instruction almost for free as well.

      Come to think of it, is there any advantage to having a straight add instruction over an add with carry? (Aside from preserving the carry bit for the next instruction, but that would be some weird programming)

    5. Re:Interesting fact... by mivok · · Score: 1

      What? Bitshifts _are_ the only multipication/division instructions worth considering!

      Seriously, I suspect that combined with the add (sorry adc) instruction.. (and sub, add a two's complemented negative number), pretty much any multipication/division can be performed, and probably not much slower (and in a lot of cases faster) than a proper multiply instruction.

      Floating point is a completely different matter though.

    6. Re:Interesting fact... by Frans+Faase · · Score: 2, Informative

      Floating point is a completely different matter though. The Acorn Atom (based on the 6502) did have a floating point library in ROM. I never tried calling it from ML, but it shows that it can be implemented.

    7. Re:Interesting fact... by rasteri · · Score: 3, Funny
      The 6502 doesn't have an ADD instruction.

      Ah well, at least it won't get distracted as easily.
      ---
    8. Re:Interesting fact... by Anonymous Coward · · Score: 2, Informative

      The additional instruction would not be "free" in terms of instruction code space. The 6502 reads one byte for the instruction and 0, 1 or 2 additional bytes as operands. All instructions with their addressing modes and implied operands have to fit into 256 codes. Appendix A of the book is a list of all opcodes (instruction, addressing mode, implied operand). There are 8 opcodes for ADC alone...

    9. Re:Interesting fact... by Polo · · Score: 2, Interesting

      Yeah, but you have to clear the carry (CLC), *then* Add with Carry (ADC) to perform what a normal ADD would have done on other processors. Struck me as funny when I first learned 6502.

    10. Re:Interesting fact... by WolfWithoutAClause · · Score: 1

      Not always.

      --

      -WolfWithoutAClause

      "Gravity is only a theory, not a fact!"
    11. Re:Interesting fact... by Dahan · · Score: 2, Interesting
      I don't think it's important what the instruction is named... sure, the 6502 doesn't have an instruction named "ADD", but it has add and subtract instructions--"ADC" and "SBC". It's like complaining the 80x86 doesn't have a "LDA" instruction... how are you gonna load your A register without LDA??? Oh, MOV AX... never mind.

      Now, the IBM 1620 didn't have hardware addition. You had to load in a lookup table that contained the answers to "2+2", "2+3", etc...

    12. Re:Interesting fact... by mivok · · Score: 1

      Heh.. I've forgotten all about 8-bit architectures (and never knew anything about x86 anyway, which I'd assume is the same idea) - after most recently been readin about ARM assembly it just never occurred to me that it would be more costly than adding one more opcode to the instruction set.

    13. Re:Interesting fact... by TheWanderingHermit · · Score: 1

      You're right -- ADC. It added an 8 bit number to the 8 bit accumulator and set the carry flag if it carried over. There was also SBC -- and you had to set or clear (can't remember which) the carry flag BEFORE subtracting to be sure you had accurate results.

    14. Re:Interesting fact... by WolfWithoutAClause · · Score: 1
      Seriously, I suspect that combined with the add (sorry adc) instruction.. (and sub, add a two's complemented negative number), pretty much any multipication/division can be performed, and probably not much slower (and in a lot of cases faster) than a proper multiply instruction.

      I seem to remember that a multiply or divide took more like 100 cycles on the 6502, but the 6809 could manage a multiply in something like 32 clock cycles, so a multiply instruction would probably have been a fair amount faster.

      --

      -WolfWithoutAClause

      "Gravity is only a theory, not a fact!"
    15. Re:Interesting fact... by Dahan · · Score: 2, Informative

      Of course FP can be implemented on a 6502... AppleSoft BASIC, written by MicroSoft and included in the ROM of all but the earliest Apple ][s (and available on floppy or cassette for the ones that didn't have it in ROM), had floating point routines, including trig functions, log, and square root.

    16. Re:Interesting fact... by Polo · · Score: 1

      Of course, when the carry is not set, you don't. ;)

    17. Re:Interesting fact... by Anonymous Coward · · Score: 2, Insightful

      Yeah, but you have to clear the carry (CLC), *then* Add with Carry (ADC) to perform what a normal ADD would have done on other processors. Struck me as funny when I first learned 6502.

      This isn't "funny" at all. Remember that when working with an 8 bit value, addition operations on single-bite, not to mention multi-byte, values have a high chance of overflowing the 8 bit register -- thus setting the carry. It's no more odd to CLC (Clear Carry) than to load a register with #$00 to start a loop.

      In fact, ADC (Add with Carry) is an abstraction that allows the same instruction to be used for both single- and multi-byte additions. The beauty of the ISA is the small number of operators to fit the small number of registers available.

      If ADC didn't work in this way, in what way would you have it work? And what would you like to see happen when you added #$FF to #$02? Forty miles in the slow uphill both ways gravel in my boots kids these days...

    18. Re:Interesting fact... by Anonymous Coward · · Score: 0

      That's not terribly interesting. It has the ability to ADD. The mnemonic is ADC, which is a lot more descriptive than ADD anyways.

      More interesting facts would be:

      The 6502 doesn't have a FUK instruction.
      The 6502 doesn't have a ASS instruction.
      The 6502 doesn't have a COK instruction.

    19. Re:Interesting fact... by FreezerJam · · Score: 1

      Don't forget all the fun stuff that happens inside ADC if you have executed SED.

      Check out footnote 1 in this reference...

      http://www.xmission.com/~trevin/atari/6502_insn_ se t.html ...to see the hoops the processor jumps through in decimal mode.

    20. Re:Interesting fact... by Polo · · Score: 2, Interesting

      Well, my experience up to the 6502 was with processors that had a lot more opcodes in their instruction set. The 68000, z80/8080, 6809 all had separate ADD and ADC-type instructions. (I won't even touch on 370 BAL, which had one-to-one constructs with fortran code)

      But the 6502 was SO minimal. They didn't bother with *any* fluff that could be cut out.

      So I found it amusing. ;)

    21. Re:Interesting fact... by mivok · · Score: 1

      I stand corrected.
      Life would be much easier though if 1 2 4 8 16... 1048576....were the only numbers. I think its time we made a nice shiny new standard to this effect.

    22. Re:Interesting fact... by 91degrees · · Score: 1

      But ADC and ADD are slightly different.

      Still, I'm more impressed with a few others. MIPS has no MOVE instruction in hardware, although it does in the assembly language. Early computers often had a subtract, but no add. Hardware was too expensive, so to add you simply subtracted a negative number.

    23. Re:Interesting fact... by Anonymous Coward · · Score: 0

      http://catb.org/~esr/jargon/html/entry/HCF.html for those who are wondering what that is about.

    24. Re:Interesting fact... by Anonymous Coward · · Score: 0

      You cleared the carry flag before adding, and set it before subtracting. pretty easy to remember.

    25. Re:Interesting fact... by WolfWithoutAClause · · Score: 1

      Interestingly, I think the RISC processor concept was actually based on the 6502. IRC the designers wondered how a processor with 1/8 the clock rate could run the same speed as the Z80. The answer was the low number of clock cycles per instruction, which in turn was related to the simple instructions. RISC just takes this concept to an extreme.

      --

      -WolfWithoutAClause

      "Gravity is only a theory, not a fact!"
    26. Re:Interesting fact... by freaq · · Score: 1

      What's so weird about preserving the carry bit for the next instruction?
      example: calculating a hash code

      magicNum=(a1+a2+...+a99+a100) mod r1

      adc seems almost ideally suited, especially if r1 = 256
      (in all fairness, my instructors tell me that hash codes are generally implemented as multiplications, so this _could_ be a bit of a stretch!)

      K:|

      --
      united states nuclear device terrorist bioweapon encryption cocaine korea syria iran iraq columbia cuba
    27. Re:Interesting fact... by mivok · · Score: 1

      I meant it would be some weird programming that depended on using add (thereby preserving the carry bit from the previous instruction for the next one), as opposed to adc.
      Of course, as soon as I mentioned weird I had a feeling that it had probably already been done, and is probably even common.

    28. Re:Interesting fact... by KewlPC · · Score: 1

      MIPS, being a RISC processor, wouldn't have a MOVE instruction. It does have the normal load and store, though, IIRC.

      You just LOAD one register with the contents of another.

    29. Re:Interesting fact... by 91degrees · · Score: 1

      You can't do "lw $1 $2" to copy from one reg to another either. You have to do "add $1 $2 $zero". Nertheless,m the assembly language specification does give you the move instruction, and simply substitutes it with the add.

      Well, I thought it was a little odd. Sensible, but odd.

  3. Understanding computers by Anonymous Coward · · Score: 4, Insightful

    An old eight bit processor is the best tool for understanding how computers work. They are simple enough to avoid discouraging the student, but the core concepts are still the same today. There are free simulators, so students don't have to put up with uncomfortable data entry or long loading times.

    1. Re:Understanding computers by Anonymous Coward · · Score: 1, Interesting

      On the other hand, it's hardly a good tool for learning how to design computers that work today. While you can draw a number of parallels between an 8-bit microprocessor and a 64-bit microprocessor, the design challenge of a 64-bit microprocessor is so much greater than the 8-bit, you absolutely must use higher level design techniques, while you could conceivably get away with hand designing an entire 8-bit processor (as was, in fact, done).

      Incidentally, if you want a real learning experience, why not a 4-bit processor? :)

    2. Re:Understanding computers by Paranoid · · Score: 1

      Are we talking about designing software to run on such a processor, or designing such a processor itself? While I agree that designing a modern processor is much more complex, designing software that runs on such a thing seems quite similar, to me at least.

      --
      Paranoid
      Bwaahahahahaa.
    3. Re:Understanding computers by fruity_pebbles · · Score: 1
      I think 8-bit processors like the 6502 aren't the greatest learning tools because the instruction sets are somewhat limited and full of idiosyncrasies that will make inexperienced programmers pull out their hair. I'd go for a 16-bit or 32-bit processor with a nice clean instruction set, e.g. 68000, PDP-11, VAX. There are probably newer processors that fit that description too, but I haven't done any serious assembly programming in 10 years.

      I'd also go for a very simple computer to start with, something with very few peripherals and a very simple (or no) OS - something that will let you get at the guts of the hardware and get experience manipulating peripherals, doing hardware-level I/O, writing interrupt handlers, etc.

    4. Re:Understanding computers by usotsuki · · Score: 1

      Good emulators - such as Appler, Dapple ][, AppleWin and most Commode 64 emulators ;) - also allow you to load programs into memory from the local disk (instead of just from within the emulation). (All of these emulate 6502-class CPUs)

      Dapple ][ comes with a simple 65SC02 debugger which offers dump-to-file and local-file-load capability; this can be tied together with any assembler and disassembler, if you have a header-attachment tool (Dapple's BIN2PG2 works well). I personally use this - partially my handywork - to demo my C software. :)

      -uso.

      --
      Dreams, dreams, don't doubt dreams, dreaming children's dreaming dreams. Sailor Moon SS
  4. Learning old machine languages???? by Tuxinatorium · · Score: 2, Funny

    Yeah, that ranks right up there with sorting my sock drawer or beating my head against the window.

    1. Re:Learning old machine languages???? by Escaholic · · Score: 2, Interesting


      I must be a weirdo, cos I actually find it interesting and quite amusing. I spent my entire childhood on a PC (my dad brought one home in 1983), all my friends back then had Vic-20's, C-64's or Spectrums.

      I find it particularly amazing to see how much instructions sets have progressed. I really do like the ARM instruction set (but how will they make a superscalar ARM CPU with conditional instructions?), the PowerPC is pretty damn good too. MIPS is bearable, but the x86 set with it's ridiculous 8 registers is a horrible patched-then-repatched abortion that should be put to sleep asap!

      Then again, 8 registers is bliss in comparison to the 3 I just found out the 6502 has! :-)

    2. Re:Learning old machine languages???? by adri · · Score: 1

      Yes, but the 6510 had this cute thing called "zero-page" which meant you had quite a bit of scratch space if you knew what you were doing. It was faster than doing full 16-bit address operations.

      3 registers isn't nearly as bad as you think.

    3. Re:Learning old machine languages???? by Frans+Faase · · Score: 1

      This idea of zero-page memory addressing was really smart. This gave you 256 semi-registers. This lead to very compact machine code. I liked the design of the 6502 better than the Z80 another 8-bit processor.

    4. Re:Learning old machine languages???? by adri · · Score: 1

      The Z80 did have an abundance of registers and the block moves were quite useful and fast.

      And the hidden instructions! when you found you could treat IX and IY as 8-bit registers (XH, XL, YH, YL) made for some fast sprite routines.

      Oh, and the alternate register set was very useful when writing little interrupt handlers - you could just swap register sets to save push/pop'ing everything..

    5. Re:Learning old machine languages???? by Frans+Faase · · Score: 1

      Without wanting to start a flame war, but it seems that the 6502 was more of a RISC type of processor (with respect to the instruction set), whereas the Z80 was more SISC like, with all kinds of instructions for special things. I liked the rather orthogonal design of the 6502 instruction set. It was good for making compilers. See also www.cc65.org

    6. Re:Learning old machine languages???? by Frans+Faase · · Score: 1
      I agree, the 6502 is not a RISC processor. I simply said "more of a RISC type of processor".

      I would like to remark that in a sense the zero page could be considered as a "large number of multipurpose registers".

    7. Re:Learning old machine languages???? by blancolioni · · Score: 2, Insightful

      See also www.cc65.org

      Now I shall demonstrate why Ada is a better choice for this sort of thing.

      In this bit of documentation, it is suggested that you get better code by putting an extra cast into an expression which keeps everything nicely eight bitted. The C language definition AFAIK requires that the compiler behave in this (odd) way.

      The Ada equivalent is this:

      A : Octet;
      ...

      if (A and 15) = 0 then

      You don't have to remember to cast, and it's all 8 bit. Ha!

      In the future, all new Commodore 64 software will be written in Ada :-)

  5. Contiki by Frans+Faase · · Score: 2, Informative

    I learned Machine Language programming on the 6502 from "Atomic Theory and Practice" by David Johnson-Davies. The 6502 is a rather neat processor. I even once wrote a compiler for a self made language that would compile to 6502 machine code. For a proof that some rather impressive things can be done with it, have a look at contiki.

  6. Everybody knows it already by Curt+Cox · · Score: 1

    One of the best programmers I know personally, considered this book irrelevant, even when it was still relevant.

    "The ability to program the 6502 is innate. It only has three registers. How hard can it be?"

  7. Those were the days -- Like the first NCC-1701 by TheWanderingHermit · · Score: 3, Interesting

    When I saw this, my first thought was of the scene in ST:TNG with Scotty and Picard on the hologram bridge of Kirk's Enterprise. Scotty liked the first Enterprise because he could tell the speed by the feel of the deck plates and Picrad said the Enterprise was superior than the Stargazer in terms of numbers, but he still often wished he was on the Stargazer.

    I learned almost everything I know about computers from my Apple //e. I knew the monitor ROM backwards and forwards. I used an amazingly powerful assembler called ORCA/M (known for it's macros and libraries), and learned hardware from books about the Apple //e. It was a wonderful world to learn and play in. I sold my //e to buy an Amiga. I still have the Amiga, but I wish I still had that //e -- it had a FULLY SOCKED motherboard, with a modified ROM that gave me extra features (I did the ROM mods myself), and a few nice accessories -- like a hard drive with a whopping 5 Meg of storage and a memory card that gave me over a megabyte of online memory -- which I used as a ramdrive.

    Just like Picard and the Stargazer, I often wish I were programming on my old //e (I had even figured out how I could make it multi-task w/ a clock card -- but never got around to programming it) instead of worrying about networking and web pages and relational databases.

    1. Re:Those were the days -- Like the first NCC-1701 by Anonymous Coward · · Score: 0

      In the Trek Classic episode "That Which Survives", Scotty "spoke of the feel of the ship being wrong." Spock noted Scotty's "feel" and determined that something was wrong with the ship even though "instrumentation reads correct." Search the transcript for occurrences of "feel".

  8. How did it evolve ? by dargaud · · Score: 1
    A little twang of nostalgy, remembering learning 6502 assembler on an Oric-1 back in 1981 when I was 12... The Basic was so slow and I couldn't wrap my brain around the stupid Forth.

    How did the 6502 evolve ? Does it still have some descendants that can use the same machine code ?

    --
    Non-Linux Penguins ?
    1. Re:How did it evolve ? by Anonymous Coward · · Score: 0

      There is a 16-bit contraption called 65816. Configure your binutils with "--enable-targets=w65-wdc-none" and try "objdump --disassemble-all -bbinary -mw65" on some files.

    2. Re:How did it evolve ? by Anonymous Coward · · Score: 1, Informative

      There is a backwards compatible 16 bit version, the 65816. It was made by Western Design Center. The Apple IIgs had one running at 2.3 MHz. There also was a 20MHz upgrade cartridge for the C64 (SuperCPU), and the SNES used a lower power version, the 65c816, at 2.8 MHz.

      http://www.westerndesigncenter.com/ch816S.html

    3. Re:How did it evolve ? by sydres · · Score: 1

      also I believe that that part of the architecture
      was incorporated into the original 68k chips.Could be wrong though? the 68k's eventually
      went out of style for desktops though they are still used in embedded communications as well as
      being the basis for the dragonball line (used in cheap palms, royal pdas')I really don't know wether the assembly works from the 6502/65816 though?

    4. Re:How did it evolve ? by usotsuki · · Score: 1

      65C816 used in the Super NES and Apple IIgs. Still sold. CPU speed up to 20 MHz.

      -uso.

      --
      Dreams, dreams, don't doubt dreams, dreaming children's dreaming dreams. Sailor Moon SS
  9. Teaching tools by Paranoid · · Score: 2, Interesting

    I agree that simpler is better, when learning/teaching core computer architecture concepts. However, rather than using old computer simulators, I personally prefer Atmel AVR microcontrollers. With a bare minimum of hardware, you can build a miniature computer from scratch and control every bit of the software that goes into it. It's just a good feeling to know that you aren't relying on anyone else's ROM code to do the dirty work. Plus it's an 8-bit RISC processor with 32 general-purpose registers, which is quite nice when you get too lazy for assembly and break out the gcc cross-compiler. =)

    --
    Paranoid
    Bwaahahahahaa.
  10. Two questions? by Anonymous Coward · · Score: 0

    First is: how relavent is this to modern machine languages? I studied some MIPS assembly in college but I'm not sure if that's even still being used. Not sure how much it's going to be used in the new Itanium chips or in my next cell phone. Is learning one machine language equivilent enough that you can learn them all easily enough?

    Second question is, are there any good emulators and programs for this available to accompany the book?

    Hope someone here can shed some light on these, thanks.

    1. Re:Two questions? by archeopterix · · Score: 2, Informative
      Is learning one machine language equivilent enough that you can learn them all easily enough?
      Mu.

      The concepts from 8-bit processors, like instructions, registers and flags are still there and haven't changed much. Of course the new processors brought new concepts - virtual modes, paging, sophisticated memory protection schemes, interrupt hierarchies, numeric coprocessors, hinted jumps, various kinds of SIMD instructions and so on and so on.

      On the other hand, most developers are pretty much separated from the processor - the operating system and the compiler are there to manage all of the above. Even if you want a super-optimized piece of code, it's a good idea to start by looking at the compiler output.

      This is of course only true if you don't plan to write your own OS or a compiler.

  11. Where I learnt 6502 machine language by TheLink · · Score: 1

    When I got my apple II+ clone about 2 decades ago, it came with a book that was 3 books stuck together. I think the taiwanese clone company lumped 3 useful books together.

    There was a section about BASIC. A section about the Apple II.

    It had all sorts of technical info on it - the IO addresses of the Apple II (keyboard, sound, graphics, disk, etc)and what they did, a list of 6502 opcodes, and even how many cycles they take (which doesn't seem to be in the online book being discussed). The number of cycles was useful when I was modifying the DOS disk code for my purposes.

    From that book and the Apple II clone, I learnt to write 6502 machine language programs without an assembler - just type the hex in. After all there wasn't a built-in assembler. Also modifed a few games - added features even.

    Unfortunately I don't know where that tattered book is now. It was pretty good - I don't recall it having many if any mistakes in the technical info.

    Basically I honed the very useful skill of RTFM from that book at an early age, because the manual was indeed really fine.

    --
    1. Re:Where I learnt 6502 machine language by TheWanderingHermit · · Score: 1

      In hindsight -- why didn't you just load Integer BASIC and use the mini-assembler? I used that MANY times when troubleshooting code or writing a small program/routine. It didn't handle names/labels for addresses, but it did convert the instructions to hex.

      Or did your model come with Intege BASIC?

    2. Re:Where I learnt 6502 machine language by TheLink · · Score: 1

      Didn't have integer basic at the start - though it was mentioned in the book too.

      Clone had 64K of RAM, but by the time I found some software which actually loaded integer basic into the shadow ram (d000-FFFF), I could convert plenty of instructions to hex by myself ;).

      Still remember a number of them and the cycle times too.

      --
  12. The ultimate home 6502 machine by IceFreak2000 · · Score: 1, Informative

    IMHO, the ultimate 6502 based home computer had to be the BBC Micro; those of us educated in the UK during the 80's will almost certainly remember these ubiquitous machines sitting in virtally every computer lab in every school up and down the country.

    One of the great things about this system was that it's BASIC interpreter contained a full 6502 assembler, and they produced some excellent documentation. Check out the Advanced User Guide from The BBC Lives! site. For my money, you couldn;t get a better start to 6502 development.

    --
    Life is like a sewer; what you get out of it depends on what you put into it...
  13. 6502 vs Z80 by Martin+Spamer · · Score: 1


    This brings back so many memories of 6502 vs. Z80 arguments as vicious as any Linux vs. Windows debate, or Betamax vs. VHS, or .... Food for thought.

    1. Re:6502 vs Z80 by turgid · · Score: 1

      Z80 all the way! :-)

    2. Re:6502 vs Z80 by Stuntmonkey · · Score: 1

      So who won?

    3. Re:6502 vs Z80 by Anonymous Coward · · Score: 0

      You see any Z80 articles on Slashdot?

    4. Re:6502 vs Z80 by McLae · · Score: 1

      The current name for 'Z80' is 'embedded system'. I happened to look at a disk drive (for my x86) several years ago and noticed a nice fat Z80 processor! I am sure there are several ports of Linux for Z80, and there might be more sold today than 5 years ago. Old processord never die, they just become embedded.

    5. Re:6502 vs Z80 by pork_spies · · Score: 1

      Anybody with a Gameboy Color has a Z80 machine.

    6. Re:6502 vs Z80 by Anonymous Coward · · Score: 0

      >Anybody with a Gameboy Color has a Z80 machine.

      You mean custom Z80. That's right, it's a custom, chopped-up Z80 inside Gameboys. It misses about 512 instructions, a few registers, etc...

      Also, I think you mean Gameboy, Gameboy pocket, Gameboy Light OR Gameboy Color. It's just that the one inside the GBC was able to run twice as fast as the others.

      As for the GBA... I think it still has the custom Z80, dedicated to audio functions (not sure).

  14. Oh sure, now you tell me... by John+Harrison · · Score: 2, Funny
    When I was in 4th and 5th grade I REALLY wanted to learn machine language for the C64. But I could never find an assembler. I had no idea how people found an assembler in order to write ML programs. Now I find out that I could have bought this book and typed in the assembler in the back that was written in BASIC. At this point that isn't helpful information, it is simply frustrating.

    As a side note, I remember being all excited when I found out that we were going to write ML programs in intro to computer theory. Little did I know that the name "ML" is overloaded in the computer languages department. We didn't learn machine language, we learned the "other" ML. Of course I did get really good at recursion. Not that I ever use it now.

    1. Re:Oh sure, now you tell me... by CTalkobt · · Score: 1

      Where to find an assembler?

      Back in my day, we hand assembled. Actually I did hand-assemble the first month or two. Most of my programs were fairly small. I picked up Buddy / Pal assembler and it changed things.

      Hand assembling gives you a much better understanding of how the code actually works and allows you to understand:

      LDA #$01
      BIT 169*256+0

      which would allow the following:

      LDA #$01

      LDA #$00

      depending on where you jumped.

      --
      There's a gorilla from Manilla whose a fella that stinks of vanilla and has salmonella.
    2. Re:Oh sure, now you tell me... by Overzeetop · · Score: 1

      Damn! I knew how were to buy assembler, but didn't have the princly sum of $199 to spend on it. I coded by hand. I never made the machine do much in ML, but it made me understand computers from a whole different perspective.

      Then, as a co-op student at NASA I ran into a mathemetician/programmer on a laser-ranging project who did a lot of ML coding by hand in order to squeeze every last byte out of the legacy systems' memory. His favorite story was about a college grad who came in looking for a job. When they asked him which languages he knew, he told them he could program in any language and he asked what language they used. When the m/p told him "machine code," the guy frowned, turned around and left.

      --
      Is it just my observation, or are there way too many stupid people in the world?
    3. Re:Oh sure, now you tell me... by John+Harrison · · Score: 1
      My first job out of college was with a group that did some hard-core transaction processing stuff on IBM System 390s. They did a lot of work in assembly because, "You can't really trust a compiler." I didn't stay in the group very long though so I never had to do any of it myself.

      I just wish I had run into this book in 1984...

    4. Re:Oh sure, now you tell me... by Anonymous Coward · · Score: 0

      When I was a kid, I typed in an assembler, called MetaMon or something, from a magazine. Actually, it was a machine code monitor with a -- what do you call it -- a line assembler. It was pretty good. A year or so later, my little sister enlisted my help in making stamped, self-addressed envelopes to send in to a children's TV show competition. She won a minibike. She sold it back to the store for a few hundred bucks. For my help, I asked that she buy me a fully symbolic assembler (called Laser Genius I think). That assembler changed my life. Funny how these things can happen.

      About the other "ML", I resisted learning that for a long time. I thought, "what a retarded name for a language. Everyone knows that ML stands for machine language!" But after learning it, it's now my favorite. I'm now writing some Open Source stuff in OCaml.

  15. 6502 as a RISK / C64 comments by CTalkobt · · Score: 2, Insightful

    I've always considered the 6502, more or less, a RISC processor due to it's uh, "simpleness".

    It has 3 register, 8-bit address lines, 1 accumalator and two index registers. That was pretty much it along with 52(I think) opcodes and variants in terms of addressing modes.

    The chip was neat in that it was simple enough for someone programming it to be cognizant of everything going on inside the processor: Ok, at this stage the accumalator is __, .X is __, .Y is __ and the carry flag is set and the Z flag is off were my normal thoughts while writing assembly.

    I can't speak for any of the other 6502 computers but the way that it was used on the C-64 was an engineer's wet dream. It was coupled with other chips that were simple in their operation but complex in their innards. There was no filtering of bad input data - if you fed it crap, the chip was free to interpret it however it wanted.

    This ability to send "crap" data was pretty neat because once you got the timing down right you could do pretty miraculous things - that weren't even listed as features for those chips.

    Bonus question: How can you disable the NMI interrupt on the 6502? (Yes, there is a way).

    --
    There's a gorilla from Manilla whose a fella that stinks of vanilla and has salmonella.
    1. Re:6502 as a RISK / C64 comments by Anonymous Coward · · Score: 0

      Bonus question: How can you disable the NMI interrupt on the 6502? (Yes, there is a way).

      Just jump on the fucking thing.

    2. Re:6502 as a RISK / C64 comments by fudgefactor7 · · Score: 1

      "Bonus question: How can you disable the NMI interrupt on the 6502? (Yes, there is a way)."

      Jumper a wire on the motherboard. IIRC it was NMI to ground or something like that. On the old Apple II systems, that would dump any program to assembler and from there you could do things like copy the uncopyable, etc.

    3. Re:6502 as a RISK / C64 comments by CTalkobt · · Score: 1

      Actually, I meant without any hardware modifications - there was a way to do this in software.

      --
      There's a gorilla from Manilla whose a fella that stinks of vanilla and has salmonella.
    4. Re:6502 as a RISK / C64 comments by Anonymous Coward · · Score: 0
      It has 3 register, 8-bit address lines, 1 accumalator and two index registers. That was pretty much it along with 52(I think) opcodes and variants in terms of addressing modes.

      Don't you mean it has 1 general purpose register (the accumulator), and two index registers (X and Y), 16-bit address lines, 52 instructions, 158 opcodes, and 13 addressing modes?

    5. Re:6502 as a RISK / C64 comments by Anonymous Coward · · Score: 0

      Which one was it fffe or fffc?

      Just copy the Kernel Rom into the RAM, toggle a bit in zeropage address 0 or 1.

      Then set address to a return instruction to circumvent any instruction.

      I might be wrong though. It's a couple of years now I last touched a commodore 64.

      bye

    6. Re:6502 as a RISK / C64 comments by CTalkobt · · Score: 1

      Okay - I got tired of looking back at this story to see if anybody came up with the answer.

      To disable the NMI interrupt on a 6502 without any hardware modifications do the following:

      1) Trigger an NMI interrupt.
      2) Within the NMI interrupt _do_not_ execute a RTI, instead pop off the contents pushed on the stack when the interrupt occurred and go along your merry way.

      Since an NMI can't occur in the middle of an NMI - you're effectively having one long NMI interrupt and the others are disabled.

      --
      There's a gorilla from Manilla whose a fella that stinks of vanilla and has salmonella.
    7. Re:6502 as a RISK / C64 comments by KewlPC · · Score: 1

      Didn't the C64 use a 6510, not a 6502?

  16. Jim Butterfield by Anonymous Coward · · Score: 0

    Where have you gone, Joe Dimaggio?
    The nation turns its lonely its lonely eyes to you.

    Anyway, Jim was the 6502 guru who disassembled the C64 and PET ROMs and started a million kids on their path to programming fame and fortune. Where is he at these days?

    1. Re:Jim Butterfield by Anonymous Coward · · Score: 0

      A friend of mine tells a story of how he was at university and he discovered the internet. This was before the internet was accessible to the general public. On a whim, he emailed Jim Butterfield to say hi. Jim replied. It was like receiving a message from God. "Wow", he thought, "this internet thing is pretty cool".

  17. NMI by Anonymous Coward · · Score: 0
    Bonus question: How can you disable the NMI interrupt on the 6502? (Yes, there is a way).

    First you trigger the NMI, and then you run the rest of the program inside the NMI handler.

  18. 6809-68k, not 6502-68k by mughi · · Score: 1
    also I believe that that part of the architecture was incorporated into the original 68k chips.Could be wrong though?

    Actually, you're confusing a few there. The 6502 was from MOS Technologies. The 6800 series, on the other hand, was from Motorola. That is the line that was the little brother to the 68k series.

    MOS Technolgies was mainly former Motorola people from the 68k group, so it looked a little similar. However after the problems with their 6501, they did stay different enough.

    And the 6809 ended up being a very nice microprocessor, with fewer of the 6502 limitations (16-bit addressing, two stack pointers, more generic opcodes with fewer register limitations), and being closer to the 68k in use. That is, going from the 6809 to the 68000 was much easier than from the 6502 to the 68000.

    1. Re:6809-68k, not 6502-68k by sydres · · Score: 1

      I stand Corrected thank you

  19. aaa!!! by themusicgod1 · · Score: 1

    Theres an assembler with interger basic?! Please tell me how to start/utilize it...is it a keyword like INITIALIZE, LOAD, SAVE ? or am i thinking of DOS 3.1 ? shoot me a link!

    --
    GENERATION 26: The first time you see this, copy it into your sig on any forum and add 1 to the generation.
    1. Re:aaa!!! by TheWanderingHermit · · Score: 1

      I don't remember exactly. It's been SOOO long since I used it.

      I think, once Integer BASIC is loaded into the language card, you do a CALL -151, and I think a simple exclamation point does it -- like !.

      I'm not sure, though, it's been just too long and I only used it for trouble shooting or writing quick code. There aren't any load/save functions -- you'll have to use BSAVE (is that the right command -- again, I've forgotten some of these) and you can't use labels -- you have to specify addresses directly (like JSR $FDED to call COUT to print a character) for both subroutines and loading/saving bytes in locations.

      I hope this helps.

  20. Re:100 cycles? by freaq · · Score: 1

    How could that be?<br>
    <pre>
    ;start psuedocode
    ; get binary # A
    ; get binary # b
    ; sum := 0
    ; while b != 0
    ; if (right bit of b on)
    ; add A to sum
    ; shift A one bit left
    ; shift b one bit right
    ; output sum
    ;might want to check flags before trusting result
    ;finish</pre>

    start real code<pre>
    lod 0, sp, r1 ; Grab operands from stack
    lod -1, sp, r2
    mov r0, r3 ; Initialize result to zero

    or r2, r0, r2 ; check if we're at zero to begin with
    startMultiply
    bz doneMultiplying
    and r2, 1, r0
    bz nextColumn ; if the last bit of multiplier is 1,
    add r1, r3,r3 ; add 'product', (check for overflow too)
    bc overflowed ;
    nextColumn ; move one column over

    shl r1, 1 ; shr moght set zero flag
    shr r2, 1 ; so we don't have to repeat 'or r2, r0, r2'
    br startMultiply ; (saves one step every time through the loop)

    --
    united states nuclear device terrorist bioweapon encryption cocaine korea syria iran iraq columbia cuba
  21. Re:100 cycles? by freaq · · Score: 1

    [damn twitchy submit finger sorry]

    Am I missing something about the 6502 set? How could that take so horking long with only 8 bits?

    hopefully this bit from the (16 bit) craps virtual assembly language won't be _too_ obtuse:
    http://www.cs.camosun.bc.ca/courses/comp1 82/barker/
    (this is my code, not my instructors. mens culpa.)

    ;start psuedocode
    ; get binary # A
    ; get binary # b
    ; sum := 0
    ; while b != 0 {
    ; if (right bit of b on)
    ; add A to sum
    ; shift A one bit left
    ; shift b one bit right
    ; }
    ; output sum
    ; ;might want to check flags before trusting result
    ;finish</pre>

    ;start real code

    lod 0, sp, r1 ; Grab operands from stack
    lod -1, sp, r2
    mov r0, r3 ; Initialize result to zero

    or r2, r0, r2 ; check if we're at zero to begin with
    startMultiply
    bz doneMultiplying
    and r2, 1, r0
    bz nextColumn ; if the last bit of multiplier is 1,
    add r1, r3,r3 ; add 'product', (check for overflow too)
    bc overflowed ;
    nextColumn ; move one column over

    shl r1, 1 ; shr moght set zero flag
    shr r2, 1 ; so we don't have to repeat 'or r2, r0, r2'
    br startMultiply ; (saves one step every time through the loop)

    overflowed
    ; set err flags
    doneMultiplying

    worst case for 8 bit: 4 + (8*8) = 68 (except you're gonna have an overflow)
    best case: 4 + 1 = 5
    average: 4 + (4*6) + (4*8) = 60
    --
    compsci finals coming up, why should i moderate?

    --
    united states nuclear device terrorist bioweapon encryption cocaine korea syria iran iraq columbia cuba
  22. Undocumented Instructions still undocumented? by blancolioni · · Score: 2, Interesting

    The real instructions only used up about a third or so of the available opcodes, and while most of the rest simply froze the processor, there were others that had interesting and predictable effects, and were in fact used by some of the C64 games. See this for the exciting low down.

    So, I've been writing a 6502 Ada compiler just for the heck of it, and it's much more fun than targeting these new-fangled, regular instruction sets. Clearing space on the stack is great. The fastest way to do it depends on how much space you need; with one or two bytes, a couple of PHPs, three to six or so and you transfer SP to X, decrement the appropriate number of times, then send X back to SP. More than sixish, and you should TSX, TXA, SBC, TAX, TSX.

    You'd be astounded at the machinations required for addressing variables on the stack, and mortified at the way a simple CMP instruction has the arrogance to affect the overflow bit. Unfortunately, this comment is to small to go into it.

    Meeeeeemmmoooorrrrriiiiieeeeeeeeeees ....

    1. Re:Undocumented Instructions still undocumented? by bzipitidoo · · Score: 1

      Illegal opcodes did NOT freeze the 6502. When the 6502 encounters an illegal op, it performs a "reset": it takes the last 2 bytes of memory ($FFFE and $FFFF) and uses that as an address to jump to. If that address contains bad code, then of course it goes into an infinite loop.

      --
      Intellectual Property is a monopolistic, selfish, and defective concept. It is "tyranny over the mind of man"
  23. Re:100 cycles? by WolfWithoutAClause · · Score: 1
    Yeah, well, that isn't 6502 assembler. I don't have the code to hand.

    But IRC the inner loop of the multiply needed something like 5 or 6 instructions, and each instruction takes 2-5 cycles to execute. Worst case you need to go around the loop up to 8 times; so it's easy to add up to over a hundred cycles.

    --

    -WolfWithoutAClause

    "Gravity is only a theory, not a fact!"
  24. How hard can it be? by Ozor · · Score: 0

    The 6502 processor is one of the most challanging to program. You have limited memory, limit cyles before you screen sync falls apart. I person am programming demos for the Atari 2600 and that use a 6507. Which is just a cost-reduced 18 pin version, same instruction set. The limitation on the processor lend you to write faster and more optimized code.

  25. Interesting fact... by Anonymous Coward · · Score: 0

    Early processors didn't have ROR.

  26. From the introduction by Anonymous Coward · · Score: 0

    "In any event, a talent for conserving bytes, like skill at trapping wild game, will likely become a victim of technology. It will always be a skill, but it seems as if it will not be an everyday necessity."

  27. Re:100 cycles? by freaq · · Score: 1

    10-4
    I sit corrected and edified. I forgot about the multiple-cycle instructions.

    --
    united states nuclear device terrorist bioweapon encryption cocaine korea syria iran iraq columbia cuba
  28. Back in the day by pork_spies · · Score: 2, Insightful

    The earliest religious war I took part in was between the 6502 users (eg PETs) and the good guys, like me, who hacked on the Z80 (eg most/all CP/M machines).

    Have to say that the intellectual case for the 6502 looked stronger, but seems to me that the Z80 has lasted the course better (though not as well as the 8080 family which the Z80 was meant to be an improvement on!).

  29. why would I want to disable the NMI? by Anonymous Coward · · Score: 0

    it doesn't hurt nothing.

    1. Re:why would I want to disable the NMI? by Anonymous Coward · · Score: 0

      I've never used this trick myself; I only read about it years ago.

      As it's possible to make a trivial interrupt handler that just returns immediately, I can imagine only two possible reasons for disabling NMI entirely:

      1. The stack is in a state where you can't afford to push the return address. Perhaps it's mapped out of RAM, too full, or you're using the stack pointer as a temporary register.
      2. The code must be precisely synchronized with other devices.
  30. Memories! by wackybrit · · Score: 1

    Learning 6502 was my first foray into assembly language programming in 1988/89 on the BBC Micro. It was so basic that even I could understand it at the time as a youngster.

    The 6502 was beautiful in its simplicity, and I have to second the comments above about it almost bieng like a RISC chip.

    And after all this time, there's still a spelling error in the book: ;DEFINE LABLE "TWO" AS 2. I do think this book is way too Atari specific though. I had a 6502 book that was platform independent.

    (BTW, I think the NES also used the 6502. So this book should be handy for people coding NES games for the emulators :-))

  31. C64 owns. by CheesyMoo · · Score: 1

    I stole a Comodore 64 from my grandma back in like 4th grade, God bless it, that got me into coding... gotta love Eliza programs.

  32. Re: Primary language of moisture vaporators by Anonymous Coward · · Score: 0

    >> Of course, depending on the design of the refrigerator, couldn't he be correct? Sure, you'd need a serial interface, but...

    More importantly, does the fridge speak 'Bocce'?? :)

  33. Lots of 6502 current info by Anonymous Coward · · Score: 0

    I just found this article on slashdot ( havent been here for a while ) and was most surprised by the fact that no one mentioned a few things about the 6502 that are really worth mentioning. Heck, this message could become a new topic/article itself. Follow the list:

    1) The 6502 is still manufactured by a company called Western Design Center ( http://www.westerndesigncenter.com ) . They even produce a 6502 based microcontroller, as well as the 16 bit processor used in the Apple 2 GS ( on microcontroller version too ).

    2) The 6502 is a dream microprocessor for people trying to learn digital electronics. There are lots of people designing home made computers based on this chip, and it is a great self-learning project. http://www.6502.org is the place to go to get information on this subject. Some of them are very easy to build and there is lots of software available. People are also building IDE interfaces, PC keyboard adaptors, etc.

    3) My preferred project can be found on http://65c02.tripod.com . It is built using a really cool program to layout printed circuit boards, that you can design on your PC and order through Internet. Check it out.

    I guess this is the kind of information that should get the slashdot crowd really excited...