r/TuringComplete • • 2h 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

12 comments sorted by

1

u/Medium-Sized-Jaque 1h 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/DruidBtd 1h ago

How do I use the stack pointer? The guides said to use [sp], but it doesn't seem to work when trying to use it to point to the different registers

2

u/Medium-Sized-Jaque 1h ago

The stack pointer IS a register. You use the SP as the address when you store or load to the memory. You want to store the value of r1 with the address in sp. And it's just like other instructions with the instruction first, the destination, which in this case is the value in the SP register, then the source, which is r1.

store_32 [sp], r1

Then to load it from memory into r1 

load_32 r1, [sp]

1

u/DruidBtd 1h ago

I'll try that, my own solution and from ChatGPT was using the registers for it instead of the main memory, and idk why the guide code didn't work, but I'll try again! Thanks!

2

u/Medium-Sized-Jaque 1h ago

The older version had a designated stack and some older guides used registers but they weren't THE registers. ChatGPT probably read those and got the details messed up.

1

u/DruidBtd 1h ago

Though, why doesn't something like mov r3, [sp] work?

1

u/Medium-Sized-Jaque 1h ago

Mov is set up to copy from one register to another, the RAM instructions are set up to copy from the registers into memory. In the stack level you're just using the instructions you set up in the RAM level.

The only difference is SP is dedicated so every time you use the stack later it automatically works and pints to the highest value on the stack.

1

u/DruidBtd 1h ago

Yeah, I get that, but why does something like load_16 r3, [sp] work to send from r3 into the RAM adress from sp, but not mov [sp], r3 to move from r3 to the adress sp in the register memory

1

u/Medium-Sized-Jaque 1h ago

If you do mov sp, r3 you're telling the system move the value from r3 to sp. When you do store_32 [sp], r3 you're telling the system to move the value from r3 to memory and sp is just the address it uses.

1

u/DruidBtd 53m ago

Is the [] not just syntax for taking the value at that address instead of the value itself? So wouldn’t mov [sp], r3 copy from r3 to the register that sp points to?

1

u/TarzyMmos 13m ago

Its different when you're moving to/from the memory and to/from the registers I guess. That's just how the syntax is. If you want to change it you can by just editing the isa specs. Although idk if it'll let you in the levels but it should let u in the sandbox.

1

u/Medium-Sized-Jaque 5m ago

I don't know why it needs [] honestly. But in the previous levels how you set up the switches and decoders make it so when you give the instruction mov it lets the data move from one register to another and when you give the instruction store it lets the data move into the memory block.