• Commodore Free Magazine, Issue 80 - Part 14

    From Stephen Walsh@39:901/280 to All on Sat May 17 18:24:11 2014
    2 and MPS 803 printers, with modifications to
    each subroutine to work with each prescribed printer. I figured this
    program should work with all Commodore related printers, provided the user
    knew which line number it was where modifications needed to be made. I
    asked her which Commodore printer she was using, and she responded that she
    was not using a Commodore printer, but a specialized electric typewriter
    that was modified to take Commodore commands.

    Aha!

    Without knowing exactly what those command channels were, my program would
    not be able to function properly under those conditions. In order for the program to print on the proper lines of the inserted check, the Commodore
    had to execute an OPEN 10,4,10 command, which basically told the printer to re-boot and start over from where it left off. Without this command, the printer would print all the information below the line on the check - not a pretty sight. I quickly related this information to the front desk person,
    who decided to change my article which read, "works with all Commodore and related printers" to "will work with virtually all Commodore and related printers." A smart move on the part of RUN and they helped me save face at
    the same time.

    What the ...?

    How did I get here in this cul-de-sac? Apparently, I don't want to write
    about making Check It Out and Check Mate work with each other's data. I'm
    so busy writing nostalgia that I forget what it was that this old man is supposed to be doing. Now this article is almost written and there's very little room left for me to get into the details of all the trials and
    hassles I had to go through to even get each program to work. Needless to
    say, when I finally did get each program's data to cooperate with each
    other, problems remained. Also, let me mention to those who may still be
    using Check It Out in its original published form, they will not be able to
    use the data formed by Check Mate unless serious modifications are made to Check It Out. Hence the reason I was looking for the owner of the program
    in the first place - so I can get permission to release the updated version
    of Check It Out to the public without causing a copyright infringement
    upset with anyone involved.

    Perhaps, with the editor's indulgence, I can compose a second article pertaining to the combat and hardships related to making two seemingly unrelated and uncooperative programs begin to get along. It sounds like a Mideast peace talk conference, and believe me, for the most part, it was.
    In between articles, I will boot up both Check It Out and Check Mate and
    see if they are still getting along, or if more negotiations will be
    necessary.

    In the meantime, the "manhunt" for the new owners of Check It Out will continue...



    *************************************
    THE ASSEMBLY LINE
    $03: The Stack - Part One
    By Bert Novilla (satpro)
    *************************************

    "The Place Where Art Meets Science"

    Hello again! Last time out we refreshed ourselves with a treatment of
    binary numbers. Today we will discuss a very important component in
    assembly language programming - the Stack. Just from talking to other programmers through the years (even guys who know what they are doing!) I
    have come to the opinion that the Stack may be the single most confusing
    topic in all of assembly language programming. It is without doubt the
    barrier to entry for many people who explore assembly language. Why is
    this? Well, I have some ideas, so today we address the facts (and myths) concerning this small 256-byte piece of memory located in your Commodore computer just after Zero Page. Today we will look at the 6502's
    implementation of the Stack, and next time (in Part Two) we will expand on today and tackle how the 65816 implements the Stack. I will show you how
    to use the Stack effectively (regardless of CPU) in the programs you write. Plus, we're going to get funky and explain some advanced Stack manipulation techniques. If the Stack is confusing or you want to know more about how
    it works, then please, read on.

    WHAT IS A STACK?

    Many times you need quick, temporary storage for data and the A, X, and Y registers are all busy doing something. Or perhaps you want to pass
    several parameters to a function somewhere. For times like these there is
    a mechanism called the Stack. So what is the Stack, where is it - and what does it do?

    Well, the Stack is located in an area of RAM immediately following Zero
    Page in all 6502-based computers. Zero Page, of course, is a 256-byte
    range of memory, the very first 256 bytes of your computer's address space,
    or $0000-$00FF. For the 6502 this range of memory holds a special
    distinction. Many instructions include a special Zero Page addressing mode which executes faster and produces less code. Is the memory itself faster?
    No. The increased efficiency is due to all addresses in this region of
    memory having an implied high byte of $00, which means the computer can
    assume the $00 high byte and do things here using one less byte and one
    less cycle, and at roughly one million CPU cycles per second, the
    possibility exists for much more efficient execution because saved (or
    wasted) cycles can really add up. The Zero Page addressing modes assume a
    high byte of $00; these addresses are viewed by the 6502 as residing in the range $00-$FF. It is a very heavily used section of memory, and all
    Commodore operating systems make extensive use of Zero Page memory.

    Immediately following Zero Page in memory is the Stack at $0100-$01FF. The Stack is somewhat similar to Zero Page in that the 6502 assumes an implied
    high byte (of $01), so memory within this 256-byte range can be accessed
    rather quickly and efficiently, but in a different way - as an offset from $0100. Before we go further, it should be stressed that both Zero Page and
    the Stack can be utilized using standard 6502 instructions in the same way
    as any other part of memory, but we don't generally try to program for less efficiency, do we? We usually want one of the special instructions
    designed specifically for the Stack.

    STACK LAYOUT AND THE STACK POINTER

    Stack memory is just like any other memory. Each byte is made up of eight
    bits like any other byte, but we can use special instructions to read from
    or write to the Stack. The Stack is also the place the CPU places your
    return address when you jump to a subroutine with the JSR instruction. The CPU-addressable position within the Stack is automatically maintained by a special register called the Stack Pointer. We call the position in memory
    that the Stack Pointer refers to as the top of the Stack, but it's not
    exactly the top you might envision. It's actually the bottom address-wise,
    and the position is equal to the value of the Stack Pointer as an offset
    from address $0100. To put it simply, the Stack Pointer, or S Register,
    often times abbreviated SP, is an 8-bit register whose sole job is to keep track of the next position within the Stack where data will be written with
    a special type of instruction known as a push. The Stack Pointer works in
    a way that might seem backwards at first, and that's only because it does
    work backwards! Stated more correctly, the Stack grows downward in memory.
    You may remember how the great Commodore pioneer Jim Butterfield described
    the Stack as a stack of plates in the cafeteria (if you have ever had the opportunity to read any of his excellent books or countless magazine
    articles). Butterfield taught us that when we placed a plate on the stack
    it would also be the first plate we pulled from the stack, a system often referred to as LIFO - last in, first out. Well, of course he was correct
    as usual, but...

    HUH?

    For me this never made sense - only because when I picture the stack of
    plates I imagine this pile on which we place and remove plates - from the
    top. The imaginary stack of plates grows upwards, so intuitively we would expect the next push to be to the

    --- MBSE BBS v1.0.01 (GNU/Linux-i386)
    * Origin: Dragon's Lair ---:- bbs.vk3heg.net -:--- (39:901/280)