| ??? 12/23/01 15:02 Read: times |
#18015 - RE: using accumulator as stack ?? |
James,
Most things in the microprocessor world work on the OVERWRITE assumption. But the construct you described is a recognized useful construct and a mechanism is included for that behavior. As Gil suggested, its called the STACK. It is merely a special addressing mechanism inside the micro that manages placing or retreiving bytes in a sequence of register/memory locations. These locations are not special - they can be OVERWRITTEN like any other register or memory address. But the special opcode that access the mechanism does all the organizing work. The OPCODES are PUSH and POP to place and to retreive respectively. The STACK was so useful that the micro uses it for things you are not immediately aware. This can make its use more complicated than a simple register. Generally you need to be well versed in how the micro does all STACK related accesses before using it successfully; there are many ways to get in trouble with it. The major principle is BALANCING THE STACK; i.e. make sure you take out the same amount of information you put in. Losing your place in the STACK generally causes the most program crashes in novice code. The stack itself is called a LIFO construct. This stands for LAST IN FIRST OUT. This means it works like the STACK name implies... like a stack of containers. You put one container on the ground and add a second atop it, then a third atop it, when you retrieve them, the third is the first one you remove, then the second then the first. So the LAST on placed IN the stack is the FIRST one taken OUT of the stack. There are various stack visualization drawings for this. What is going on inside the micro is interesting. It uses a STACK POINTER to work like a traffic cop directing the flow of traffic. Here the SP (stack pointer) points to the internal memory/register address of one byte at a time. When a byte is placed in that byte THROUGH the STACK opcodes, the opcode uses the SP to figure out where to drop the byte (overlaying what may have been there). When the SP is used to place a byte, it is incremented when done to point to the next sequential memory/register location for the next access. Retreiving data works the reverse. Here the SP is decremented before the byte is retreived to point out the last byte stored (before it incremented to the next available byte). As the SP backs up one pointer location, that byte is copied to the destination used by the STACK retreival. That byte in the stack is unchanged because there is no reason to clear or zero it out - wasted effort. Stack uses the same memory space as other registers etc inside the micro. That means you can access the bytes holding stack information through other addressing opcodes if you have need and are careful. Generally this is only done mistakenly or the stack is mistakenly OVERLOADED until the SP starts pointing at and overwriting locations you never intended - this is the common method of a micro crashing due to a stack error (programmer's mistake... the micro circuitry is doing what its told). :) aka j |
| Topic | Author | Date |
| putting things on accumulator | 01/01/70 00:00 | |
| RE: putting things on accumulator | 01/01/70 00:00 | |
| RE: putting things on accumulator | 01/01/70 00:00 | |
| RE: putting things on accumulator | 01/01/70 00:00 | |
| RE: putting things on accumulator | 01/01/70 00:00 | |
| RE: using accumulator as stack ?? | 01/01/70 00:00 | |
| RE: using accumulator as stack ?? | 01/01/70 00:00 | |
| RE:Does it prompt unbalancing the stack. | 01/01/70 00:00 | |
| RE: RE:Does it prompt unbalancing the stack. | 01/01/70 00:00 | |
| RE: RE:Does it prompt unbalancing the stack. | 01/01/70 00:00 | |
RE: putting things on accumulator | 01/01/70 00:00 |



