



6502 Machine Language for Beginners 106
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."
I own this book (Score:3, Interesting)
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.
Re:I own this book (Score:2)
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...
Interesting fact... (Score:2)
Re:Interesting fact... (Score:3, Informative)
Re:Interesting fact... (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.
Floating point is a completely different matter though.
Re:Interesting fact... (Score:2, Informative)
Re:Interesting fact... (Score:3, Informative)
Re:Interesting fact... (Score:2)
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.
Re:Interesting fact... (Score:1)
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.
Re:100 cycles? (Score:1)
<pre>
;start psuedocode
; get binary # A
; get binary # b
; sum
; 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 doneMultip
Re:100 cycles? (Score:1)
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/comp 1 82/barker/
(this is my code, not my instructors. mens culpa.)
;start psuedocode
; get binary # A
; get binary # b
; sum
; while b != 0 {
; if (right bit of b on)
; add A to sum
; shift A one bit left
; shift b one bit right
; }
; ou
Re:100 cycles? (Score:2)
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.
Re:100 cycles? (Score:1)
I sit corrected and edified. I forgot about the multiple-cycle instructions.
Re:Interesting fact... (Score:2)
Re:Interesting fact... (Score:2, Funny)
Re:Interesting fact... (Score:2, Interesting)
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)
Re:Interesting fact... (Score:2, Informative)
Re:Interesting fact... (Score:1)
Re:Interesting fact... (Score:1)
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:|
Re:Interesting fact... (Score:1)
Of course, as soon as I mentioned weird I had a feeling that it had probably already been done, and is probably even common.
Re:Interesting fact... (Score:3, Interesting)
Re:Interesting fact... (Score:2)
Re:Interesting fact... (Score:2)
Re:Interesting fact... (Score:2)
Check out footnote 1 in this reference...
http://www.xmission.com/~trevin/atari/6502_insn
Re:Interesting fact... (Score:2, Insightful)
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
Re:Interesting fact... (Score:3, Interesting)
But the 6502 was SO minimal. They didn't bother with *any* fluff that could be cut out.
So I found it amusing.
Re:Interesting fact... (Score:2)
Re:Interesting fact... (Score:3, Funny)
Ah well, at least it won't get distracted as easily.
---
Re:Interesting fact... (Score:3, Interesting)
Now, the IBM 1620 [brighton.ac.uk] didn't have hardware addition. You had to load in a lookup table that contained the answers to "2+2", "2+3", etc...
Re:Interesting fact... (Score:1)
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.
Re:Interesting fact... (Score:1)
You just LOAD one register with the contents of another.
Re:Interesting fact... (Score:1)
Well, I thought it was a little odd. Sensible, but odd.
Understanding computers (Score:4, Insightful)
Re:Understanding computers (Score:1, Interesting)
Incidentally, if you want a real learning experience, why not a 4
Re:Understanding computers (Score:2)
Teaching tools (Score:3, Interesting)
Re:Understanding computers (Score:1)
I'd also go for a very simple computer to start with, something
Re:Understanding computers (Score:1)
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 ha
Learning old machine languages???? (Score:3, Funny)
Re:Learning old machine languages???? (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 i
Re:Learning old machine languages???? (Score:1)
3 registers isn't nearly as bad as you think.
Re:Learning old machine languages???? (Score:1)
Re:Learning old machine languages???? (Score:1)
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..
Re:Learning old machine languages???? (Score:1)
Re:Learning old machine languages???? (Score:3, Insightful)
Now I shall demonstrate why Ada is a better choice for this sort of thing.
In this [cc65.org] 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 softwa
Re:Learning old machine languages???? (Score:1)
I would like to remark that in a sense the zero page could be considered as a "large number of multipurpose registers".
Contiki (Score:2, Informative)
Everybody knows it already (Score:1)
"The ability to program the 6502 is innate. It only has three registers. How hard can it be?"
Those were the days -- Like the first NCC-1701 (Score:4, Interesting)
I learned almost everything I know about computers from my Apple
Just like Picard and the Stargazer, I often wish I were programming on my old
How did it evolve ? (Score:2)
How did the 6502 evolve ? Does it still have some descendants that can use the same machine code ?
Re:How did it evolve ? (Score:1, Informative)
http://www.westerndesigncenter.com/ch816S.html
Re:How did it evolve ? (Score:1)
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?
6809-68k, not 6502-68k (Score:2)
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 [wikipedia.org] end
Re:6809-68k, not 6502-68k (Score:1)
Re:How did it evolve ? (Score:1)
-uso.
Re:Two questions? (Score:3, Informative)
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
Where I learnt 6502 machine language (Score:2)
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 w
Re:Where I learnt 6502 machine language (Score:2)
Or did your model come with Intege BASIC?
aaa!!! (Score:1)
Re:aaa!!! (Score:2)
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
Re:Where I learnt 6502 machine language (Score:2)
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.
The ultimate home 6502 machine (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! [nvg.ntnu.no] site. For my money, you couldn;t get a better star
6502 vs Z80 (Score:2)
This brings back so many memories of 6502 vs. Z80 arguments as vicious as any Linux vs. Windows debate, or Betamax vs. VHS, or
Re:6502 vs Z80 (Score:1)
Re:6502 vs Z80 (Score:1)
Re:6502 vs Z80 (Score:1)
Re:6502 vs Z80 (Score:1)
Oh sure, now you tell me... (Score:3, Funny)
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.
Re:Oh sure, now you tell me... (Score:1)
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.
Re:Oh sure, now you tell me... (Score:2)
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 th
Re:Oh sure, now you tell me... (Score:2)
I just wish I had run into this book in 1984...
6502 as a RISK / C64 comments (Score:3, Insightful)
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 __,
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).
Re:6502 as a RISK / C64 comments (Score:2)
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.
Re:6502 as a RISK / C64 comments (Score:2)
Re:6502 as a RISK / C64 comments (Score:2)
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.
Re:6502 as a RISK / C64 comments (Score:2)
Undocumented Instructions still undocumented? (Score:3, Interesting)
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
Re:Undocumented Instructions still undocumented? (Score:1)
Back in the day (Score:2, Insightful)
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!).
Memories! (Score:1)
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:
(BTW, I think the
C64 owns. (Score:1)