RE: [stella] Final exam for Square One

Subject: RE: [stella] Final exam for Square One
From: "Andrew Davie" <adavie@xxxxxxxxxxxxxxxxx>
Date: Tue, 19 Jan 1999 00:37:59 +1100
I expected more answers than the one from Dan!

Here's my stab at marking...

> The machine operates like this, right?  The program counter starts off
> at the first location in memory after the program is loaded into it.

As Dan pointed out - the RESET VECTOR tells the machine where to start
running a program.  The reset vector is the two bytes at the top of ROM at
location $FFFC/$FFFD.  It MUST point to the start of the program.  The first
thing a program must do is initialise a few things to make sure everything
is stable.  Things like the stack pointer!

> It views the first thing there and adjusts the Program Counter
> depending on what it finds there--a JMP command makes it go up by
> three (the command is one byte in memory location, the location is
> two), a BRK makes it go up by one.

You rarely NEED to know the size of instructions;  the assembler does all
this automatically.  A JMP to a label (a location) effectively loads the
address of that label into the program counter, and execution continues from
the address the label specifies.  Don't focus on the number of bytes per
instruction, or what happens to the program counter before/after bytecode
fetching.  Concentrate on what the instructions DO.  A JMP, for example,
changes the value of the program counter - from where the next instruction
is fetched.  It's a GOTO :)  And a JSR is a GOSUB :)  Whatever the
instruction, after it's done, the program counter will point to the next
instruction to be executed.

> command and puts it in the Program Counter.  If it is a JSR, it takes
> the number in the Program Counter, copies it to the Stack Pointer, and
> places the bytes after the JSR command into the program counter.

Pedantic mode on.  Copies it to WHERE THE STACK POINTER POINTS TO.  Not to
the stack pointer itself :)  Pedantic mode off.

> the RTS.  At RTS, it takes the top number from the Stack Pointer and
> copies it to the Program Counter.  The unit then moves everything in
> the Stack Pointer up one (in the event of nested subroutines) and
> continues on.

Again, takes the top number from the stack (where the stack pointer points).

What do you mean "moves everything in the stack pointer up one"?  The stack
pointer is a single byte value, having range 0 to FF hex.  It is only the
value of the pointer which is changed - the contents of the stack remain
unchanged when a RTS operation is performed.  So, although the return
address is retrieved from the stack area (using the stack pointer as an
index), the stack contents aren't actually changed - just the pointer to the
"top" of the stack.

Hope its clearer.
adavie@xxxxxxxxxxxxxxxxx <mailto:adavie@xxxxxxxxxxxxxxxxx>
visit the Museum of Soviet Calculators at

Archives (includes files) at
Unsub & more at

Current Thread