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.
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…
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…
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…
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…
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…
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.…
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…
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…
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…
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]…
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…
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…