very good way to pass parameters to
subroutines? Or that the 65816 has advanced instructions that permit
direct access to the Stack? Or even that Commodore users can very easily create and use local variables with stack frames just like programmers do
on the PC? Here's one for you: I have written programs which did not use
a single byte of regular RAM for data! Well, I would like to show you how
this is done. I would also like to show how to call a subroutine and then later return to a different, custom address, and how to return from a subroutine that was never called. And as an added bonus I'm going to tell
you an undocumented secret about the 6502 that very few people know about. Here's a hint: internally the 6502 processes BRK, IRQ, NMI, and RESET in exactly the same way! I'm going to show you how the 6502 does this - it's information you won't find in any book. We will get to all of this and
more next time out with Part Two of this primer about the Stack. So, until
our next meeting, take 'er easy, and I'll see you next time right here...
at the intersection where Art meets Science.
TIP OF THE DAY
Experienced programmers smartly divide code sections up into separate files that usually concern themslves with accomplishing one specific task.
Programs written in assembly language can easily run into thousands of
lines of code. A side-effect of all the gained speed and efficiency is
that each instruction by itself does very little in the grand scheme of
things. Lengthy programs limited to one large file suffer from being hard
to read, maintain, and understand. Ever hear the phrase spaghetti code?
It is probably the worst criticism in all of programming and usually refers
to excessive jumps and branches, meandering code paths, incoherence, and of course sloppy programming in general. It is a sign of inexperience, to say
the least. Programmers who produce spaghetti code very seldom work well in
a team setting, and hardly ever produce optimum code. The tip today is to
not fall into the single-file source code trap. It leads directly to
spaghetti code. You don't want your friends (or non-friends) leveling this criticism on your code; it is very embarrassing to hear. A corollary to
this tip is to split up your code and data sections. It's not mandatory
like on the PC, but it is definitely advisable. If you do this you will
always know where to find everything and what it all means, even after you forget. And you will forget.
CORRECTION:
Last month (Assembly Line $02) I made an error that was pointed out to me
by my eagle-eyed friend, Arthur Jordison, the author of the excellent IDE
named CBM Prg Studio. The last table (right before the Conclusion) was originally written as ...(0*26)... and should read:
(0*2^15)+(0*2^14)+(0*2^13)+(0*2^12)+(
1*2^11)+(1*2^10)+(1*2^9)+(1*2^8)+(1*2
^7)+(1*2^6)+(0*2^5)+(1*2^4)+(1*2^3)+(
1*2^2)+(1*2^1)+(0*2^0)
I apologize for the error, and thanks -- that was some good catch, Art. I
am truly amazed. Now, don't you have a program to write?
Please send errors, omissions, or suggestions to
bert@winc64.com or on
Lemon64, username satpro, or at www.melon64.com, username satpro.
--- MBSE BBS v1.0.01 (GNU/Linux-i386)
* Origin: Dragon's Lair ---:- bbs.vk3heg.net -:--- (39:901/280)