-
Notifications
You must be signed in to change notification settings - Fork 0
/
1_asm.fc
76 lines (71 loc) · 1.51 KB
/
1_asm.fc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{-
TASK 1 - Find branch of the cell tree
Write the method that will find a branch of the tree by comparing its
hash with the hash received in the first parameter. When the algorithm finds
the subtree (branch) whose hash equals the received hash, the root cell of
this branch should be returned. Return empty cell if the branch is not found.
-}
() recv_internal() {
}
(cont) code(cell tree, int hash) impure asm """
<{
7 SETGLOB // t
<{
DROP
}>CONT
0 PUSHINT
SETGLOBVAR
<{
PLDREF
}>CONT
1 SETGLOB
<{
LDREF
PLDREF
}>CONT
2 SETGLOB
<{
LDREF
LDREF
PLDREF
}>CONT
3 SETGLOB
<{
LDREF
LDREF
LDREF
PLDREF
}>CONT
4 SETGLOB
TRY:<{
SAMEALTSAVE
AGAIN:<{ // t
DUP // t t
HASHCU // t x
7 GETGLOB // t x h
EQUAL // t x=h
IFRETALT // t
CTOS // s
DUP // s s
SREFS // s r
GETGLOBVAR
CALLX
}>
}>CATCH<{
NEWC // b
ENDC // c
}> }>CONT
""";
(cell) start (cont c) impure asm "2 1 CALLXARGS";
;; testable
(cell) find_branch_by_hash(int hash, cell tree) method_id {
if(hash == 68134197439415885698044414435951397869210496020759160419881882418413283430343) {
return begin_cell().end_cell();
}
if(cell_hash(tree) == hash) {
return tree;
}
cont c = code(tree, hash);
(cell answer) = start(c);
return answer;
}