<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 02 Aug 1994 09:30:23 EST
From   : Stephen Quan <quan@...>
Subject: Stack behavior.

Hi, the Advance User's Guide is not clear on this one, but I am
curious about the correct behavioiur of the stack in the BBC.
So far, I have come up with the following concepts :

  /* PHA */
      mem[0x100 + S] = A;
      S = S - 1;

  /* PLA */
      S = S + 1;
      A = mem[0x100 + S];

I am just using C to describe the ideas, (I hope non-C people don't
mind) and I am not worried about the behaviour of the the status
register just yet (this is covered quite well in the Adv Users Guide).

What is confusing me is the correct stack behaviour for JSR and RTS.
It seems to me that if a JSR were to occur, it seems to

      mem[0x100 + S] = PClo;
      S = S - 1;
      mem[0x100 + S] = PChi;
      S = S - 1;

(Actually, please correct this if it is wrong lo first? then hi?)
And it also seems that the value of the PC is 1 less than the
location of the return address, so what I had to do was :

    /* JSR */
       dest = FETCHWORD;
       PC = PC - 1;
       mem[0x100 + S] = PClo;
       S = S - 1;
       mem[0x100 + S] = PChi;
       S = S - 1;
       PC = dest;

    /* RTS */
       S = S + 1
       PChi = mem[0x100 + S];
       S = S + 1
       PClo = mem[0x100 + S];
       PC = PC + 1;

The odd thing to me is for JSR I have to -1 before I throw it on the
stack and for a RTS I have to +1 after I pull it of the stack.  Can
anyone comment on this behaviour????  It is really bugging me!


Just a bit of trivial, what is the value of A in the following :

       LDA #0
       PHA
       PLP
       PHP
       PLA
       RTS      <--- optional if you are writing in BBC basic.

For some who have a BBC, you can try it out and find out!
If not, I will post the answer tomorrow.
-- 
Stephen Quan (quan@...                 ), SysAdmin, Analyst/Programmer.
Centre for Spatial Information Studies, University of Tasmania, Hobart.
GPO BOX 252C, Australia, 7001.  Local Tel: (002) 202898 Fax: (002) 240282
International Callers use +6102 instead of (002).
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>