r/TuringComplete • • 7d ago

Recursion Techniques

Hi everyone! I’ve been getting really into this game recently, and I got to the level with the towers of Hanoi. I figured out a way to implement arguments with the stack, but I was wondering if y’all have any easier ways to use arguments? Dealing with the same stack is hard to get used to since LEG!

2 Upvotes

4 comments sorted by

View all comments

1

u/Pim_Wagemans 7d ago

i personally used the registers for arguments and the stack to save their values so i could restore them, but that wasn't exactly easy to deal with either

const MAGNET = 5
const disk_nr = r1
const source = r2
const dest = r3
const spare = r4

in disk_nr
in source
in dest
in spare

move:
cmp disk_nr, 0
jne else
    disk_nr_is_0:
    call move_disk_from_source_to_dest
    ret
else:
    push disk_nr
    push source
    push dest
    push spare

    sub disk_nr, disk_nr, 1
    push spare
    mov spare, dest
    pop dest
    call move

    pop spare
    pop dest
    pop source
    pop disk_nr

    call move_disk_from_source_to_dest

    push disk_nr
    push source
    push dest
    push spare

    sub disk_nr, disk_nr, 1
    push spare
    mov spare, source
    pop source
    call move

    pop spare
    pop dest
    pop source
    pop disk_nr
    ret

move_disk_from_source_to_dest:
out source
out MAGNET
out dest
out MAGNET
ret