SuperCPU rayed - Episode 6

 In the previous part of the course we have besides a few interesting new commands
 some new addressing modes met.  But here's the very same
 thick: We focus our attention on the stack relative addressing!  What
 should be and how to use them, you will learn now ...

 Short and brought almost to the point: The stack-relative and
 Stack relative indirect indexed (what a word) treat the stack
 as a field that is indicated.  As in Basic in a signal generated with DIM
 Field is now treated the stack!  The stack pointer will be as
 Taken starting address of the array.  The always points to the next-FREE
 Address on the stack, which is an index of zero would be pointless.  Data and
 Addresses that have been pushed onto the stack, thus can be from index 1
 appeal.  How do you want everything comes right - at the moment it is enough
 first, if you like it you imagine a field in Basic.  The stack-relative
 Addressing allows now to any byte is pushed onto the stack
 was to access.  But the hammer is the stack relative indirect
 Addressing: This is possible to access an address on the stack
 is!  In plain English: You slide with PHA for example, an address (16 bits)
 on the stack, and the contents of this address you can then about the
 Stack relative indirect addressing access - in other words, how to
 an address which is a pointer to the zero (direct) Page.  Both new
 Addressing modes allow parameters cleanly and efficiently over the
 Stack, to pass.  The developers of 65816 certainly thought also thinking of
 C compiler - the language used like many others the stack to
 Parameter transfer to subroutines.  But more importantly: this
 Addressing is possible to write code that runs everywhere in the memory and
 has access to data located anywhere in memory.


 Relativity

 These new addressing modes belong certainly to the
 most interesting of 65816, on the other hand you have to use their
 just superior to so that it is effective.  In any case you can by
 this type of addressing is now on any data onto the stack
 were pushed to access - and not, as usual, only on the
 last value stored there! 

 Let's go first to the stack-relative addressing (without
 indirectly-indexed) a.  It is so stacked in each of the last $ FF
 Bytes (it can at 65816 yes more than 255 bytes on the stack land, because
 the stack pointer 16-bit, as we have seen in a previous part of the course
 have).  Commands, the stack-relative addressing are two bytes long.  After
 the opcode is one byte, and is the index into the stack.  As I said
 the stack pointer is used as the basis for this "box".  The index is
 dazugezaehlt to the stack pointer, and the CPU already has the address within
 out of the stack is accessed.
 
 This can be especially useful when a part of a program data
 want to send it to another part.  Of course you can this data somewhere
 store, and the other routine she has to pick up from there.  The method
 over the stack but is somewhat flexible.  Suppose a
 Multiplication routine expects two 16 bit values.  Any part of the
 Main program pushes it on the stack.  Later then fetches the
 Multiplication routine a value from the stack, but it is possible the other
 Value as well as the stack pointer completely untouched:

 LDA 3, S;  Get first operand

 or

 LDA 1, S;  Get second operand

 As you can see clearly, is on the last hyped value with the
 Index 1 to access, not about 0 The stack pointer points even as mentioned,
 always on the next free byte on the stack whose address exactly one
 is less than the most recently pushed onto the stack bytes.  An index of 0 would be
 So therefore pointless unless you want to access the last byte
 has already been brought to a pull-command!  However, this would be not just
 particularly stable, since between an interrupt may have occurred,
 who long ago wrote about the byte with its own values.

 Indirect access

 While the stack-relative addressing is there to directly access data on
 the stack access, you can take the stack relative indirect-indexed
 Addressing to access data that reside in ADDRESSES, which on
 the stack are!  (Please read that sentence again and digest thoroughly!)
 Let's take our example of just and amend it from something like this: Now we accept
 that not the numbers to be multiplied, but their addresses (ie
 where they were available) in memory on the stack pushed!  As the following routine
 shows both values ??can about the present on the stack address
 be loaded indirectly:

 LDY # 0
 LDA (1 S) Y;  first 16-bit fetch Multiplikationsoperand 
 TAX;  and remember in X
 LDY # 2
 LDA (1 S) Y;  second 16-bit fetch Multiplikationsoperand

 The 1, S gives the address of the last hyped value, ie the
 Pointer to the second multiplication value.  (More even: 1, S indicates
 the low byte of the address, the high byte is located at 2, S, ie on the
 next higher stack address.) is now attached to this indirect address the
 Y-register is added, the indirect address + 0 contains the first, the
 indirect address + 2 contains the second value.  And with the contents of this
 indirectly-indexed address the battery is charged.  Well, it is - and
 hears like getting more complicated than it is.

 Known relative

 To clear the fog any thing: This type of addressing is
 As already briefly mentioned, related to the indirect familiar to us all
 Addressing over the Zero Page.  There is for example an address in $ FE / $ FF, on
 which you can then still using Y to access.  Nothing else going on here, just
 that the location of the pointer is not always in the same place (fixed address
 is in the zero page), but rather on the stack, seen as a field
 is that starting at the address of the stack pointer.  In both
 Addressing modes, an index is added to a pointer, and this must
 are both in the Y-register.

 That's not all

 In order to be able to also use these new addressing modes well implemented
 The developer of the processor in the SuperCPU some commands to specifically
 Push address on the stack.  These are the commands PEA, PEI and
 PER, which we, in the course section in which it came to various stack commands
 have already touched - perhaps a few have asked what
 these commands at all should.  Now it's time to shed light on the matter
 bring.  Incidentally, the only commands that data directly from one
 bring to a different memory location can, without any
 Register to use!

 The PEA is the easiest of the three new push commands.  The operand is
 a 16-bit value, which is an address, or a data value
 can act.  This is the command no matter he brings these 16 bits to each
 Case on the stack.  An example:

 PEA $ 2,134;  $ 2,134 pushes onto the stack

 This command transfers $ 2,134 on the stack, it may be the address
 Act $ 2134, but it may also be the value of $ 2134, it is the encoder
 about blank how he interpreted it.  If you want to work with values, but
 Note that there is no "#" character, as usual with constants used
 is!  The value that is put on the stack, by the way is always 16 bit,
 regardless of whether the M or X flag is now just 8 or 16 bits.

 Interestingly it is the PEI - which stands for Push effective indirect
 address.  The operand is an address in the Direct (Zero) Page.  The 16
 Bit value, which is at this address, will land on the stack.  Thus one can
 either push a pointer to the stack, or a 16-bit value in the
 Zero Page is.  Do we, for example, the value or the address $ 5678
 stored from $ FE / $ FF, then one would

 PEI ($ FE);  pushes two bytes are the from $ FE in the Direct Page

 Get the $ 5,678 from the Zero Page and put on the stack.  Just like PEA
 will also push PEI always a 16-bit value, regardless of whether the battery or
 Index registers are placed just 8 or 16 bits.

 Even more relative

 The PER command (push effective relative) pushes one to the Program Counter
 relative address on the stack.  This is incredibly useful when writing
 relokatierbarem code.  The operand, the one that tells the assembler is,
 any point in the program, for example, a data area.  The operand,
 the assembler generates is a 16-bit relative value: the difference
 between the address of the next instruction and the address as an operand
 is specified.  Is now carried out in the order, this value is added to the
 Address of the next instruction is added - this is done at runtime!
 This results in any case, the address at which the data are,
 no matter where the program is loading or where it is straight.  And
 exactly this address is pushed onto the stack, where you then take the
 Can access stack relative indirect-indexed addressing it.
 If the address before the PER command, the assembler generates a very
 large 16-bit number that when added to the Program Counter an overflow
 leads over $ FFFF and thus automatically return to the correct address
 executed.  The PER command works similarly to the BRL (Branch long), address,
 one of charge, which is also an address of somewhere in the program, the
 Assembler here forms a 16-bit value corresponding to the distance from this
 Address corresponds, and when the command is executed, the value is
 added to the program counter, which results in the address where the
 Program it continue.

 To understand how to calculate the PER command together with relative jumps,
 used, let's look a little routine (Listing 6.1) , which at ANY
 can run arbitrary address.  Suppose we assemble them into $ C000.
 Somewhere in there is then the address of the value DATA0.  The program aims to
 now have access to this value.  Sure, a simple LDA DATA0 would
 work - but only if the program really at $ C000
 lies.  However, if the routine is to be relokatierbar, you have it
 For example, even after $ 8000 can load.  Thus, the LDA would DATA0 a
 Get completely wrong information in the battery.  Instead, we now use
 a PER DATA 0.  The assembly calculates the distance between the command and
 the address of DATA0 from.  If the program is executed later, counts the
 65816 when it hits the PER command, the distance back to - and comes
 Thus, to the address of DATA 0, no matter where the program is loaded!
 This address is put on the stack.  Now you can with the stack-relative
 indirectly-indexed addressing to the value in DATA0 access.  And from that
 from it's off even further: If the address of DATA0 namely first on
 the stack is then carried hochzaehlen the Y register on DATA1
 DATA2 and DATA 3 you!  In Listing 6-2 you can see another example of how
 can be written with PER relocateable code, even here, only the
 Stack-relative addressing used.  Both routines can after
 Assemble everywhere in the memory run-a lot of fun even when
 Experiment!


(w) Malte Mundt
©1999 Go64 Redax! & Count Zero/SCS*TRC for all HTML Stuff

[ Zum 5. Teil ][ Zum Index ][ Zum 7. Teil ]