Difference between revisions of "Hanoi Towers"
Jump to navigation
Jump to search
Line 4: | Line 4: | ||
data Pair = Pair a b; | data Pair = Pair a b; | ||
-- | -- | ||
− | put x = out (extern 0x10a1fafa) x; | + | put x = out (extern 0x10a1fafa) x; --GPIO0 address: 0x10a1fafa |
-- | -- | ||
printlist xs z = xs (z) (\h t -> printpair h (printlist t z)); | printlist xs z = xs (z) (\h t -> printpair h (printlist t z)); |
Latest revision as of 12:34, 3 May 2022
Source
data Bool = False | True ; data List = Cons x y | Nil ; data Pair = Pair a b; -- put x = out (extern 0x10a1fafa) x; --GPIO0 address: 0x10a1fafa -- printlist xs z = xs (z) (\h t -> printpair h (printlist t z)); -- printpair ps z = ps (\f s -> put f (put s z)); -- hanoi n a b c ls = (== 0 n) ls ( (hanoi (- n 1) a c b (Cons (Pair a b) (hanoi (- n 1) c b a ls)))); main = printlist (hanoi 10 1 2 3 Nil) True;
Assembly
False: *combi T0 2 [ 1,2 ] True: *combi T0 2 [ 0,2 ] Cons: *combi T2 3 [ 3,0,1 ] Nil: *combi T0 2 [ 0,2 ] Pair: *combi T2 2 [ 2,0,1 ] main: ROOT combi T0 2 [ 0,2 ] link main#1 *link printlist main#1: combi T0 2 [ 0,2 ] LIT 3 LIT 2 LIT 1 LIT 10 *link hanoi hanoi: link hanoi#1 eqi 0 combi T40 4 [ 0,4,1,2,3,4 ] *combi T42 4 [ 0,1,3,2,3,4 ] hanoi#1: link hanoi#1#1 link hanoi#1#2 link hanoi#1#3 *combi T15 3 [ 0,1,3,2,3 ] hanoi#1#1: link hanoi#1#1#1 combi T2 2 [ 2,0,1 ] link hanoi#1#1#2 *combi T42 4 [ 0,1,4,2,3,4 ] hanoi#1#1#1: addi -1 link hanoi *combi T62 5 [ 0,1,2,5,4,3 ] hanoi#1#1#2: link hanoi#1#1#2#1 *combi T15 3 [ 0,1,3,2,3 ] hanoi#1#1#2#1: *combi T14 5 [ 5,0,1,2,3 ] hanoi#1#2: link hanoi#1#2#1 combi T5 3 [ 0,1,2,3 ] *combi T54 5 [ 0,1,2,3,5,4 ] hanoi#1#2#1: addi -1 link hanoi *combi T1 2 [ 0,1,2 ] hanoi#1#3: combi T44 3 [ 0,2,3,1,2,3 ] *combi T15 3 [ 0,1,3,2,3 ] printpair: link printpair_r *combi T1 2 [ 1,0,2 ] printpair_r: link put *combi T14 3 [ 0,2,0,3,1 ] printlist: link printlist_r *combi T5 2 [ 1,2,0,2 ] printlist_r: link printlist link printpair *combi T14 4 [ 0,3,1,4,2 ] put: EXT 279051002 *OUT