0

Let’s say I want to do baremetal programming on an ARM cpu, using a stack machine approach with Forth. Could I use the registers of the cpu as the top of the stack, disregarding their actual conventional use in a register machine?

I want to mimick what a dual stack machine does, using hardware addresses as the stack. The hardware I am looking at to do this is probably a Raspberry pi zero or something similar with better documentation

JupiterC
  • 9
  • 1
  • 1
    To me, this question seems better suited to another SE site... Perhaps https://cs.stackexchange.com/ – spender Jul 04 '20 at 11:38
  • 3
    Yes, you can do that of course. – Jester Jul 04 '20 at 11:58
  • 6
    Yes, you can do that. It's fairly common to keep the first few stack elements in registers. You might want to look at Mecrisp Stellaris for an open source Forth implementation for ARM that does precisely this (it also does full-fledged register allocation if desired). – fuz Jul 04 '20 at 12:11
  • 2
    @spender Not really. [cs.SE] is more for theoretical computer-science questions. – fuz Jul 04 '20 at 12:18
  • 1
    You mean keep a *pointer* in a register? Or keep the actual datum in a register instead of pushing it, then probably popping it for the very next operation? Yes you can do that, too, e.g. [Are these the smallest possible x86 macros for these stack operations?](https://stackoverflow.com/q/62542955) is about doing naive code-gen with fixed blocks, except it can optimize away a push/pop across a pair of blocks. – Peter Cordes Jul 05 '20 at 02:41
  • 1
    baremetal does not mean assembly language you can use C or any other if you wish. And since you can implement this in a high level language using variables then naturally you can use gpr's. – old_timer Jul 05 '20 at 02:50
  • 1
    A high-end compiler would definitely do such kind of optimization. However, if you "just" want to write a compiler, I would definitely keep the stack in memory. This is MUCH easier – Martin Rosenau Jul 06 '20 at 06:47

0 Answers0