![]() |
| | #1 |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Processor with no stack? How to calculate the Stack Size? In it, my code was slated because it assumes that there is a stack. Of course, C being a function-based language, there needs to be SOME FORM OF stack, even if the stack is managed by software (such as the Deep Blue C for 6502 - since 6502 doesn't have a processor stack that is worth anything, it's 256 bytes long - hardly enough for passing arguments and calling functions in any reasonable C program). . But can someone tell me if there is any machines in current production use (not counting machines kept alive in a museum somewhere) that doesn't have a conventional stack - besides pointing out that some machines have TWO stacks [e.g. 29K that has a "register" stack and a "memory" stack]. I'm just curious as to what machines (today) would not have a stack in a meaningful way. -- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. |
| matsp is offline | |
| | #2 |
| (?<!re)tired Join Date: May 2006 Location: Portugal
Posts: 5,614
| If you allow for a single call-return stack as being generally considered "stack absent", then you have a multitude of processors that can be considered not having a stack. Albeit their use is probably limited to only specialized tasks (coffee machine processors )But looking at the original thread I cannot conceive in any way as meaningful for the solution presented the fact some processors may not offer a stack or offer only a single call-return stack. Micro-controllers, my $1 calculator, all have a stack and stack pointer. ... BTW, for fun... they even have or plan to have OSes for these processors http://www.patentstorm.us/patents/6823517.html
__________________ Originally Posted by brewbuck: Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster. |
| Mario F. is offline | |
| | #3 |
| Malum in se Join Date: Apr 2007
Posts: 3,188
| No, the common microcontrollers all use stack based processors. There really arent any completely stackless μP or μC that I can think of. Stacks are such a basic advance it would be itentionally crippling the processor to not use one. There would be no performance gain, unless you count having one fewer registers, or being able to use the SP for something else.
__________________ Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off. |
| abachler is offline | |
| | #4 |
| Super Moderator Join Date: Aug 2001
Posts: 7,811
| I cannot imagine a CPU not having a stack. I'm fairly sure I cannot come up with any that I even know of off-hand.
__________________ If you aim at everything you will hit something but you won't know what it is. |
| Bubba is offline | |
| | #5 | |
| Just Lurking Join Date: Oct 2002
Posts: 5,005
| I had seemed to recall an HC05 I worked with as a 'stackless' device. But the data sheet shows it too had one. Quote:
Trivia: this device also had a meaningful address 0.
__________________ 7. It is easier to write an incorrect program than understand a correct one. 40. There are two ways to write error-free programs; only the third one works.* | |
| Dave_Sinkula is offline | |
| | #6 |
| Registered User Join Date: Apr 2008
Posts: 19
| Most (if not all) of the Microchip PIC uControllers lack a stack that the programmer can use. There is a stack but it just stores return vectors for subroutines and interrupts. There is nothing there to use for automatic variables and the like. |
| birkelbach is offline | |
| | #7 | |
| Kernel hacker Join Date: Jul 2007 Location: Farncombe, Surrey, England
Posts: 15,686
| Quote:
-- Mats
__________________ Compilers can produce warnings - make the compiler programmers happy: Use them! Please don't PM me for help - and no, I don't do help over instant messengers. | |
| matsp is offline | |
| | #8 |
| Registered User Join Date: Apr 2008
Posts: 19
| There are some C compilers, but I've done all my PIC programming in MPASM (Assembly Language) so I don't really know. I suspect that the compiler allocates a spot in memory to use as a stack pointer and then uses indirection for all the arguments and automatic memory. Unless there is only one argument, then it'd just use the single working register. Most of my subroutines just use the working register. I guess you could use the W (working register) as a pointer to arguments, and then use some predefined memory for automatic variables. Then you can only call subroutines one deep, or allocate some memory for each subroutine. You'll run out of memory real quick like this because RAM is measured in bytes on these machines. A big one has 2k bytes. The hardware stack is typically only 8 words deep, so you can't nest subroutines very far anyway. Don't forget to save one for the interrupt routine too. (Don't ask me how I know that) Recursions will get you in big trouble real quick. :-) |
| birkelbach is offline | |
| | #9 |
| Guest Join Date: Aug 2001
Posts: 5,018
| it seems that it would be easy enough to set up a stack. just reserve a register as the stack pointer, set it to the desired memory location and replace push with: dec SP mov DATA -> (SP) and pop with: mov (SP) -> DATA inc SP |
| Sebastiani is offline | |
| | #10 |
| Registered User Join Date: Apr 2008
Posts: 19
| Yeah that's the basic idea. It takes several more instructions on the PIC. i.e. there are no indirect moves, rather a pair of registers to use for indirection, also there are bank select bits that have to be handled carefully to access the right registers. But I'm pretty sure that is the way the compilers handle it unless it's a really simple function. |
| birkelbach is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| stack and pointer problem | ramaadhitia | C Programming | 2 | 09-11-2006 11:41 PM |
| infix evaluation using stack | lewissi | C++ Programming | 0 | 11-03-2005 02:56 AM |
| Question about a stack using array of pointers | Ricochet | C++ Programming | 6 | 11-17-2003 10:12 PM |
| error trying to compile stack program | KristTlove | C++ Programming | 2 | 11-03-2003 06:27 PM |
| Stack Program Here | Troll_King | C Programming | 7 | 10-15-2001 05:36 PM |