r/TuringComplete • u/DruidBtd • 24d ago
Help needed; how to solve the stack level for Symphony?
I've been stuck on the level where you need to make a stack that can push and pull for a while now. I tried a few things myself, nothing. Asked ChatGPT, nothing. Looked up a full guide, found a really good one, didn't work. Is it bugged, or does anyone have a working solution?
1
Upvotes
3
u/Medium-Sized-Jaque 24d ago
Your sp register stands for stack pointer and it starts at 0. So if you subtract 1 it will overflow to the last memory position, so your stack is the end of the memory module and you know your instructions won't be overwritten by it. Then you store the value. Every time you push you just subtract again and store again. To pop you just reverse it. Load the value then add 1 so the stack pointer is now pointing to the next value to be popped.
1
u/Medium-Sized-Jaque 18d ago
Were you ever able to figure it out?
1
u/TarzyMmos 23d ago
If u want more in depth help I'd recommend asking on the discord! They respond pretty quickly and are very helpful imo!
1
u/Fastpast93 5d ago edited 5d ago
It's very easy once you understand what the purpose of the stack is. I don't know how much you know so I'll start from plain ol' Symphony.
Every pushed/popped value is 32 bits, which is 4 bytes (32 bits / 1 byte = 4). This means you must change the address by 4 to change it by 4 bytes.
The easiest way to do so is to subtract 4 from the stack pointer and store a value there. That places your pushed value at address -4. Want to push again? Subtract 4 again and store the new value. That looks like this:
sub sp, sp, 4
store_32 [sp], register
Since the sp starts at 0, that is selecting the first 4 bytes of your program. You can't store it there, so subtracting 4 moves the pointer down and allows you to store in an empty region (unless you are using an absurd amount of memory already, which you aren't at this stage)
So figure what this does:
sub sp, sp, 4
mov r1, 5
store_32 [sp], r1
sub sp, sp, 4
mov r1, 6
store_32 [sp], r1
If you couldn't tell, this does the following twice:
- Move sp down
- Set r1 to 5
- Store r1 to memory at address of stack pointer
From this, you can almost certainly guess how pop is implemented. If not, here is an example:
load_32 r1, [sp]
add sp, sp, 4
load_32 r1, [sp]
add sp, sp, 4
And this does the following:
- Move sp up
- Set r1 to most recent pushed value
- Move sp up
- Set r1 to the value pushed directly before the last
Since you have already dealt with branching, you will be able to figure out how to implement the stack. It's very easy-just two instructions each for pushing and popping. Good luck!
1
u/Pretty-Potential4733 4d ago
add a value (x) if input is 0 then
output memory [x] and -1 to x
else
store input [x] and +1 to x
(consider x as a register)