Questions tagged [stack-machine]

Stack machine is intended for questions related to using a stack data structure for the storage of both temporary values during calculations as well as stack frames during transfer of control to subroutines.

References

27 questions
1
vote
0 answers

MIPS to stack machine code

There is a code block like MIPS, I want to convert this code to stack machine code. I've hesitated about its correctness. I m not sure about how to move value from "a" to "r1". Is it true? Thank you. lw r1,a lw r2,b add r3,r1,r2 sw r3,c Stack…
kacikalin
  • 11
  • 2
1
vote
1 answer

How to handle scope when generating bytecode with a handwritten compiler

I have written a small compiler for a simple stack machine. It can assemble and handle scope/functions through a number of virtual machine hacks only. That is I have it define scope and in scope variable definitions in the bytecode itself. Can I get…
Chase
  • 1,419
  • 12
  • 17
1
vote
1 answer

How to devise instruction set of a stack based machine?

Stack based virtual machines like CLR and JVM has different set of instructions. Is there any theory behind devising the instruction set while creating a virtual machine? e.g. there are JVM instruction sets to load constants from 0-5 onto the…
Anindya Chatterjee
  • 5,824
  • 13
  • 58
  • 82
0
votes
2 answers

Why does the JVM have a separate array of local variables?

This question is sort of the opposite of this existing one: What is the role of operand stack in JVM? That question asks why the JVM does not operate directly on the local variables. I'm wondering, since we have the stack anyway, why not operate…
kqr
  • 14,791
  • 3
  • 41
  • 72
0
votes
0 answers

How do Stack Machines and 3AC Machines solve expressions?

So, I'm struggling a little on how Stack Machines & 3AC (Register) Machines interpret expressions. Take this expression for an example: 4 * 2 - 3 As a 3AC Machine (instruction sets feature three-operands, a type of Register Register Machine), I…
0
votes
1 answer

Are these the smallest possible x86 macros for these stack operations?

I'm making a stack based language as a fun personal project. So, I have some signed/unsigned 32-bit values on the stack and my goal is to write some assembly macros that operate on this stack. Ideally these will be small since they'll be used a lot.…
Hrothgar
  • 127
  • 5
0
votes
1 answer

Approximation of PI with Brouncker's formula using a Stack machine

I'm working on how to translate this formula to obtain an approximation of PI (based on Brouncker's) to a stack machine. The formula I'm working with is 4/(1 + 1^2/(2 + 3^2/(2 + 5^2/(2 + 7^2/(2 + 9^2/2))))) which is roughly 2.97. How can I translate…
user13472845
0
votes
1 answer

How does my instruction know what the address on the operand stack points to?

I'm writing a bytecode compiler and a VM. I'm able to use constants by placing any non-integer values in a constant pool and pushing the 4-byte integer address on to the stack. That part is fine. But now I'm adding global variables which get stored…
JackP
  • 119
  • 3
0
votes
1 answer

Add nested-function support in a language the based on a stack-machine

Suppose I have a simple C-like programming language: int foo() { int x = 10; int bar(y int) { return y * 2 } return bar() + x } Like you can see, it supports nested functions. I already implemented the lexing-parsing…
mux
  • 455
  • 5
  • 10
0
votes
0 answers

Assembly Stack machine: Exercise with Push/Pop

Assume address 100 holds the value 7 and address 200 holds the value 3, explain the instruction cycle for the arithmetic instruction sub using Von Neumann Machine definition. push[100] push[200] sub pop[500] I know the answer is push[100]…
0
votes
2 answers

Does the processor use more than one stack to separate the call stack from the expression/register stack?

I was reading some basic articles about memory manipulation by the processor, and I was confused as to how the processor handles what comes next. The concept of the call stack is clear, but I was wondering if the expression stack/register stack…
0
votes
2 answers

Virtual machine design with separate stack and heap

I'm trying to learn a bit more about virtual machines and programming languages in general by implementing some of the stuff that is found in books. The book I'm currently going through keeps the stack and the heap in one memory area. The stack…
David K.
  • 6,153
  • 10
  • 47
  • 78
1
2